Slide 1

Slide 1 text

Reusable Libraries Ryan Harter @rharter +RyanHarter

Slide 2

Slide 2 text

My Apps Fragment Shift

Slide 3

Slide 3 text

My Apps Fragment Shift

Slide 4

Slide 4 text

My Apps Fragment Shift

Slide 5

Slide 5 text

Steps to make libraries work • Identify good candidates • Limit scope and requirements • Design a good API • Document and Communicate • Treat it like a client project

Slide 6

Slide 6 text

Identify Good Candidates

Slide 7

Slide 7 text

Identify Good Candidates

Slide 8

Slide 8 text

Identify Good Candidates • It’s not a library if it’s only used once

Slide 9

Slide 9 text

Identify Good Candidates • It’s not a library if it’s only used once • Don’t reinvent the wheel

Slide 10

Slide 10 text

Identify Good Candidates • It’s not a library if it’s only used once • Don’t reinvent the wheel • Two Categories

Slide 11

Slide 11 text

Identify Good Candidates • It’s not a library if it’s only used once • Don’t reinvent the wheel • Two Categories • Utility

Slide 12

Slide 12 text

Identify Good Candidates • It’s not a library if it’s only used once • Don’t reinvent the wheel • Two Categories • Utility • UI

Slide 13

Slide 13 text

Identify Good Candidates

Slide 14

Slide 14 text

Identify Good Candidates • Google for libraries

Slide 15

Slide 15 text

Identify Good Candidates • Google for libraries • Check Android Arsenal

Slide 16

Slide 16 text

Identify Good Candidates • Google for libraries • Check Android Arsenal • Look at what other apps use

Slide 17

Slide 17 text

Identify Good Candidates • Google for libraries • Check Android Arsenal • Look at what other apps use • Be Confident

Slide 18

Slide 18 text

Identify Good Candidates • Google for libraries • Check Android Arsenal • Look at what other apps use • Be Confident • Count Stars

Slide 19

Slide 19 text

Identify Good Candidates • Google for libraries • Check Android Arsenal • Look at what other apps use • Be Confident • Count Stars • Inspect Source

Slide 20

Slide 20 text

Limit Scope and Requirements

Slide 21

Slide 21 text

Limit Scope and Requirements

Slide 22

Slide 22 text

Limit Scope and Requirements • Choose a single problem to solve

Slide 23

Slide 23 text

Limit Scope and Requirements • Choose a single problem to solve • Picasso - Efficient image loading and caching

Slide 24

Slide 24 text

Limit Scope and Requirements • Choose a single problem to solve • Picasso - Efficient image loading and caching • Retrofit - Easy REST API access

Slide 25

Slide 25 text

Limit Scope and Requirements • Choose a single problem to solve • Picasso - Efficient image loading and caching • Retrofit - Easy REST API access • Avoid “Apache Syndrome”

Slide 26

Slide 26 text

Limit Scope and Requirements • Choose a single problem to solve • Picasso - Efficient image loading and caching • Retrofit - Easy REST API access • Avoid “Apache Syndrome” • Every Apache library depends on every other Apache library

Slide 27

Slide 27 text

Limit Scope and Requirements • Library mission statement • One sentence • What the library does

Slide 28

Slide 28 text

Limit Scope and Requirements • Library mission statement • One sentence • What the library does “Allow the user to load an image from any source.”

Slide 29

Slide 29 text

Design a Good API

Slide 30

Slide 30 text

Design a Good API

Slide 31

Slide 31 text

Design a Good API • Who is your user?

Slide 32

Slide 32 text

Design a Good API • Who is your user? • If user needs to mess with code, it’s not a library

Slide 33

Slide 33 text

Design a Good API • Who is your user? • If user needs to mess with code, it’s not a library • Design from the outside in

Slide 34

Slide 34 text

Design a Good API • Who is your user? • If user needs to mess with code, it’s not a library • Design from the outside in • Package your library

Slide 35

Slide 35 text

API Strategies - Utility Requirements: Persist filter state to support undo/redo. public class HistoryManager { public T undo(); public T redo(); public void push(T state); public void clear(); }

Slide 36

Slide 36 text

API Strategies - Superclass Fragment Shift

Slide 37

Slide 37 text

