com.trello.rxlifecycle.android.ActivityEvent Java Examples

The following examples show how to use com.trello.rxlifecycle.android.ActivityEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityView.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@NonNull private LifecycleEvent convertToEvent(ActivityEvent event) {
  switch (event) {
    case CREATE:
      return LifecycleEvent.CREATE;
    case START:
      return LifecycleEvent.START;
    case RESUME:
      return LifecycleEvent.RESUME;
    case PAUSE:
      return LifecycleEvent.PAUSE;
    case STOP:
      return LifecycleEvent.STOP;
    case DESTROY:
      return LifecycleEvent.DESTROY;
    default:
      throw new IllegalStateException("Unrecognized event: " + event.name());
  }
}
 
Example #2
Source File: SampleActivity.java    From rx-receivers with Apache License 2.0 5 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Setup views.
  setContentView(R.layout.sample_activity);
  ButterKnife.inject(this);

  // Bind views to events.
  RxTelephonyManager.phoneStateChanges(this)
      .compose(this.<PhoneStateChangedEvent>bindUntilEvent(ActivityEvent.PAUSE))
      .map(Object::toString) //
      .startWith("waiting for change") //
      .map(prefix(getString(R.string.phone_state))) //
      .subscribe(RxTextView.text(phoneStateView));

  RxWifiManager.wifiStateChanges(this)
      .compose(this.<Integer>bindUntilEvent(ActivityEvent.PAUSE))
      .map(integer -> {
        switch (integer) {
          case WifiManager.WIFI_STATE_DISABLED:
            return "wifi disabled";
          case WifiManager.WIFI_STATE_DISABLING:
            return "wifi disabling";
          case WifiManager.WIFI_STATE_ENABLED:
            return "wifi enabled";
          case WifiManager.WIFI_STATE_ENABLING:
            return "wifi enabling";
          default:
            return "unknown";
        }
      }) //
      .map(prefix(getString(R.string.wifi_state))) //
      .subscribe(RxTextView.text(wifiStateView));

  RxBatteryManager.batteryChanges(this)
      .compose(this.<BatteryState>bindUntilEvent(ActivityEvent.PAUSE))
      .map(Object::toString)
      .map(prefix(getString(R.string.battery_state))) //
      .subscribe(RxTextView.text(batteryStateView));
}
 
Example #3
Source File: HttpManager.java    From RxRetrofit-mvp with MIT License 5 votes vote down vote up
/**
     * 处理http请求
     *
     * @param basePar 封装的请求数据
     */
    public void doHttpDeal(BaseApi basePar) {
        //手动创建一个OkHttpClient并设置超时时间缓存等设置
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(basePar.getConnectionTime(), TimeUnit.SECONDS);

        /*创建retrofit对象*/
        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(basePar.getBaseUrl())
                .build();
        /*rx处理*/
        ProgressSubscriber subscriber = new ProgressSubscriber(basePar, onNextListener);

        Observable observable = basePar.getObservable(retrofit)
                /*失败后的retry配置*/
                .retryWhen(new RetryWhenNetworkException())
                /*异常处理*/
                .onErrorResumeNext(funcException)
                /*生命周期管理*/
//                .compose(appCompatActivity.get().bindToLifecycle())
                .compose(appCompatActivity.get().bindUntilEvent(ActivityEvent.DESTROY))
                /*http请求线程*/
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                /*回调线程*/
                .observeOn(AndroidSchedulers.mainThread())
                /*结果判断*/
                .map(basePar);

        /*数据回调*/
        observable.subscribe(subscriber);
    }
 
Example #4
Source File: AnswersActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {

    CollectionUtils.getInstance().contailItem(mQuestionUrl).compose(this.<Collection>bindUntilEvent(ActivityEvent.DESTROY))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<Collection>() {
                @Override
                public void call(Collection model) {
                    isSaved = true;
                    menu.findItem(R.id.save).setIcon(ContextCompat.getDrawable(AnswersActivity.this,R.drawable.ic_save));
                }
            });
    return super.onPrepareOptionsMenu(menu);
}
 
Example #5
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
protected void onDestroy() {
    lifecycleSubject.onNext(ActivityEvent.DESTROY);
    AppManager.getAppManager().removeActivity(this);
    super.onDestroy();
}
 
Example #6
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppManager.getAppManager().addActivity(this);
    lifecycleSubject.onNext(ActivityEvent.CREATE);
}
 
Example #7
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onStop() {
    lifecycleSubject.onNext(ActivityEvent.STOP);
    super.onStop();
}
 
Example #8
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onStop() {
    lifecycleSubject.onNext(ActivityEvent.STOP);
    super.onStop();
}
 
