GenericDialogs.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:aptoide-client-v8 作者:
/**
 * Show an AlertDialog with the {@code title} and the {@code message}. The Alert dialog has an
 * "yes" button and a "no" button.
 *
 * @param title Title to apply on AlertDialog
 * @param message Message to asSnack on AlertDialog
 *
 * @return A Observable that shows the dialog when subscribed and return the action made by
 * user. This action is represented by EResponse
 *
 * @see EResponse
 */
public static Observable<EResponse> createGenericYesNoCancelMessage(@NonNull Context context,
    @Nullable String title, @Nullable String message) {
  return Observable.create((Subscriber<? super EResponse> subscriber) -> {
    final AlertDialog dialog = new AlertDialog.Builder(context).setTitle(title)
        .setMessage(message)
        .setPositiveButton(android.R.string.yes, (listener, which) -> {
          subscriber.onNext(EResponse.YES);
          subscriber.onCompleted();
        })
        .setNegativeButton(android.R.string.no, (listener, which) -> {
          subscriber.onNext(EResponse.NO);
          subscriber.onCompleted();
        })
        .setOnCancelListener(listener -> {
          subscriber.onNext(EResponse.CANCEL);
          subscriber.onCompleted();
        })
        .create();
    // cleaning up
    subscriber.add(Subscriptions.create(() -> dialog.dismiss()));
    dialog.show();
  })
      .subscribeOn(AndroidSchedulers.mainThread());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号