rx.functions.Action1 Java Examples

The following examples show how to use rx.functions.Action1. 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: MainPresenter.java    From MVPExamples with MIT License 6 votes vote down vote up
public MainPresenter() {
    App.getServerAPI()
        .getItems(DEFAULT_NAME.split("\\s+")[0], DEFAULT_NAME.split("\\s+")[1])
        .delay(1, TimeUnit.SECONDS)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<ServerAPI.Response>() {
            @Override
            public void call(ServerAPI.Response response) {
                items = response.items;
                publish();
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                error = throwable;
                publish();
            }
        });
}
 
Example #2
Source File: CommonRemoteDataSource.java    From DoingDaily with Apache License 2.0 6 votes vote down vote up
@Override
public void getGankPictures(int pageIndex, @NonNull final GankPictureCallback callback) {

    NetworkManager.getGankAPI().getPictures(pageIndex).subscribeOn(Schedulers.newThread())//子线程访问网络
            .observeOn(AndroidSchedulers.mainThread())//回调到主线程
            .subscribe(new Action1<PictureGankBean>() {
                @Override
                public void call(PictureGankBean bean) {
                    callback.onPicturesLoaded(bean);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    callback.onDataNotAvailable();
                }
            });
}
 
Example #3
Source File: ResetPasswordFragment.java    From talk-android with MIT License 6 votes vote down vote up
@OnClick({R.id.btn_reset})
public void onClick(View view) {
    if (view.getId() == R.id.btn_reset) {
        String passwordStr = etPassword.getText().toString();
        String passwordStr2 = etEtPassword2.getText().toString();
        if (StringUtil.isBlank(passwordStr)) {
            Toast.makeText(getActivity(), R.string.password_required, Toast.LENGTH_SHORT).show();
            return;
        }
        if (!passwordStr.equals(passwordStr2)) {
            Toast.makeText(getActivity(), R.string.password_not_equal, Toast.LENGTH_SHORT).show();
            return;
        }

        TalkClient.getInstance().getAccountApi()
                .resetPassword(passwordStr)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<User>() {
                    @Override
                    public void call(User user) {
                        RegisterActivity.initUserData(getActivity(), user);
                        TransactionUtil.goTo(getActivity(), ChooseTeamActivity.class, true);
                    }
                }, new ApiErrorAction());
    }
}
 
Example #4
Source File: UseRxJavaRightWayActivity.java    From AndroidRxJavaSample with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_use_rxjava_right_way);
    tvContent = (TextView) findViewById(R.id.tv_content);
    subscriptionForUser = userApi.getUserInfo()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<Response>() {
                @Override
                public void call(Response response) {
                    String content = new String(((TypedByteArray) response.getBody()).getBytes());
                    tvContent.setText("receiver data : " + content);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    tvContent.setText("receiver error : " + throwable.getMessage());
                }
            });

    compositeSubscription.add(subscriptionForUser);

}
 
Example #5
Source File: TryWhenFragment.java    From AndroidRxJavaSample with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    super.onClick(v);
    switch (v.getId()) {
        case R.id.btn_operator:
            tvLogs.setText("");
            userApi.getUserInfoNoToken()
                    .retryWhen(new RetryWithDelay(3, 3000))
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new Action1<Response>() {
                        @Override
                        public void call(Response response) {
                            String content = new String(((TypedByteArray) response.getBody()).getBytes());
                            printLog(tvLogs, "", content);
                        }
                    }, new Action1<Throwable>() {
                        @Override
                        public void call(Throwable throwable) {
                            throwable.printStackTrace();
                        }
                    });
    }
}
 
Example #6
Source File: ChatActivity.java    From talk-android with MIT License 6 votes vote down vote up
@Override
public void editMessage(Message msg, String text) {
    if (msg.getStatus() == MessageDataProcess.Status.NONE.ordinal()) {
        presenter.updateMessage(msg.get_id(), text);
    } else {
        msg.setBody(text);
        MessageRealm.getInstance().addOrUpdate(msg)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<Message>() {
                    @Override
                    public void call(Message message) {
                        BusProvider.getInstance().post(new NewMessageEvent(message));
                    }
                }, new RealmErrorAction());
        adapter.updateOne(msg.get_id(), RowFactory.getInstance()
                .makeRows(msg, ChatActivity.this, messageActionCallback, retriever));
    }
}
 