API Strategies - Superclass public class BaseExportActivity extends Activity { /** * Returns a list of preferred packages which appear above the * divider with a slightly larger icon than the rest. * * @return the package ids of the preferred packages. */ protected List getPreferredPackages() { return DEFAULT_PREFERRED_PACKAGES; } /** * @return the public folder name to save files to. */ protected File getSaveFolder() { return new File(getPublicPicturesDirectory(), "Pixite"); } /** * Allows the AppInfo to be updated for things like Refragment or * Refilter. Default implementation does nothing. * * @param info The app info to update. */ protected void updateAppInfo(AppInfo info) { } }

Slide 38

Slide 38 text

API Strategies - Isolated Activity Fragment Shift

Slide 39

Slide 39 text

API Strategies - Isolated Activity

Slide 40

Slide 40 text

API Strategies - Isolated Activity Intent i = new Intent(getActivity(), InspirationActivity.class); i.putExtra(InspirationActivity.EXTRA_USER_ID, "1234567890"); i.putExtra(InspirationActivity.EXTRA_ACCESS_TOKEN, "super_secret_access_token"); i.putExtra(InspirationActivity.EXTRA_SKIP_TAG, "shiftpromo"); i.putExtra(InspirationActivity.EXTRA_USERNAME, "shift_by_pixite"); startActivity(i);

Slide 41

Slide 41 text

API Strategies - Isolated Activity Intent i = new Intent(getActivity(), InspirationActivity.class); i.putExtra(InspirationActivity.EXTRA_USER_ID, "1234567890"); i.putExtra(InspirationActivity.EXTRA_ACCESS_TOKEN, "super_secret_access_token"); i.putExtra(InspirationActivity.EXTRA_SKIP_TAG, "shiftpromo"); i.putExtra(InspirationActivity.EXTRA_USERNAME, "shift_by_pixite"); startActivity(i); ... <item name="inspirationActivityStyle">@style/InspirationActivityStyle</item> <item name="inspirationTextStyle">@style/TextAppearance.AppCompat.Inverse</item> <item name="inspirationFollowButtonStyle">@style/Widget.InspirationButton.Follow</item> <item name="inspirationMoreButtonStyle">@style/Widget.InspirationButton.More</item> <item name="inspirationRowStyle">@style/Widget.InspirationRow</item> <item name="inspirationRowTextStyle">@style/TextAppearance.InspirationRow</item>

Slide 42

Slide 42 text

API Strategies - Hybrid Intent i = new Intent(this, ImageChooserActivity.class); startActivityForResult(i, REQUEST_CHOOSE_PHOTO);

Slide 43

Slide 43 text

Distribution • Open Source (jcenter, Maven Central) • Private Maven Repo • Git Repository

Slide 44

Slide 44 text

Distribution - gradle-git-repo uploadArchives { repositories { mavenDeployer { repository(url: '[email protected]:rharter/maven-repo.git/releases') snapshotRepository(url: ‘[email protected]:rharter/maven-repo.git/snapshots') // standard pom settings } } } https://github.com/rharter/gradle-git-repo

Slide 45

Slide 45 text

Document and Communicate

Slide 46

Slide 46 text

Document and Communicate

Slide 47

Slide 47 text

Document and Communicate • If a library is only used once, is it a library?

Slide 48

Slide 48 text

Document and Communicate • If a library is only used once, is it a library? • Communicate outside of engineering

Slide 49

Slide 49 text

Document and Communicate • If a library is only used once, is it a library? • Communicate outside of engineering • Sales needs to know what to sell

Slide 50

Slide 50 text

Document and Communicate • If a library is only used once, is it a library? • Communicate outside of engineering • Sales needs to know what to sell • Design needs to know components and limitations

Slide 51

Slide 51 text

Document and Communicate • If a library is only used once, is it a library? • Communicate outside of engineering • Sales needs to know what to sell • Design needs to know components and limitations • Javadoc for Engineering, Wiki for others

Slide 52

Slide 52 text

Manage the Project

Slide 53

Slide 53 text

Manage the Project

Slide 54

Slide 54 text

Manage the Project • Treat internal libraries like a client project

Slide 55

Slide 55 text

Manage the Project • Treat internal libraries like a client project • Dedicate resources

Slide 56

Slide 56 text

Manage the Project • Treat internal libraries like a client project • Dedicate resources • Manage requests

Slide 57

Slide 57 text

Manage the Project • Treat internal libraries like a client project • Dedicate resources • Manage requests • Define requirements

Slide 58

Slide 58 text

Manage the Project • Treat internal libraries like a client project • Dedicate resources • Manage requests • Define requirements • Enforce versioned release cycle

Slide 59

Slide 59 text

Reusable Libraries @rharter +RyanHarter http://ryanharter.com