Esempio n. 1
0
  /**
   * Delete contact call
   *
   * @param contact
   */
  private void deleteContact(Contact contact) {

    apiService
        .deleteContact(contact.getId())
        .observeOn(AndroidSchedulers.mainThread())
        .doOnRequest(aLong -> showLoader("Deleting contact..."))
        .doOnNext(
            contact1 -> {
              hideLoader();

              Message.show(getContext(), "Contact Deleted");
              activity.supportFinishAfterTransition();
            })
        .doOnError(throwable -> hideLoader())
        .subscribe(
            new RetroSubscriber<Contact>() {
              @Override
              public void onRetrofitError(RetrofitError error) {
                super.onRetrofitError(error);

                String message;

                if (error.getKind() == RetrofitError.Kind.NETWORK) message = "Network error";
                else message = "Something went wrong";

                Message.show(getContext(), message);
              }
            });
  }
Esempio n. 2
0
  /**
   * Update contact call
   *
   * @param contact
   */
  private void updateContact(Contact contact) {

    apiService
        .updateContact(contact.getId(), contact.getAsMap())
        .observeOn(AndroidSchedulers.mainThread())
        .doOnNext(contact1 -> Snackbar.make(this, "Profile Updated", Snackbar.LENGTH_SHORT).show())
        .doOnError(throwable -> showRetryMessage(contact))
        .subscribe(
            new RetroSubscriber<Contact>() {

              @Override
              public void onNetworkError(RetrofitError error) {
                super.onNetworkError(error);
                Message.show(getContext(), Constants.ERROR_NETWORK);
              }
            });
  }