Example #7
Source File: RxUtil.java    From BookReader with Apache License 2.0 6 votes vote down vote up
public static <T> Observable.Transformer<T, T> rxCacheBeanHelper(final String key) {
    return new Observable.Transformer<T, T>() {
        @Override
        public Observable<T> call(Observable<T> observable) {
            return observable
                    .subscribeOn(Schedulers.io())//指定doOnNext执行线程是新线程
                    .doOnNext(new Action1<T>() {
                        @Override
                        public void call(final T data) {
                            Schedulers.io().createWorker().schedule(new Action0() {
                                @Override
                                public void call() {
                                    LogUtils.d("get data from network finish ,start cache...");
                                    ACache.get(ReaderApplication.getsInstance())
                                            .put(key, new Gson().toJson(data, data.getClass()));
                                    LogUtils.d("cache finish");
                                }
                            });
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
Example #8
Source File: AccountPresenter.java    From TLint with Apache License 2.0 6 votes vote down vote up
private void loadUserList() {
    mSubscription = Observable.create(new Observable.OnSubscribe<List<User>>() {
        @Override
        public void call(Subscriber<? super List<User>> subscriber) {
            subscriber.onNext(mUserDao.queryBuilder().list());
        }
    })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<User>>() {
                @Override
                public void call(List<User> users) {
                    mAccountView.renderUserList(users);
                }
            });
}
 
Example #9
Source File: Example11.java    From AnDevCon-RxPatterns with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    TextView tv = (TextView) view.findViewById(R.id.hiddenIdTextView);
    if (tv!=null) {
        String gistName = tv.getText().toString();
        mGitHubClient.gist(gistName)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<GistDetail>() {
                    @Override
                    public void call(GistDetail gistDetail) {
                        displayFileList(gistDetail);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                    }
                });

        mGistVisible = gistName;
        displayHomeAsUp(true); // just hacking everything together with a single activity for simplicity
    }
}
 
Example #10
Source File: NewsFragment.java    From ZZShow with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mParam1 = getArguments().getString(ARG_PARAM1);
        mParam2 = getArguments().getString(ARG_PARAM2);
    }
    mSubscription = RxBus.getInstance().toObservable(ChannelChangeEvent.class)
            .subscribe(new Action1<ChannelChangeEvent>() {
                @Override
                public void call(ChannelChangeEvent channelChangeEvent) {
                    KLog.d("NewsChannelPresenterImpl","GET ---------------");
                    if(channelChangeEvent.isChannelChanged()) {
                        mPresenter.loadNewsChannels();
                        if(channelChangeEvent.getChannelName() != null) {
                            mCurrentViewPagerName = channelChangeEvent.getChannelName();
                        }
                    }else{
                        if(channelChangeEvent.getChannelName() != null) {
                            mCurrentViewPagerName = channelChangeEvent.getChannelName();
                            mViewPager.setCurrentItem(getCurrentViewPagerPosition());
                        }
                    }
                }
            });
}
 
Example #11
Source File: FavoritesPresenter.java    From talk-android with MIT License 6 votes vote down vote up
public void getFavorites(String teamId, String maxId) {
    favoritesView.showProgressBar();
    Observable<List<Message>> observable = StringUtil.isBlank(maxId) ? talkApi.getFavorites(teamId)
            : talkApi.getFavorites(teamId, maxId);
    observable.observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<Message>>() {
                @Override
                public void call(List<Message> favorites) {
                    favoritesView.dismissProgressBar();
                    favoritesView.showFavorites(favorites);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable e) {
                    favoritesView.dismissProgressBar();
                    Logger.e(TAG, "get favorites error", e);
                }
            });
}
 
Example #12
Source File: Dispatcher.java    From ZhihuDailyFluxRRD with Apache License 2.0 6 votes vote down vote up
/**
 * 订阅action
 *
 * @param store BaseStore
 */
public void register(final BaseStore store) {
    if (null == store) {
        throw new IllegalArgumentException("the store can't be null");
    }

    final int uniqueId = System.identityHashCode(store);
    if (mStoreSubscriptionHashMap.containsKey(uniqueId)) {
        Subscription subscription = mStoreSubscriptionHashMap.get(uniqueId);
        if (subscription.isUnsubscribed()) {
            mStoreSubscriptionHashMap.remove(uniqueId);
        } else {
            return;
        }
    }

    //将subscription缓存下来,以便之后取消订阅
    mStoreSubscriptionHashMap.put(uniqueId, Apollo.get().toObservable(BaseAction.class.getCanonicalName(), BaseAction.class)
            .subscribe(new Action1<BaseAction>() {
                @Override
                public void call(BaseAction action) {
                    store.onAction(action);
                }
            }));
}
 
