Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

HELLO I’m Hannes

Slide 4

Slide 4 text

REFACTORING PLAID A REACTIVE MVP APPROACH

Slide 5

Slide 5 text

SLOWED DOWN BY BAD CODE?

Slide 6

Slide 6 text

FEAR CHANGING CODE!

Slide 7

Slide 7 text

FEAR CHANGING CODE!

Slide 8

Slide 8 text

TDD Test-Driven-Development

Slide 9

Slide 9 text

SOLID Robert C. Martins
 „Uncle Bob“

Slide 10

Slide 10 text

SINGLE RESPONSIBILITY “A class should only have one reason to change” Book 
 currentPage() nextPage() print()

Slide 11

Slide 11 text

SINGLE RESPONSIBILITY “A class should only have one reason to change” Book 
 currentPage() nextPage() print() Book 
 currentPage() nextPage() Printer 
 print(Book)

Slide 12

Slide 12 text

IMMUTABILITY

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

You want an 
 immutable hot dog

Slide 15

Slide 15 text

AUTOVALUE @AutoValue public abstract class HotDog { }

Slide 16

Slide 16 text

AUTOVALUE @AutoValue public abstract class HotDog implements Parcelable { }

Slide 17

Slide 17 text

AUTOVALUE @AutoValue public abstract class HotDog implements Parcelable {
 @Json public abstract double getPrice(); }

Slide 18

Slide 18 text

AUTOVALUE @AutoValue public abstract class HotDog implements Parcelable {
 @Json public abstract double getPrice(); @ColumnName public abstract boolean hasKetchup(); }

Slide 19

Slide 19 text

AUTOVALUE @AutoValue public abstract class HotDog implements Parcelable {
 @Json public abstract double getPrice(); @ColumnName public abstract boolean hasKetchup(); public abstract static HotDog(double p, boolean k) { return new AutoValue_HotDog(p, k); } }

Slide 20

Slide 20 text

MVC Model-View-Controller

Slide 21

Slide 21 text

MVC Trygve Reenskaug View Model Controller observes changes

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

PLAID Nick Butcher

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

PLAID • https://github.com/nickbutcher/plaid • 5170 Stars on Github • Last commit: 1st of June 2016 • 5.000 - 10.000 installs 2nd June 2016

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

PLAID • No clear Separation of responsibilities • AsyncTask • Android Services • Shared Preferences for persistency 2nd June 2016

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

HomeActivity

Slide 38

Slide 38 text

HomeActivity

Slide 39

Slide 39 text

HomeActivity ConnectivityManager

Slide 40

Slide 40 text

HomeActivity ConnectivityManager Animations

Slide 41

Slide 41 text

HomeActivity ConnectivityManager Animations FeedAdapter

Slide 42

Slide 42 text

HomeActivity ConnectivityManager Animations FilterAdapter FeedAdapter

Slide 43

Slide 43 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter

Slide 44

Slide 44 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter

Slide 45

Slide 45 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap

Slide 46

Slide 46 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged()

Slide 47

Slide 47 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged()

Slide 48

Slide 48 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged()

Slide 49

Slide 49 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged()

Slide 50

Slide 50 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged()

Slide 51

Slide 51 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged() SourceManager

Slide 52

Slide 52 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged() SourceManager

Slide 53

Slide 53 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged() SourceManager

Slide 54

Slide 54 text

REFACTORING

Slide 55

Slide 55 text

Internet

Slide 56

Slide 56 text

Mock

Slide 57

Slide 57 text

https://www.getpostman.com/

Slide 58

Slide 58 text

src/test/resources ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("somefile.json").getFile());

Slide 59

Slide 59 text

src/test/resources ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("somefile.json").getFile()); Mock https://github.com/square/okhttp/tree/master/mockwebserver

Slide 60

Slide 60 text

src/test/resources ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("somefile.json").getFile()); Mock https://github.com/square/okhttp/tree/master/mockwebserver @Rule https://github.com/artem-zinnatullin/qualitymatters

Slide 61

Slide 61 text

