Search in sources :

Example 6 with NonNull

use of io.reactivex.annotations.NonNull in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class SplashPresenter method toActDownLoadNetKey.

/**
 * 下载网络请求验证码
 */
private void toActDownLoadNetKey() {
    ThreadUtils.runThread(new Runnable() {

        @Override
        public void run() {
            HttpClient httpClient = new HttpClient();
            Map<String, String> msg = new HashMap<String, String>();
            msg.put("appKey", "9c3d77f18e4848d095e626e9b3a009a3");
            msg.put("appSecret", "ff265c879c4ac08028e77a6c66078f9ce81c15b6fbc76c18f7a12a97c859c92b");
            String params = new Gson().toJson(msg);
            StringRequestEntity paramEntity = null;
            try {
                paramEntity = new StringRequestEntity(params, "application/json", "utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            PostMethod postMethod = new PostMethod(Api.POST_KEY);
            postMethod.setRequestEntity(paramEntity);
            try {
                httpClient.executeMethod(postMethod);
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                InputStream inputStream = postMethod.getResponseBodyAsStream();
                final String resultKey = convertStreamToString(inputStream);
                ThreadUtils.runInMainThread(new Runnable() {

                    @Override
                    public void run() {
                        ResultKeyGsonBean resultKeyBean = new Gson().fromJson(resultKey, ResultKeyGsonBean.class);
                        String access_token = resultKeyBean.getData().getAccess_token();
                        GlobalConstantUtils.setToken(access_token);
                        Observable.create(new ObservableOnSubscribe<String>() {

                            @Override
                            public void subscribe(@NonNull ObservableEmitter<String> e) throws Exception {
                                SystemClock.sleep(2000);
                                e.onNext("");
                                e.onComplete();
                            }
                        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<String>() {

                            @Override
                            public void accept(String s) throws Exception {
                                Intent intent = new Intent(AppLifecyclesImpl.mAppContext, MainActivity.class);
                                mRootView.launchActivity(intent);
                                mRootView.killMyself();
                            }
                        });
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) ObservableOnSubscribe(io.reactivex.ObservableOnSubscribe) PostMethod(org.apache.commons.httpclient.methods.PostMethod) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) IOException(java.io.IOException) MainActivity(com.mtm.mrecord.mvp.ui.activity.MainActivity) ResultKeyGsonBean(com.mtm.mrecord.mvp.model.entity.ResultKeyGsonBean) LoginException(javax.security.auth.login.LoginException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) HttpClient(org.apache.commons.httpclient.HttpClient) NonNull(io.reactivex.annotations.NonNull) Map(java.util.Map) HashMap(java.util.HashMap) ObservableEmitter(io.reactivex.ObservableEmitter)

Example 7 with NonNull

use of io.reactivex.annotations.NonNull in project Shuttle by timusus.

the class AestheticEditText method onAttachedToWindow.

@SuppressWarnings("ConstantConditions")
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
    subscriptions.add(ViewUtil.getObservableForResId(getContext(), textColorResId, Aesthetic.get(getContext()).textColorPrimary()).compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this), onErrorLogAndRethrow()));
    subscriptions.add(ViewUtil.getObservableForResId(getContext(), textColorHintResId, Aesthetic.get(getContext()).textColorSecondary()).compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewHintTextColorAction.create(this), onErrorLogAndRethrow()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 8 with NonNull

use of io.reactivex.annotations.NonNull in project Shuttle by timusus.

the class AestheticRadioButton method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subscriptions = new CompositeDisposable();
    // noinspection ConstantConditions
    subscriptions.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
    subscriptions.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this)));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 9 with NonNull

use of io.reactivex.annotations.NonNull in project Shuttle by timusus.

the class AestheticTextInputEditText method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subs = new CompositeDisposable();
    subs.add(Aesthetic.get(getContext()).textColorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewTextColorAction.create(this), onErrorLogAndRethrow()));
    subs.add(Aesthetic.get(getContext()).textColorSecondary().compose(Rx.<Integer>distinctToMainThread()).subscribe(ViewHintTextColorAction.create(this), onErrorLogAndRethrow()));
    // noinspection ConstantConditions
    subs.add(Observable.combineLatest(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()), Aesthetic.get(getContext()).isDark(), ColorIsDarkState.creator()).compose(Rx.<ColorIsDarkState>distinctToMainThread()).subscribe(new Consumer<ColorIsDarkState>() {

        @Override
        public void accept(@NonNull ColorIsDarkState colorIsDarkState) {
            invalidateColors(colorIsDarkState);
        }
    }, onErrorLogAndRethrow()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 10 with NonNull

use of io.reactivex.annotations.NonNull in project Shuttle by timusus.

the class AestheticTextInputLayout method onAttachedToWindow.

@SuppressWarnings("ConstantConditions")
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    subs = new CompositeDisposable();
    subs.add(Aesthetic.get(getContext()).textColorSecondary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@NonNull Integer color) {
            TextInputLayoutUtil.setHint(AestheticTextInputLayout.this, adjustAlpha(color, 0.7f));
        }
    }, onErrorLogAndRethrow()));
    subs.add(ViewUtil.getObservableForResId(getContext(), backgroundResId, Aesthetic.get(getContext()).colorAccent()).compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@NonNull Integer color) {
            invalidateColors(color);
        }
    }, onErrorLogAndRethrow()));
}
Also used : Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

NonNull (io.reactivex.annotations.NonNull)39 Disposable (io.reactivex.disposables.Disposable)17 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Consumer (io.reactivex.functions.Consumer)14 Function (io.reactivex.functions.Function)13 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)6 OnClick (butterknife.OnClick)5 List (java.util.List)5 RequestBody (okhttp3.RequestBody)5 ObservableEmitter (io.reactivex.ObservableEmitter)4 ObservableOnSubscribe (io.reactivex.ObservableOnSubscribe)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Headers (okhttp3.Headers)3 View (android.view.View)2 ANError (com.androidnetworking.error.ANError)2 User (com.khmelenko.lab.varis.network.response.User)2 LzyResponse (com.lzy.demo.model.LzyResponse)2 ServerModel (com.lzy.demo.model.ServerModel)2 Action (io.reactivex.functions.Action)2