Example #9
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onPause() {
    lifecycleSubject.onNext(ActivityEvent.PAUSE);
    super.onPause();
}
 
Example #10
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onResume() {
    super.onResume();
    lifecycleSubject.onNext(ActivityEvent.RESUME);
}
 
Example #11
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onStart() {
    super.onStart();
    lifecycleSubject.onNext(ActivityEvent.START);
}
 
Example #12
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
    return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
 
Example #13
Source File: RxAppCompatActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
@CheckResult
public final Observable<ActivityEvent> lifecycle() {
    return lifecycleSubject.asObservable();
}
 
Example #14
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onDestroy() {
    lifecycleSubject.onNext(ActivityEvent.DESTROY);
    super.onDestroy();
}
 
Example #15
Source File: BaseActivity.java    From Ticket-Analysis with MIT License 4 votes vote down vote up
public Observable ClickView(View view) {
    return RxView.clicks(view).throttleFirst(BuildConfig.TIME_CLICK_IGNORE, TimeUnit.MILLISECONDS).compose(bindUntilEvent(ActivityEvent.DESTROY));
}
 
Example #16
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onPause() {
    lifecycleSubject.onNext(ActivityEvent.PAUSE);
    super.onPause();
}
 
Example #17
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onResume() {
    super.onResume();
    lifecycleSubject.onNext(ActivityEvent.RESUME);
}
 
Example #18
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onStart() {
    super.onStart();
    lifecycleSubject.onNext(ActivityEvent.START);
}
 
Example #19
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lifecycleSubject.onNext(ActivityEvent.CREATE);
}
 
Example #20
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
    return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
 
Example #21
Source File: RxFragmentActivity.java    From ZhiHu-TopAnswer with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
@CheckResult
public final Observable<ActivityEvent> lifecycle() {
    return lifecycleSubject.asObservable();
}
 
Example #22
Source File: HttpManager.java    From RxjavaRetrofitDemo-master with MIT License 4 votes vote down vote up
/**
     * 处理http请求
     *
     * @param basePar 封装的请求数据
     */
    public void doHttpDeal(BaseApi basePar) {
        //手动创建一个OkHttpClient并设置超时时间缓存等设置
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(basePar.getConnectionTime(), TimeUnit.SECONDS);
        builder.addInterceptor(new CookieInterceptor(basePar.isCache(), basePar.getUrl()));
        if(RxRetrofitApp.isDebug()){
            builder.addInterceptor(getHttpLoggingInterceptor());
        }


        /*创建retrofit对象*/
        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(basePar.getBaseUrl())
                .build();


        /*rx处理*/
        ProgressSubscriber subscriber = new ProgressSubscriber(basePar);
        Observable observable = basePar.getObservable(retrofit)
                 /*失败后的retry配置*/
                .retryWhen(new RetryWhenNetworkException(basePar.getRetryCount(),
                        basePar.getRetryDelay(), basePar.getRetryIncreaseDelay()))
                /*生命周期管理*/
//                .compose(basePar.getRxAppCompatActivity().bindToLifecycle())
                .compose(basePar.getRxAppCompatActivity().bindUntilEvent(ActivityEvent.PAUSE))
                /*http请求线程*/
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                /*回调线程*/
                .observeOn(AndroidSchedulers.mainThread())
                /*结果判断*/
                .map(basePar);


        /*链接式对象返回*/
        SoftReference<HttpOnNextListener> httpOnNextListener = basePar.getListener();
        if (httpOnNextListener != null && httpOnNextListener.get() != null) {
            httpOnNextListener.get().onNext(observable);
        }

        /*数据回调*/
        observable.subscribe(subscriber);

    }
 
Example #23
Source File: HttpManager.java    From RxjavaRetrofitDemo-string-master with MIT License 4 votes vote down vote up
/**
     * RxRetrofit处理
     *
     * @param basePar
     */
    public Observable httpDeal(Retrofit retrofit, BaseApi basePar) {
        /*失败后的retry配置*/
        Observable observable = basePar.getObservable(retrofit)
                /*失败后retry处理控制*/
                .retryWhen(new RetryWhenNetworkException(basePar.getRetryCount(),
                        basePar.getRetryDelay(), basePar.getRetryIncreaseDelay()))
                /*异常处理*/
                .onErrorResumeNext(new ExceptionFunc())
                /*tokean过期统一处理*/
//                .flatMap(new TokeanFunc(basePar, retrofit))
                /*返回数据统一判断*/
                .map(new ResulteFunc())
                /*http请求线程*/
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                /*回调线程*/
                .observeOn(AndroidSchedulers.mainThread());

        /*生命周期管理*/
        if (appCompatActivity != null) {
            observable.compose(appCompatActivity.get().bindUntilEvent(ActivityEvent.DESTROY));
        }

        /*是否不需要处理sub对象*/
        if (basePar.isNoSub()) {
            return observable;
        }

        /*ober回调,链接式返回*/
        if (onNextSubListener != null && null != onNextSubListener.get()) {
            onNextSubListener.get().onNext(observable, basePar.getMethod());
        }

        /*数据String回调*/
        if (onNextListener != null && null != onNextListener.get()) {
            ProgressSubscriber subscriber = new ProgressSubscriber(basePar, onNextListener, appCompatActivity);
            observable.subscribe(subscriber);
        }

        return observable;
    }
 