class HomeActivityTest {
 @Rule MockWebServer server = new MockWebServer(); @Test public void showItems(){ server.enqueue( new MockResponse (…) ); onView( withId( R.id.recyclerView )) .check( matches( isDisplayed() ); onView(withId( R.id.recyclerView)) .check( new RecyclerViewItemCountAssertion(20) ) // test visibility of error and loading view }

Slide 62

Slide 62 text

CLEAN ARCHITECTURE Entity Entity Entity Interactor
 Presenter
 View


Slide 63

Slide 63 text

CLEAN ARCHITECTURE Entity Entity Entity Interactor
 Presenter
 View
 Break the Rules! https://publicobject.com/2016/04/20/deliberate-disobedience/ Jesse Wilson

Slide 64

Slide 64 text

HomeActivity ConnectivityManager Animations onActivityResult() FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap FilterAdapter getFilters() registerFilterChanged() SourceManager

Slide 65

Slide 65 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap SourceManager

Slide 66

Slide 66 text

REACTIVE PROGRAMMING

Slide 67

Slide 67 text

java.util.Observable

Slide 68

Slide 68 text

SQLBrite SQLiteDatabase SourceDao

Slide 69

Slide 69 text

interface SourceDao {
 
 fun getAllSources(): Observable>
 
 fun getEnabledSources(): Observable>
 
 fun insert(source: Source): Observable
 
 fun delete(source: Source): Observable }

Slide 70

Slide 70 text

@AutoValue class Source : Parcelable {
 @ColumnName(COL_NAME) fun name() : String @ColumnName(COL_ENABLED) fun boolean enabled(); }

Slide 71

Slide 71 text

TDD • Write failing unit test first • Write just enough code to pass all tests • Repeat

Slide 72

Slide 72 text

class SqliteSourceDaoTest {
 @Test fun insertAndGet(){ dao = SqliteSourceDao() val source = Source.create(…) val inserted = dao.insert(source)
 .toBlocking().first() assertEquals(1, insertRes) } }

Slide 73

Slide 73 text

Unit Test failed

Slide 74

Slide 74 text

class SqliteSourceDao : SourceDao, Dao() {
 
 fun insert(source: Source): Observable = insert(TABLE, source.toContentValues()) }

Slide 75

Slide 75 text

Unit Tests OK

Slide 76

Slide 76 text

class SqliteSourceDaoTest {
 @Test fun insertAndGet(){ dao = SqliteSourceDao() val source = Source.create(…) val inserted = dao.insert(source)
 .toBlocking().first() assertEquals(1, insertRes) val queried = dao.getAllSources().toBlocking() assertEquals(queried, listOf(source)) } }

Slide 77

Slide 77 text

Unit Test failed

Slide 78

Slide 78 text

class SqliteSourceDao : SourceDao, Dao() {
 
 fun insert(source: Source): Observable = insert(TABLE, source.toContentValues()) fun getAll(source: Source): Observable> = query( SELECT(“*“).FROM(TABLE) ) .mapToList(Source.MAPPER) }

Slide 79

Slide 79 text

Unit Tests OK

Slide 80

Slide 80 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap SourceManager

Slide 81

Slide 81 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap SourceDao

Slide 82

Slide 82 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap SourceDao

Slide 83

Slide 83 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager pageIndexMap runningCallsMap SourceDao

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

RxBus

Slide 88

Slide 88 text

RxBus

Slide 89

Slide 89 text

HomeActivity Animations FilterAdapter FeedAdapter DataManager SourceDao P R E
 S
 E
 N
 T
 E R
 View Model

Slide 90

Slide 90 text

TESTING MVP • View with Mock Presenter • Presenter with Mock View and Mock Model • Model plain old unit test (slides before)

Slide 91

Slide 91 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao

Slide 92

Slide 92 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route

Slide 93

Slide 93 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route Queries Http Endpoint

Slide 94

Slide 94 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route Router Queries Http Endpoint

Slide 95

Slide 95 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route Router Queries Http Endpoint A collection of Routes

Slide 96

Slide 96 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route Router Page Queries Http Endpoint A collection of Routes

Slide 97

Slide 97 text

SINGLE RESPONSIBILITY DataManager pageIndexMap runningCallsMap SourceDao Route Router Page Queries Http Endpoint A collection of Routes Page Index

Slide 98

Slide 98 text

OBSERVABLE STREAM SourceDao Route Router Page SQLBrite SQLiteDatabase

Slide 99

Slide 99 text

OBSERVABLE STREAM SourceDao Route Router Page SQLBrite SQLiteDatabase

Slide 100

Slide 100 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 101

Slide 101 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 102

Slide 102 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 103

Slide 103 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 104

Slide 104 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 105

Slide 105 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 106

Slide 106 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 107

Slide 107 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 108

Slide 108 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 109

Slide 109 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 110

Slide 110 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 111

Slide 111 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 112

Slide 112 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 113

Slide 113 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 114

Slide 114 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 115

Slide 115 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 116

Slide 116 text

SourceDao Route Router Page SQLBrite SQLiteDatabase SourceDao HomePresenter HomeActivity FilterPresenter FilterFragment

Slide 117

Slide 117 text

UNIDIRECTIONAL DATAFLOW

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

HomePresenter HomeActivity FilterPresenter FilterFragment SearchPresenter SearchActivity SettingsPresenter SettingsActivity

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

MOVE FAST WITHOUT FEARING TO BREAK THINGS

Slide 122

Slide 122 text

THE CODE YOU WRITE TODAY WILL BE LEGACY CODE TOMORROW

Slide 123

Slide 123 text

JUST LIKE TODAY’S CELLS IN YOUR BODY ARE LEGACY CELLS TOMORROW

Slide 124

Slide 124 text

We are hiring! www.tickaroo.com

Slide 125

Slide 125 text

QUESTIONS? hannesdorfmann.com @sockeqwe