io.reactivex.annotations.NonNull Java Examples

The following examples show how to use io.reactivex.annotations.NonNull. 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: RxUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doFinally(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxLifecycleUtils.bindToLifecycle(view));
        }
    };
}
 
Example #2
Source File: ZeroFiveNewsDetailModel.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public Flowable<ZeroFiveNewsDetail> getAcgNewsDetail(final String url) {
  return Flowable.create(new FlowableOnSubscribe<ZeroFiveNewsDetail>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<ZeroFiveNewsDetail> e) throws Exception {
      Element html = Jsoup.connect(url).get();
      if (html == null) {
        e.onError(new Throwable("element html is null"));
      } else {
        ZeroFiveNewsDetail zeroFiveNewsDetail = JP.from(html, ZeroFiveNewsDetail.class);
        e.onNext(zeroFiveNewsDetail);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #3
Source File: ZeroFiveNewsModel.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public Flowable<ZeroFiveNewsPage> getAcgNews(final String typeUrl) {
  return Flowable.create(new FlowableOnSubscribe<ZeroFiveNewsPage>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<ZeroFiveNewsPage> e) throws Exception {
      Element html = Jsoup.connect(typeUrl).get();
      if(html == null){
        e.onError(new Throwable("element html is null"));
      }else {
        ZeroFiveNewsPage zeroFiveNewsPage = JP.from(html, ZeroFiveNewsPage.class);
        e.onNext(zeroFiveNewsPage);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #4
Source File: ZeroFiveNewsDetailPresenter.java    From AcgClub with MIT License 6 votes vote down vote up
public void start2Share(RxPermissions rxPermissions) {
  rxPermissions.request(
      Manifest.permission.WRITE_EXTERNAL_STORAGE,
      Manifest.permission.ACCESS_FINE_LOCATION,
      Manifest.permission.WRITE_EXTERNAL_STORAGE)
      .subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean aBoolean) throws Exception {
          if (aBoolean) {
            mView.showShareView();
          } else {
            mView.showError(R.string.msg_error_check_permission);
          }
        }
      });
}
 
Example #5
Source File: AVUser.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
public Observable<AVUser> dissociateWithAuthData(final String platform) {
  if (StringUtil.isEmpty(platform)) {
    return Observable.error(new IllegalArgumentException(String.format(ILLEGALARGUMENT_MSG_FORMAT, "platform")));
  }

  String objectId = getObjectId();
  if (StringUtil.isEmpty(objectId) || !isAuthenticated()) {
    return Observable.error(new AVException(AVException.SESSION_MISSING,
            "the user object missing a valid session"));
  }
  this.remove(AUTHDATA_TAG + "." + platform);
  return this.saveInBackground().map(new Function<AVObject, AVUser>() {
    public AVUser apply(@NonNull AVObject var1) throws Exception {
      Map<String, Object> authData = (Map<String, Object>) AVUser.this.get(AUTHDATA_TAG);
      if (authData != null) {
        authData.remove(platform);
      }
      return AVUser.this;
    }
  });
}
 
Example #6
Source File: ScheduleNewModel.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public Flowable<ScheduleNew> getScheduleNew(final String url) {
  return Flowable.create(new FlowableOnSubscribe<ScheduleNew>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<ScheduleNew> e) throws Exception {
      Element html = Jsoup.connect(url).get();
      if (html == null) {
        e.onError(new Throwable("element html is null"));
      } else {
        ScheduleNew scheduleNew = JP.from(html, ScheduleNew.class);
        e.onNext(scheduleNew);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #7
Source File: ScheduleOtherModel.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public Flowable<ScheduleOtherPage> getScheduleOtherPage(final String url) {
  return Flowable.create(new FlowableOnSubscribe<ScheduleOtherPage>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<ScheduleOtherPage> e) throws Exception {
      Element html = Jsoup.connect(url).get();
      if (html == null) {
        e.onError(new Throwable("element html is null"));
      } else {
        ScheduleOtherPage scheduleOtherPage = JP.from(html, ScheduleOtherPage.class);
        e.onNext(scheduleOtherPage);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #8
Source File: RxUtil.java    From Hands-Chopping with Apache License 2.0 6 votes vote down vote up
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doFinally(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxLifecycleUtils.bindToLifecycle(view));
        }
    };
}
 
Example #9
Source File: ScheduleVideoModel.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public Flowable<ScheduleVideo> getScheduleVideo(final String url) {
  return Flowable.create(new FlowableOnSubscribe<ScheduleVideo>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<ScheduleVideo> e) throws Exception {
      Element html = Jsoup.connect(url).get();
      if(html == null){
        e.onError(new Throwable("element html is null"));
      }else {
        ScheduleVideo scheduleVideo = JP.from(html, ScheduleVideo.class);
        if (!TextUtils.isEmpty(scheduleVideo.getVideoHtml())) {
          scheduleVideo.setVideoUrl("http://tup.yhdm.tv/?m=1&vid=" + scheduleVideo.getVideoUrl());
        }
        /*StringBuilder scheduleVideoHtmlBuilder = new StringBuilder();
        scheduleVideoHtmlBuilder.append(HtmlConstant.SCHEDULE_VIDEO_CSS);
        scheduleVideoHtmlBuilder.append("<div class=\"player_main\" style=\"position: relative;\"> ");
        scheduleVideoHtmlBuilder.append(scheduleVideo.getVideoHtml());
        scheduleVideoHtmlBuilder.append("</div>");
        scheduleVideo.setVideoHtml(scheduleVideoHtmlBuilder.toString());*/
        e.onNext(scheduleVideo);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #10
Source File: ParallelFlowableLife.java    From rxjava-RxLife with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void subscribe(@NonNull Subscriber<? super T>[] subscribers) {
    if (!validate(subscribers)) {
        return;
    }

    int n = subscribers.length;

    Subscriber<? super T>[] parents = new Subscriber[n];

    for (int i = 0; i < n; i++) {
        Subscriber<? super T> a = subscribers[i];
        if (a instanceof ConditionalSubscriber) {
            parents[i] = new LifeConditionalSubscriber<>((ConditionalSubscriber<? super T>) a, scope);
        } else {
            parents[i] = new LifeSubscriber<>(a, scope);
        }
    }
    ParallelFlowable<T> upStream = this.upStream;
    if (onMain) upStream = upStream.runOn(AndroidSchedulers.mainThread());
    upStream.subscribe(parents);
}
 
Example #11
Source File: HttpMethods.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 订阅请求
 */
public static <T> void toSubscribe(Observable<T> observable, BaseObserver<T> observer) {
    // 指定subscribe()发生在IO线程
    observable.subscribeOn(Schedulers.io())
            .unsubscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .retryWhen(new Function<Observable<Throwable>, ObservableSource<?>>() {
                private int mRetryCount;

                @Override
                public ObservableSource<?> apply(@NonNull Observable<Throwable> throwableObservable) {
                    return throwableObservable.flatMap((Function<Throwable, ObservableSource<?>>) throwable -> {
                        boolean exceptionType = (throwable instanceof NetworkErrorException
                                || throwable instanceof ConnectException
                                || throwable instanceof SocketTimeoutException
                                || throwable instanceof TimeoutException) && mRetryCount < 3;
                        if (exceptionType) {
                            mRetryCount++;
                            return Observable.timer(4000, TimeUnit.MILLISECONDS);
                        }
                        return Observable.error(throwable);
                    });
                }
            })
            .subscribe(observer);
}
 
Example #12
Source File: ContactDao.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 插入联系人
 *
 * @param name
 * @param accountName
 * @param memo
 */
public void insertContact(@NonNull String name, @NonNull String accountName, @NonNull String memo) {
    Cursor cursor = mDatabase.query(ContactEntry.TABLE_NAME, new String[]{ContactEntry.COLUMN_ACCOUNT_NAME}, ContactEntry.COLUMN_ACCOUNT_NAME + " = ?", new String[]{accountName}, null, null, null);
    if (cursor.getCount() == 0) {
        ContentValues values = new ContentValues();
        values.put(ContactEntry.COLUMN_ACCOUNT_NAME, accountName);
        values.put(ContactEntry.COLUMN_CONTACT_NAME, name);
        values.put(ContactEntry.COLUMN_MEMO, memo);
        mDatabase.insert(ContactEntry.TABLE_NAME, null, values);
    } else {
        updateContact(accountName, name, memo);
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
}
 
Example #13
Source File: RxUtil.java    From lifecycle-component with Apache License 2.0 6 votes vote down vote up
public static <T> ObservableTransformer<T, T> applySchedulers(final IView view) {
    return new ObservableTransformer<T, T>() {
        @Override
        public Observable<T> apply(Observable<T> observable) {
            return observable.subscribeOn(Schedulers.io())
                    .doOnSubscribe(new Consumer<Disposable>() {
                        @Override
                        public void accept(@NonNull Disposable disposable) throws Exception {
                            view.showLoading();//显示进度条
                        }
                    })
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .observeOn(AndroidSchedulers.mainThread())
                    .doFinally(new Action() {
                        @Override
                        public void run() {
                            view.hideLoading();//隐藏进度条
                        }
                    }).compose(RxLifecycleUtils.bindToLifecycle(view));
        }
    };
}
 
Example #14
Source File: ScheduleMainPresenter.java    From AcgClub with MIT License 6 votes vote down vote up
/**
 * 视频观看权限申请
 */
public void checkPermission2ScheduleVideo(RxPermissions rxPermissions, final String videoUrl) {
  if (TextUtils.isEmpty(videoUrl)) {
    mView.showError(R.string.msg_error_url_null);
    return;
  }
  rxPermissions.request(permission.WRITE_EXTERNAL_STORAGE,
      permission.READ_PHONE_STATE,
      permission.ACCESS_NETWORK_STATE,
      permission.ACCESS_WIFI_STATE)
      .subscribe(new Consumer<Boolean>() {
        @Override
        public void accept(@NonNull Boolean aBoolean) throws Exception {
          if (aBoolean) {
            mView.start2ScheduleVideo(videoUrl);
          } else {
            mView.showError(R.string.msg_error_check_permission);
          }
        }
      });
}
 
Example #15
Source File: ElementaryFragment.java    From AndroidFrame with Apache License 2.0 6 votes vote down vote up
/**
 * 搜索图片
 */
private void search(String key) {
    swipeRefreshLayout.setRefreshing(true);
    unsuscribe();
    disposable = HttpUtil.getZhuangBiApi().search(key).subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<List<ZhuangbiImage>>() {
                @Override
                public void accept(@NonNull List<ZhuangbiImage> zhuangbiImages) throws Exception {
                    Logger.e(LOG_TAG, "==网络请求成功==");
                    //进度条停止
                    swipeRefreshLayout.setRefreshing(false);
                    //给列表设置数据
                    zhuangBiListAdapter.setZhuangbiImages(zhuangbiImages);
                }

            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    swipeRefreshLayout.setRefreshing(false);
                    Toast.makeText(LQBApp.getApp(), "请求失败,请刷新重试", Toast.LENGTH_SHORT).show();
                    Logger.e(LOG_TAG, "==网络请求错误==");
                }
            });
}
 
Example #16
Source File: GankBeautyResultToItemsMapper.java    From AndroidFrame with Apache License 2.0 6 votes vote down vote up
@Override
public List<Item> apply(@NonNull GankBeautyResult gankBeautyResult) throws Exception {
    List<GankBeautyResult.ResultsBean> results = gankBeautyResult.getResults();
    List<Item> itemList = new ArrayList<>();
    //2018-01-29T07:40:56.269Z
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    for (GankBeautyResult.ResultsBean result : results) {
        Date inDate = sdf1.parse(result.getCreatedAt());
        String outDateStr = sdf2.format(inDate);
        Item item = new Item();
        item.description = outDateStr;
        item.imageUrl = result.getUrl();
        itemList.add(item);
    }
    return itemList;
}
 
Example #17
Source File: XianDuPagePresenter.java    From scallop with MIT License 5 votes vote down vote up
@Override
    public void getSubCategories(String parent) {
        Observable<BaseResponse<XianDuSubCategory>> observable = dataManager.getXianDuSubCategories(parent);
        observable.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .map(new Function<BaseResponse<XianDuSubCategory>, List<XianDuSubCategory>>() {
            @Override
            public List<XianDuSubCategory> apply(@NonNull BaseResponse<XianDuSubCategory> xianDuSubCategoryBaseResponse)
                    throws Exception {
                return xianDuSubCategoryBaseResponse.getResults();
            }
        }).subscribe(new Observer<List<XianDuSubCategory>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {
                disposable = d;
            }

            @Override
            public void onNext(@NonNull List<XianDuSubCategory> xianDuSubCategories) {
                getView().showList(xianDuSubCategories);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                getView().showError(e.getMessage());
            }

            @Override
            public void onComplete() {
//                getView().showSuccessful();
            }
        });
    }
 
Example #18
Source File: PicturesPresenter.java    From scallop with MIT License 5 votes vote down vote up
@Override
    public void getPictures(String category, final int page) {
        Observable<BaseResponse<GanHuo>> observable = dataManager.getGanHuo(category, page);
        observable.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .map(new Function<BaseResponse<GanHuo>, List<GanHuo>>() {
            @Override
            public List<GanHuo> apply(@NonNull BaseResponse<GanHuo> ganHuoBaseResponse)
                    throws Exception {
                return ganHuoBaseResponse.getResults();
            }
        }).subscribe(new Observer<List<GanHuo>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {
                disposable = d;
            }

            @Override
            public void onNext(@NonNull List<GanHuo> ganHuoList) {
                getView().showList(ganHuoList, page);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                getView().showError(e.getMessage());
            }

            @Override
            public void onComplete() {
//                getView().showComplete();
            }
        });

    }
 
Example #19
Source File: WxLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
private void getToken(final String code) {
    mTokenSubscribe = Flowable.create(new FlowableOnSubscribe<WxToken>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<WxToken> wxTokenEmitter) {
            Request request = new Request.Builder().url(buildTokenUrl(code)).build();
            try {
                Response response = mClient.newCall(request).execute();
                JSONObject jsonObject = new JSONObject(response.body().string());
                WxToken token = new WxToken(jsonObject);
                wxTokenEmitter.onNext(token);
                wxTokenEmitter.onComplete();
            } catch (IOException | JSONException e) {
                wxTokenEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<WxToken>() {
                @Override
                public void accept(@NonNull WxToken wxToken) {
                    if (mFetchUserInfo) {
                        mLoginListener.beforeFetchUserInfo(wxToken);
                        fetchUserInfo(wxToken);
                    } else {
                        mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.WX, wxToken));
                        LoginUtil.recycle();
                    }

                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    mLoginListener.loginFailure(new Exception(throwable.getMessage()), ShareLogger.INFO.ERR_GET_TOKEN_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #20
Source File: TwitterLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    mSubscribe = Flowable.create(new FlowableOnSubscribe<TwitterUser>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<TwitterUser> userEmitter) {

            TwitterApiClient apiClient = TwitterCore.getInstance().getApiClient();
            Call<User> userCall = apiClient.getAccountService().verifyCredentials(true, false, false);

            try {
                Response<User> execute = userCall.execute();
                userEmitter.onNext(new TwitterUser(execute.body()));
                userEmitter.onComplete();
            } catch (Exception e) {
                ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR);
                userEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<TwitterUser>() {
                @Override
                public void accept(@NonNull TwitterUser user) {
                    mLoginListener.loginSuccess(new LoginResultData(LoginPlatform.TWITTER, token, user));
                    LoginUtil.recycle();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #21
Source File: WeiboLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    mSubscribe = Flowable.create(new FlowableOnSubscribe<WeiboUser>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<WeiboUser> weiboUserEmitter) {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(buildUserInfoUrl(token, USER_INFO)).build();
            try {
                Response response = client.newCall(request).execute();
                JSONObject jsonObject = new JSONObject(response.body().string());
                WeiboUser user = WeiboUser.parse(jsonObject);
                weiboUserEmitter.onNext(user);
                weiboUserEmitter.onComplete();
            } catch (IOException | JSONException e) {
                ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR);
                weiboUserEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<WeiboUser>() {
                @Override
                public void accept(@NonNull WeiboUser weiboUser) throws Exception {
                    mLoginListener.loginSuccess(
                            new LoginResultData(LoginPlatform.WEIBO, token, weiboUser));
                    LoginUtil.recycle();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #22
Source File: QQLoginInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void fetchUserInfo(final BaseToken token) {
    mSubscribe = Flowable.create(new FlowableOnSubscribe<QQUser>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<QQUser> qqUserEmitter) {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder().url(buildUserInfoUrl(token, URL)).build();

            try {
                Response response = client.newCall(request).execute();
                JSONObject jsonObject = new JSONObject(response.body().string());
                QQUser user = QQUser.parse(token.getOpenid(), jsonObject);
                qqUserEmitter.onNext(user);
                qqUserEmitter.onComplete();
            } catch (IOException | JSONException e) {
                ShareLogger.e(ShareLogger.INFO.FETCH_USER_INOF_ERROR);
                qqUserEmitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<QQUser>() {
                @Override
                public void accept(@NonNull QQUser qqUser) {
                    mLoginListener.loginSuccess(
                            new LoginResultData(LoginPlatform.QQ, token, qqUser));
                    LoginUtil.recycle();
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    mLoginListener.loginFailure(new Exception(throwable), ShareLogger.INFO.ERR_FETCH_CODE);
                    LoginUtil.recycle();
                }
            });
}
 
Example #23
Source File: RxConsumer.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(@NonNull BaseBean<T> tBaseBean) throws Exception {
    if (tBaseBean.errorCode == NetConfig.REQUEST_SUCCESS){
        onSuccess(tBaseBean.data);
    }else {
        onFail(tBaseBean.errorMsg);
    }
}
 
Example #24
Source File: WxShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void shareImage(final int platform, final ShareImageObject shareImageObject,
                       final Activity activity, final ShareListener listener) {

    mShareImage = Flowable.create(new FlowableOnSubscribe<Pair<Bitmap, byte[]>>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<Pair<Bitmap, byte[]>> emitter) {
            try {
                String imagePath = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(Pair.create(BitmapFactory.decodeFile(imagePath),
                        ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE)));
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Pair<Bitmap, byte[]>>() {
                @Override
                public void accept(@NonNull Pair<Bitmap, byte[]> pair) {
                    WXImageObject imageObject = new WXImageObject(pair.first);

                    WXMediaMessage message = new WXMediaMessage();
                    message.mediaObject = imageObject;
                    message.thumbData = pair.second;

                    sendMessage(platform, message, buildTransaction("image"));
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    listener.shareFailure(new Exception(throwable));
                    recycle();
                    activity.finish();
                }
            });
}
 
Example #25
Source File: WxShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
private void shareFunc(final int platform, final String title, final String targetUrl
        , final String summary, final String miniId, final String miniPath
        , final ShareImageObject shareImageObject
        , final Activity activity, final ShareListener listener) {

    mShareFunc = Flowable.create(new FlowableOnSubscribe<byte[]>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<byte[]> emitter) {
            try {
                String imagePath = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE));
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<byte[]>() {
                @Override
                public void accept(@NonNull byte[] bytes) {
                    handleShareWx(platform, title, targetUrl, summary
                            , bytes, miniId, miniPath, listener);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    listener.shareFailure(new Exception(throwable));
                    recycle();
                    activity.finish();
                }
            });
}
 
Example #26
Source File: QQShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
@Override
public void shareImage(final int platform, final ShareImageObject shareImageObject,
                       final Activity activity, final ShareListener listener) {
    mShareImage = Flowable.create(new FlowableOnSubscribe<String>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<String> emitter) throws Exception {
            try {
                emitter.onNext(ImageDecoder.decode(activity, shareImageObject));
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<String>() {
                @Override
                public void accept(@NonNull String localPath) throws Exception {
                    if (platform == SharePlatform.QZONE) {
                        shareToQzoneForImage(localPath, activity, listener);
                    } else {
                        shareToQQForImage(localPath, activity, listener);
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    listener.shareFailure(new Exception(throwable));
                    recycle();
                    activity.finish();
                }
            });
}
 
Example #27
Source File: JudgeModel.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
public static List<String> getJudgesStringArrayListOf(@NonNull ArrayList<JudgeModel> usernames) {
  List<String> stringList = new ArrayList<>();
  for (int i = 0; i < usernames.size(); i++) {
    stringList.add(usernames.get(i).getmUsername());
  }
  return stringList;
}
 
Example #28
Source File: WeiboShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
private void shareTextOrImage(final Pair<String, byte[]> shareImageObject, final String title, final String targetUrl, final String summary,
                              final Activity activity, final ShareListener listener) {

    mShareImage = Flowable.create(new FlowableOnSubscribe<Pair<String, byte[]>>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<Pair<String, byte[]>> emitter) {
            try {
                emitter.onNext(shareImageObject);
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<Pair<String, byte[]>>() {
                @Override
                public void accept(@NonNull Pair<String, byte[]> stringPair) {
                    handleShare(stringPair, title, targetUrl, summary, listener);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) {
                    listener.shareFailure(new Exception(throwable));
                    recycle();
                    activity.finish();
                }
            });
}
 
Example #29
Source File: ScheduleMainModel.java    From AcgClub with MIT License 5 votes vote down vote up
@Override
public Flowable<DilidiliInfo> getDilidiliInfo() {
  return Flowable.create(new FlowableOnSubscribe<DilidiliInfo>() {
    @Override
    public void subscribe(@NonNull FlowableEmitter<DilidiliInfo> e) throws Exception {
      Element html = Jsoup.connect(HtmlConstant.YHDM_M_URL).get();
      if (html == null) {
        e.onError(new Throwable("element html is null"));
      } else {
        DilidiliInfo dilidiliInfo = JP.from(html, DilidiliInfo.class);
        /*Iterator<ScheduleWeek> scheudleWeekIterator = dilidiliInfo.getScheduleWeek().iterator();
        while (scheudleWeekIterator.hasNext()) {
          ScheduleWeek scheduleWeek = scheudleWeekIterator.next();
          Iterator<ScheduleWeek.ScheduleItem> scheduleItemIterator = scheduleWeek
              .getScheduleItems().iterator();
          while (scheduleItemIterator.hasNext()) {
            ScheduleWeek.ScheduleItem scheduleItem = scheduleItemIterator.next();
            if (scheduleItem.getAnimeLink().contains("www.005.tv")) {
              scheduleItemIterator.remove();
            }
          }
        }
        Iterator<ScheduleBanner> scheudleBannerIterator = dilidiliInfo.getScheduleBanners()
            .iterator();
        while (scheudleBannerIterator.hasNext()) {
          ScheduleBanner scheudleBanner = scheudleBannerIterator.next();
          if (TextUtils.isEmpty(scheudleBanner.getImgUrl()) |
              TextUtils.isEmpty(scheudleBanner.getAnimeLink()) |
              !scheudleBanner.getAnimeLink().contains("anime")) {
            scheudleBannerIterator.remove();
          }
        }*/
        e.onNext(dilidiliInfo);
        e.onComplete();
      }
    }
  }, BackpressureStrategy.BUFFER);
}
 
Example #30
Source File: QQShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@SuppressLint("CheckResult")
private void shareFunc(final int platform, final String title, final String targetUrl, final String summary,
                       final ShareImageObject shareImageObject, final boolean immediate, final Activity activity, final ShareListener listener) {
    mShareFunc = Flowable.create(new FlowableOnSubscribe<String>() {
        @Override
        public void subscribe(@NonNull FlowableEmitter<String> emitter) {
            try {
                if (immediate) {
                    emitter.onNext(shareImageObject.getPathOrUrl());
                } else {
                    emitter.onNext(ImageDecoder.decode(activity, shareImageObject));
                }
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, BackpressureStrategy.DROP)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<String>() {
                @Override
                public void accept(@NonNull String s) {
                    if (platform == SharePlatform.QZONE) {
                        shareToQZoneForMedia(title, targetUrl, summary, s, activity, listener);
                    } else {
                        shareToQQForMedia(title, summary, targetUrl, s, activity, listener);
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(@NonNull Throwable throwable) throws Exception {
                    listener.shareFailure(new Exception(throwable));
                    recycle();
                    activity.finish();
                }
            });
}