Example #13
Source File: Oauth2Activity.java    From talk-android with MIT License 6 votes vote down vote up
private void checkIsNew(User user) {
    if (user.wasNew()) {
        this.user = user;
        MainApp.IMAGE_LOADER.displayImage(user.getAvatarUrl(), dialogAvatar,
                ImageLoaderConfig.AVATAR_OPTIONS);
        TalkClient.getInstance().getTalkApi().getStrikerToken().observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<StrikerTokenResponseData>() {
                    @Override
                    public void call(StrikerTokenResponseData responseData) {
                        if (responseData != null) {
                            MainApp.PREF_UTIL.putString(Constant.STRIKER_TOKEN, responseData.getToken());
                            userDialog.show();
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Logger.e("Oauth2Activity", "fail to get file auth key", throwable);
                    }
                });
    } else {
        TransactionUtil.goTo(this, ChooseTeamActivity.class, true);
    }
}
 
Example #14
Source File: SessionState.java    From java-dcp-client with Apache License 2.0 6 votes vote down vote up
/**
 * Recovers the session state from persisted JSON.
 *
 * @param persisted the persisted JSON format.
 */
public void setFromJson(final byte[] persisted) {
  try {
    SessionState decoded = JACKSON.readValue(persisted, SessionState.class);
    decoded.foreachPartition(new Action1<PartitionState>() {
      int i = 0;

      @Override
      public void call(PartitionState dps) {
        partitionStates.set(i++, dps);
      }
    });
  } catch (Exception ex) {
    throw new RuntimeException("Could not decode SessionState from JSON.", ex);
  }
}
 
Example #15
Source File: QiblaPresenter.java    From android with Apache License 2.0 6 votes vote down vote up
public void getAzimuth() {
    Subscription s = mLocationRepository.getLocation()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnSubscribe(new Action0() {
                @Override
                public void call() {
                    showLoading();
                }
            })
            .subscribe(new Action1<Location>() {
                @Override
                public void call(Location location) {
                    showAzimuth(location);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    showError(throwable);
                }
            });

    mSubscription.add(s);
}
 
Example #16
Source File: LeakingSubjectActivity.java    From android-subscription-leaks with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_leaking_subject);

    // This should leak because it's constantly looping on itself
    mSubject
        .delay(1, TimeUnit.SECONDS)
        .subscribe(new Action1<Long>() {
            @Override public void call(Long aLong) {
                Timber.d("LeakingSubjectActivity received: " + aLong);
                mSubject.onNext(aLong + 1);
            }
        });
}
 
Example #17
Source File: KeyVaultFutures.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
ServiceFuture<T> toFuture(final ServiceCallback<T> callback) {
    final KeyVaultFuture<T> future = new KeyVaultFuture<>();
    Observable.from(callAsync())
            .subscribe(new Action1<TInner>() {
                @Override
                public void call(TInner inner) {
                    T fluent = wrapModel(inner);
                    if (callback != null) {
                        callback.success(fluent);
                    }
                    future.success(fluent);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    if (callback != null) {
                        callback.failure(throwable);
                    }
                    future.failure(throwable);
                }
            });
    return future;
}
 
Example #18
Source File: PmDetailPresenter.java    From TLint with Apache License 2.0 6 votes vote down vote up
@Override
public void block() {
    mGameApi.blockPm(uid, isBlock ? 0 : 1)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<BaseData>() {
                @Override
                public void call(BaseData baseData) {
                    ToastUtil.showToast(isBlock ? "取消屏蔽成功" : "屏蔽成功");
                    isBlock = !isBlock;
                    mPmDetailView.isBlock(isBlock);
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    ToastUtil.showToast(isBlock ? "取消屏蔽失败,请检查网络后重试" : "屏蔽失败,请检查网络后重试");
                }
            });
}
 
Example #19
Source File: TestActivity.java    From goro with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  GoroService.setup(this, Goro.create());

  Scheduler scheduler = new RxGoro(goro).scheduler("test-queue");
  Observable.just("ok")
      .subscribeOn(scheduler)
      .subscribe(new Action1<String>() {
        @Override
        public void call(String s) {
          result = "ok";
          resultSync.countDown();
        }
      });

  Observable.error(new RuntimeException("test error"))
      .subscribeOn(scheduler)
      .subscribe(Actions.empty(), new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) {
          error = throwable;
          errorSync.countDown();
        }
      });
}
 
