Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxDialog

JasonNi
June 17, 2017

 RxDialog

JasonNi

June 17, 2017
Tweet

More Decks by JasonNi

Other Decks in Technology

Transcript

  1. public class LaunchActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState)

    { Observable<Boolean> launchObservable = RxDialog.create(); Observable<Boolean> campaignObservable = RxDialog.create(); Observable<Boolean> rateObservable = RxDialog.create(); // ...
 Observable.concat( launchObservable, campaignObservable, rateObservable ); // ...
 }
 
 } LaunchActivity.java
  2. public class RxDialog { 
 public static Observable<Boolean> create() {


    return Observable.create(emitter -> { 
 AlertDialog.Builder builder = new AlertDialog.Builder(context); 
 builder.setPositiveButton(R.string.alert_ok, (dialog, which) -> {
 if (!emitter.isDisposed()) {
 emitter.onNext(true);
 emitter.onComplete();
 }
 });
 Dialog dialog = builder.show();
 // ...
 });
 }
 } RxDialog.java
  3. public class RxDialog { 
 public static Observable<Boolean> create() {


    return Observable.create(emitter -> { 
 AlertDialog.Builder builder = new AlertDialog.Builder(context);
 builder.setPositiveButton(R.string.alert_ok, (dialog, which) -> {
 if (!emitter.isDisposed()) {
 emitter.onNext(true);
 emitter.onComplete();
 }
 });
 Dialog dialog = builder.show();
 // ...
 });
 }
 } RxDialog.java onComplete
  4. public class LaunchActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState)

    { Observable<Boolean> launchObservable = RxDialog.create(); Observable<Boolean> campaignObservable = RxDialog.create(); Observable<Boolean> rateObservable = RxDialog.create(); // ...
 Observable.concat( launchObservable, campaignObservable, rateObservable ); // ...
 }
 
 } LaunchActivity.java
  5. public class LaunchActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState)

    { Observable<Boolean> launchObservable = Observable.empty(); Observable<Boolean> campaignObservable = Observable.empty(); Observable<Boolean> rateObservable = Observable.empty(); // ... if (有公告) launchObservable = RxDialog.create(); if (有評價) launchObservable = RxDialog.create(); if (有活動) launchObservable = RxDialog.create(); Observable.concat( launchObservable, campaignObservable, rateObservable ); // ...
 }
 } LaunchActivity.java