Slide 1

Slide 1 text

BETTER ANDROID INTENTS DART & HENSON https://github.com/f2prateek/dart

Slide 2

Slide 2 text

ABOUT US Senior Android Dev @ Groupon
 ~20 years of Java coding OSS: Dart, TP, BoundBox, … STEPHANE NICOLAS DANIEL MOLINERO REGUERA Android Dev @ Groupon
 Turbulence Ninja OSS: Dart, TP. +stephane @D_Lemures

Slide 3

Slide 3 text

5IF"OESPJE5FBNJT)JSJOH
 jobs.groupon.com/careers/

Slide 4

Slide 4 text

INTENTS & EXTRAS NAVIGATION LAYER DART: CONSUMING INTENTS ANNOTATIONS BINDING SETUP HENSON: CREATING INTENTS INTENT BUILDERS FLUENT API ANNOTATIONS SETUP CONCLUSION THE TALK

Slide 5

Slide 5 text

AN INTENT IS AN ABSTRACT DESCRIPTION OF AN OPERATION TO BE PERFORMED INTENTS & EXTRAS BROADCAST
 RECEIVER SERVICE ACTIVITY from developer.android.com/reference/android/content/Intent.html

Slide 6

Slide 6 text

AN INTENT IS AN ABSTRACT DESCRIPTION OF AN OPERATION TO BE PERFORMED INTENTS & EXTRAS ACTIVITY from developer.android.com/reference/android/content/Intent.html INTENT

Slide 7

Slide 7 text

EXTRAS CAN BE USED TO PROVIDE EXTENDED INFORMATION INTENTS & EXTRAS ACTIVITY from developer.android.com/reference/android/content/Intent.html INTENT EXTRAS

Slide 8

Slide 8 text

NAVIGATION LAYER ACTIVITY 1 ACTIVITY 4 ACTIVITY 2 ALL INTENTS TOGETHER FORM THE NAVIGATION LAYER OF AN ANDROID APP ACTIVITY 3 ACTIVITY 5 ACTIVITY 6

Slide 9

Slide 9 text

NAVIGATION LAYER HOW TO ORGANIZE 
 YOUR NAVIGATION LAYER ?

Slide 10

Slide 10 text

CONSUMING & CREATING INTENTS DEAL LIST 
 ACTIVITY DEAL DETAIL 
 ACTIVITY CREATING AN INTENT CONSUMING AN INTENT

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

CONSUMING INTENTS

Slide 13

Slide 13 text

DART CONSUMING INTENTS

Slide 14

Slide 14 text

DART: CONSUMING INTENTS ACTIVITY String field1 int field2 boolean field3

Slide 15

Slide 15 text

DART: CONSUMING INTENTS ACTIVITY String field1 int field2 boolean field3 INTENT

Slide 16

Slide 16 text

DART: CONSUMING INTENTS ACTIVITY String field1 int field2 boolean field3 INTENT EXTRA 1 value 1 EXTRA 2 value 2 EXTRA 3 value 3 EXTRAS

Slide 17

Slide 17 text

DART: CONSUMING INTENTS public class DealDetailActivity extends Activity { public static final String EXTRA_DEAL_ID = "EXTRA_DEAL_ID"; public static final String EXTRA_SHOW_MAP = "EXTRA_SHOW_MAP"; 
 private String dealId; private boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dealId = getIntent().getStringExtra(EXTRA_DEAL_ID); shouldShowMap = getIntent().getBooleanExtra(EXTRA_SHOW_MAP, false); if (dealId == null) { throw new IllegalArgumentException("Deal Id is required"); } ... }

Slide 18

Slide 18 text

public class DealDetailActivity extends Activity { public static final String EXTRA_DEAL_ID = "EXTRA_DEAL_ID"; public static final String EXTRA_SHOW_MAP = "EXTRA_SHOW_MAP"; 
 private String dealId; private boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dealId = getIntent().getStringExtra(EXTRA_DEAL_ID); shouldShowMap = getIntent().getBooleanExtra(EXTRA_SHOW_MAP, false); if (dealId == null) { throw new IllegalArgumentException("Deal Id is required"); } ... } DART: CONSUMING INTENTS

Slide 19

Slide 19 text