Example #24
Source File: HttpManager.java    From Bailan with Apache License 2.0 4 votes vote down vote up
/**
     * 处理http请求
     *
     * @param basePar 封装的请求数据
     */
    public void doHttpDeal(BaseApi basePar) {
        //手动创建一个OkHttpClient并设置超时时间缓存等设置
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(basePar.getConnectionTime(), TimeUnit.SECONDS);
        builder.addInterceptor(new CookieInterceptor(basePar.isCache(), basePar.getUrl()));
        if(RxRetrofitApp.isDebug()){
            builder.addInterceptor(getHttpLoggingInterceptor());
        }


        /*创建retrofit对象*/
        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(basePar.getBaseUrl())
                .build();


        /*rx处理*/
        ProgressSubscriber subscriber = new ProgressSubscriber(basePar);
        //定义Observable 并没有执行 只有订阅的时候才会执行 getObservable()是请求数据之后返回的Observable
        Observable observable = basePar.getObservable(retrofit)
                 /*失败后的retry配置*/
                .retryWhen(new RetryWhenNetworkException(basePar.getRetryCount(),
                        basePar.getRetryDelay(), basePar.getRetryIncreaseDelay()))
                /*生命周期管理*/
//                .compose(basePar.getRxAppCompatActivity().bindToLifecycle())
                .compose(basePar.getRxAppCompatActivity().bindUntilEvent(ActivityEvent.PAUSE))
                /*http请求线程*/
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                /*回调线程*/
                .observeOn(AndroidSchedulers.mainThread())
                /*结果判断*/
                .map(basePar);


        /*链接式对象返回*/
        SoftReference<HttpOnNextListener> httpOnNextListener = basePar.getListener();
        if (httpOnNextListener != null && httpOnNextListener.get() != null) {
            httpOnNextListener.get().onNext(observable);
        }

        /*数据回调*/
        observable.subscribe(subscriber);

    }
 
Example #25
Source File: HttpManager.java    From Bailan with Apache License 2.0 4 votes vote down vote up
/**
     * 处理http请求
     *
     * @param basePar 封装的请求数据
     */
    public void doHttpDeal(BaseApi basePar) {
        //手动创建一个OkHttpClient并设置超时时间缓存等设置
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(basePar.getConnectionTime(), TimeUnit.SECONDS);
        builder.addInterceptor(new CookieInterceptor(basePar.isCache(), basePar.getUrl()));
        if(RxRetrofitApp.isDebug()){
            builder.addInterceptor(getHttpLoggingInterceptor());
        }


        /*创建retrofit对象*/
        Retrofit retrofit = new Retrofit.Builder()
                .client(builder.build())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(basePar.getBaseUrl())
                .build();


        /*rx处理*/
        ProgressSubscriber subscriber = new ProgressSubscriber(basePar);
        //定义Observable 并没有执行 只有订阅的时候才会执行 getObservable()是请求数据之后返回的Observable
        Observable observable = basePar.getObservable(retrofit)
                 /*失败后的retry配置*/
                .retryWhen(new RetryWhenNetworkException(basePar.getRetryCount(),
                        basePar.getRetryDelay(), basePar.getRetryIncreaseDelay()))
                /*生命周期管理*/
//                .compose(basePar.getRxAppCompatActivity().bindToLifecycle())
                .compose(basePar.getRxAppCompatActivity().bindUntilEvent(ActivityEvent.PAUSE))
                /*http请求线程*/
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                /*回调线程*/
                .observeOn(AndroidSchedulers.mainThread())
                /*结果判断*/
                .map(basePar);


        /*链接式对象返回*/
        SoftReference<HttpOnNextListener> httpOnNextListener = basePar.getListener();
        if (httpOnNextListener != null && httpOnNextListener.get() != null) {
            httpOnNextListener.get().onNext(observable);
        }

        /*数据回调*/
        observable.subscribe(subscriber);

    }