Example #20
Source File: Example6.java    From AnDevCon-RxPatterns with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    startSub = exampleObservable
            .doOnUnsubscribe(new Action0() {
                @Override
                public void call() {
                    Log.d(TAG, "Called unsubscribe OnStop()");
                }
            })
            .subscribe(new Action1<Integer>() {
                @Override
                public void call(Integer i) {
                    mOutputTextView2.setText(Integer.toString(i) + " OnStart()");
                }
            }, errorHandler);
}
 
Example #21
Source File: NoteController.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static void saveNoteZipAsync(final SaveNoteListener l){
    Observable.create(new Observable.OnSubscribe<String>() {
        @Override
        public void call(Subscriber<? super String> subscriber) {
            String zipFilePath =  NotePersistenceController.saveNoteFiles();
            subscriber.onNext(zipFilePath);
            subscriber.onCompleted();
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(
                    new Action1<String>() {
                        @Override
                        public void call(String path) {
                            l.onZipPath(path);
                        }
                    });
}
 
Example #22
Source File: AppListFragment.java    From AppPlus with MIT License 6 votes vote down vote up
private void subscribeEvents() {
    RxBus.getInstance()
            .toObservable()
            .subscribe(new Action1() {
                @Override
                public void call(Object o) {
                    if(o instanceof RxEvent){
                        RxEvent msg = (RxEvent) o;
                        List<AppEntity> list = new ArrayList<AppEntity>();
                        if(mAdapter!=null){
                            list = mAdapter.getListData();
                        }
                        dealRxEvent(msg, list);
                    }
                }
            });
}
 
Example #23
Source File: MergedObservableTest.java    From mantis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleRemoteObservableMerge() {
    // setup
    Observable<Integer> os = Observable.range(0, 101);
    // serve
    PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000);
    int serverPort = portSelector.acquirePort();
    RemoteRxServer server = RemoteObservable.serve(serverPort, os, Codecs.integer());
    server.start();
    // connect
    Observable<Integer> ro = RemoteObservable.connect("localhost", serverPort, Codecs.integer());

    MergedObservable<Integer> merged = MergedObservable.createWithReplay(1);
    merged.mergeIn("t1", ro);

    // assert
    MathObservable.sumInteger(Observable.merge(merged.get()))
            .toBlocking().forEach(new Action1<Integer>() {
        @Override
        public void call(Integer t1) {
            Assert.assertEquals(5050, t1.intValue()); // sum of number 0-100
        }
    });
}
 
Example #24
Source File: ServiceFuture.java    From autorest-clientruntime-for-java with MIT License 6 votes vote down vote up
/**
 * Creates a ServiceCall from an observable object and a callback.
 *
 * @param observable the observable to create from
 * @param callback the callback to call when events happen
 * @param <T> the type of the response
 * @return the created ServiceCall
 */
public static <T> ServiceFuture<T> fromResponse(final Observable<ServiceResponse<T>> observable, final ServiceCallback<T> callback) {
    final ServiceFuture<T> serviceFuture = new ServiceFuture<>();
    serviceFuture.subscription = observable
            .last()
            .subscribe(new Action1<ServiceResponse<T>>() {
                @Override
                public void call(ServiceResponse<T> t) {
                    if (callback != null) {
                        callback.success(t.body());
                    }
                    serviceFuture.valueSet = serviceFuture.set(t.body());
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    if (callback != null) {
                        callback.failure(throwable);
                    }
                    serviceFuture.setException(throwable);
                }
            });
    return serviceFuture;
}
 
Example #25
Source File: EndlessRecyclerOnScrollListener.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public <T extends BaseV7EndlessResponse> EndlessRecyclerOnScrollListener(BaseAdapter baseAdapter,
    V7<T, ? extends Endless> v7request, Action1<T> successRequestListener,
    ErrorRequestListener errorRequestListener, int visibleThreshold, boolean bypassCache,
    BooleanAction<T> onFirstLoadListener, Action0 onEndOfListReachedListener) {
  this.multiLangPatch = new MultiLangPatch();
  this.onEndlessFinishList = new LinkedList<>();
  this.adapter = baseAdapter;
  this.v7request = v7request;
  this.successRequestListener = successRequestListener;
  this.errorRequestListener = errorRequestListener;
  this.visibleThreshold = visibleThreshold;
  this.bypassCache = bypassCache;
  this.onFirstLoadListener = onFirstLoadListener;
  this.onEndOfListReachedListener = onEndOfListReachedListener;
  this.endCallbackCalled = false;
  this.firstCallbackCalled = false;
  bypassServerCache = false;
}
 
Example #26
Source File: PostPresenter.java    From Hews with MIT License 6 votes vote down vote up
void loadSummary(final Post post) {
    mCompositeSubscription.add(mDataManager.getSummary(post.getKids())
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<Comment>() {
            @Override
            public void call(Comment comment) {
                if (comment != null) {
                    post.setSummary(mUtils.convertHtmlToString(
                        comment.getText().replace("<p>", "<br /><br />").replace("\n", "<br />")));
                    mPostView.showSummary(post.getIndex());
                } else {
                    post.setSummary(null);
                }
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                mPostView.showErrorLog("loadSummary: " + String.valueOf(post.getId()),
                    throwable.toString());
            }
        }));
}
 
Example #27
Source File: SlicingFragment.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
private Action1<Long> updateFiles() {
    return new Action1<Long>() {
        @Override
        public void call(Long aLong) {
            mListener.updateFiles();
        }
    };
}
 
Example #28
Source File: EditActivity.java    From jianshi with Apache License 2.0 5 votes vote down vote up
private void saveDiary() {
  if (!checkNotNull()) {
    Toast.makeText(EditActivity.this, R.string.edit_content_not_null,
        Toast.LENGTH_SHORT).show();
    return;
  }

  String titleString = (TextUtils.isEmpty(title.getText().toString()))
      ? title.getHint().toString() : title.getText().toString();
  String contentString = (TextUtils.isEmpty(content.getText().toString()))
      ? content.getHint().toString() : content.getText().toString();

  if (diary == null) {
    diary = new Diary();
    diary.setTitle(titleString);
    diary.setContent(contentString);
    diary.setUuid(UUID.randomUUID().toString().toUpperCase());
    diary.setTime_created(DateUtil.getCurrentTimeStamp());
  }else {
    diary.setTitle(titleString);
    diary.setContent(contentString);
    diary.setTime_modified(DateUtil.getCurrentTimeStamp());
  }
  diaryService.saveDiary(diary)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new Action1<Void>() {
        @Override
        public void call(Void aVoid) {
          Intent i = ViewActivity.createIntent(EditActivity.this, diary.getUuid());
          startActivity(i);
          finish();
        }
      });
}
 