public class DealDetailActivity extends Activity { public static final String EXTRA_DEAL_ID = "EXTRA_DEAL_ID"; public static final String EXTRA_SHOW_MAP = "EXTRA_SHOW_MAP"; 
 private String dealId; private boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dealId = getIntent().getStringExtra(EXTRA_DEAL_ID); shouldShowMap = getIntent().getBooleanExtra(EXTRA_SHOW_MAP, false); if (dealId == null) { throw new IllegalArgumentException("Deal Id is required"); } ... } DART: CONSUMING INTENTS BOILERPLATE!!!

Slide 20

Slide 20 text

DART: ANNOTATIONS public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 21

Slide 21 text

DART: ANNOTATIONS DECLARE REQUIRED AND OPTIONAL FIELDS public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 22

Slide 22 text

DART: BINDING public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 23

Slide 23 text

DART: BINDING BIND INTENT EXTRAS TO ANNOTATED FIELDS public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 24

Slide 24 text

ACTIVITY MODEL String field1 int field2 boolean field3 DART: BINDING A MODEL

Slide 25

Slide 25 text

ACTIVITY MODEL String field1 int field2 boolean field3 DART: BINDING A MODEL SEPARATE EXTRAS AND ACTIVITIES

Slide 26

Slide 26 text

public class DealDetailModel {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; } MODEL: public class DealDetailActivity extends Activity {
 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(detailModelInstance, this); ... } ACTIVITY: DART: BINDING A MODEL

Slide 27

Slide 27 text

compile ‘com.f2prateek.dart:dart:2.0.1 provided ‘com.f2prateek.dart:dart-processor:2.0.1 GRADLE: com.f2prateek.dart dart 2.0.1 com.f2prateek.dart dart-processor 2.0.1 provided MAVEN: DART: SETUP

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

CREATING INTENTS

Slide 30

Slide 30 text

HENSON CREATING INTENTS

Slide 31

Slide 31 text

public class CentralIntentFactory { public Intent newDealDetailActivityIntent(Context context, String dealId) {
 return new Intent(context, DealDetailActivity.class) .putExtra(EXTRA_DEAL_ID, dealId);
 }
 
 public Intent newDealDetailActivityIntent(Context context, 
 String dealId, 
 boolean showMap) {
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, dealId)
 .putExtra(EXTRA_SHOW_MAP, showMap);
 }
 ...
 } 
 HENSON: CREATING INTENTS

Slide 32

Slide 32 text

public class CentralIntentFactory { public Intent newDealDetailActivityIntent(Context context, String dealId) {
 return new Intent(context, DealDetailActivity.class) .putExtra(EXTRA_DEAL_ID, dealId);
 }
 
 public Intent newDealDetailActivityIntent(Context context, 
 String dealId, 
 boolean showMap) {
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, dealId)
 .putExtra(EXTRA_SHOW_MAP, showMap);
 }
 ...
 } 
 HENSON: CREATING INTENTS - MEYER’S OPEN/CLOSED PRINCIPLE - BIG BALL OF MUD

Slide 33

Slide 33 text

public class DealDetailActivity extends Activity { ... public static Intent getIntent(Context context, 
 String dealId) { 
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, dealId);
 } 
 
 public static Intent getIntent(Context context, 
 String dealId, 
 boolean showMap) { 
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, itemId)
 .putExtra(EXTRA_SHOW_MAP, showMap);
 } ...
 } 
 HENSON: CREATING INTENTS

Slide 34

Slide 34 text

public class DealDetailActivity extends Activity { ... public static Intent getIntent(Context context, 
 String dealId) { 
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, dealId);
 } 
 
 public static Intent getIntent(Context context, 
 String dealId, 
 boolean showMap) { 
 return new Intent(context, DealDetailActivity.class)
 .putExtra(EXTRA_DEAL_ID, itemId)
 .putExtra(EXTRA_SHOW_MAP, showMap);
 } ...
 } 
 HENSON: CREATING INTENTS BOILERPLATE!!!

Slide 35

Slide 35 text


 HENSON: INTENT BUILDERS public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 36

Slide 36 text

DART & HENSON GENERATE THEM FOR YOU ! 
 HENSON: INTENT BUILDERS public class DealDetailActivity extends Activity {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(this); ... } }

Slide 37