Example #29
Source File: XiaomiPushReceiver.java    From talk-android with MIT License 5 votes vote down vote up
@Override
public void onReceiveRegisterResult(Context context, MiPushCommandMessage miPushCommandMessage) {
    Logger.d(TAG, "command result");
    String command = miPushCommandMessage.getCommand();
    List<String> arguments = miPushCommandMessage.getCommandArguments();
    final String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);

    if (MiPushClient.COMMAND_REGISTER.equals(command)) {
        if (miPushCommandMessage.getResultCode() == ErrorCode.SUCCESS && BizLogic.isLogin()) {
            if (StringUtil.isBlank(MainApp.PREF_UTIL.getString(Constant.XIAOMI_TOKEN))) {
                MainApp.PREF_UTIL.putString(Constant.XIAOMI_TOKEN, cmdArg1);
            }
            TalkClient.getInstance().getTalkApi()
                    .postToken(cmdArg1)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Action1<Object>() {
                        @Override
                        public void call(Object o) {
                            MainApp.PREF_UTIL.putString(Constant.XIAOMI_TOKEN, cmdArg1);
                            Logger.d(TAG, "xiaomi push register success: " + cmdArg1);
                        }
                    }, new Action1<Throwable>() {
                        @Override
                        public void call(Throwable throwable) {
                            Logger.e(TAG, "xiaomi push  register", throwable);
                        }
                    });
        }
    }
}
 
Example #30
Source File: VerticleHelper.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
public <T> Action1<ResourceResponse<T>> getRxResultHandler(Message<JsonObject> message, boolean withJsonEncode, TypeReference<T> type) {
    return result -> {
        DeliveryOptions deliveryOptions = new DeliveryOptions();
        deliveryOptions.setHeaders(result.getHeaders());
        if (withJsonEncode) {
            message.reply(Json.encode(result.getResponse()), deliveryOptions);
        } else {
            message.reply(result.getResponse(), deliveryOptions);
        }
    };
}