Slide 37 text

public class DealDetailActivity$$IntentBuilder {
 private Intent intent;
 private Bundler bundler = Bundler.create();
 
 public DealDetailActivity$$IntentBuilder(Context context) {
 intent = new Intent(context, DealDetailActivity.class);
 }
 
 public DealDetailActivity$$IntentBuilder dealId(String dealId) {
 bundler.put("dealId", dealId);
 return this;
 }
 
 public DealDetailActivity$$IntentBuilder shouldShowMap(Boolean shouldShowMap) {
 bundler.put(“shouldShowMap", shouldShowMap);
 return this;
 }
 
 public Intent build() {
 intent.putExtras(bundler.get());
 return intent;
 } } 
 HENSON: INTENT BUILDERS

Slide 38

Slide 38 text

public class DealDetailActivity$$IntentBuilder {
 private Intent intent;
 private Bundler bundler = Bundler.create();
 
 public DealDetailActivity$$IntentBuilder(Context context) {
 intent = new Intent(context, DealDetailActivity.class);
 }
 
 public DealDetailActivity$$IntentBuilder dealId(String dealId) {
 bundler.put("dealId", dealId);
 return this;
 }
 
 public DealDetailActivity$$IntentBuilder shouldShowMap(Boolean shouldShowMap) {
 bundler.put(“shouldShowMap", shouldShowMap);
 return this;
 }
 
 public Intent build() {
 intent.putExtras(bundler.get());
 return intent;
 } } 
 HENSON: INTENT BUILDERS

Slide 39

Slide 39 text

public class DealDetailActivity$$IntentBuilder {
 private Intent intent;
 private Bundler bundler = Bundler.create();
 
 public DealDetailActivity$$IntentBuilder(Context context) {
 intent = new Intent(context, DealDetailActivity.class);
 }
 
 public DealDetailActivity$$IntentBuilder dealId(String dealId) {
 bundler.put("dealId", dealId);
 return this;
 }
 
 public DealDetailActivity$$IntentBuilder shouldShowMap(Boolean shouldShowMap) {
 bundler.put(“shouldShowMap", shouldShowMap);
 return this;
 }
 
 public Intent build() {
 intent.putExtras(bundler.get());
 return intent;
 } } 
 HENSON: INTENT BUILDERS

Slide 40

Slide 40 text


 HENSON: FLUENT API Intent intent = Henson.with(context) .gotoDealDetailActivity() .dealId(dealId) .shouldShowMap(true) .build();

Slide 41

Slide 41 text


 HENSON: FLUENT API Intent intent = Henson.with(context) .gotoDealDetailActivity() .dealId(dealId) .shouldShowMap(true) .build(); HENSON CLASS PROVIDES A FLUENT API TO ACCESS INTENT BUILDERS

Slide 42

Slide 42 text

HENSON: ANNOTATIONS @HensonNavigable public class SettingsActivity extends Activity {
 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... } }

Slide 43

Slide 43 text

HENSON: ANNOTATIONS MAKE YOUR ACTIVITIES VISIBLE TO HENSON EVEN IF THEY DON'T USE DART ANNOTATIONS @HensonNavigable public class SettingsActivity extends Activity {
 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... } }

Slide 44

Slide 44 text

public class DealDetailModel {
 @InjectExtra String dealId; @InjectExtra @Nullable Boolean shouldShowMap; } MODEL: @HensonNavigable(model = DealDetailModel.class) public class DealDetailActivity extends Activity {
 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Dart.inject(detailModelInstance, this); ... } ACTIVITY: HENSON: ANNOTATIONS

Slide 45

Slide 45 text

compile ‘com.f2prateek.dart:henson:2.0.1 provided ‘com.f2prateek.dart:henson-processor:2.0.1 GRADLE: com.f2prateek.dart henson 2.0.1 com.f2prateek.dart henson-processor 2.0.1 provided MAVEN: HENSON: SETUP

Slide 46

Slide 46 text

CONCLUSION QUESTIONS ? COMMENTS ?

Slide 47

Slide 47 text

CONCLUSION QUESTIONS ? COMMENTS ?

Slide 48

Slide 48 text

BETTER ANDROID INTENTS DART & HENSON https://github.com/f2prateek/dart +stephane @D_Lemures