1

i'm trying to subscribe to a constructor so as not to make the user signup every time but once they use the phone number register it should subscribe to user and refresh the data. i tried this it didn't subscribe but it register the users in my database

compositeDisposable.add(
                            myCatchyAPI.updateUserInfo(Common.API_KEY,
                                    account.getPhoneNumber().toString(),
                                    edt_user_name.getText().toString(),

edt_user_address.getText().toString(),
                                    account.getId())
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(updateUserModel ->    

all i got was [UPDATE USER API RETURN] success but not subcribing to updateUserModel

btn_update.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.show();
            AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
                @Override
                public void onSuccess(Account account) {
                    compositeDisposable.add(
                            myCatchyAPI.updateUserInfo(Common.API_KEY,
                                    account.getPhoneNumber().toString(),
                                    edt_user_name.getText().toString(),
                                    edt_user_address.getText().toString(),
                                    account.getId())
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(updateUserModel -> {
                                if (updateUserModel.isSuccess())
                                {
                                    // refresh if it already has users before
                                    compositeDisposable.add(
                                            myCatchyAPI.getUser(Common.API_KEY, account.getId())
                                                    .subscribeOn(Schedulers.io())
                                                    .observeOn(AndroidSchedulers.mainThread())
                                                    .subscribe(userModel -> {

                                               if (userModel.isSuccess())
                                               {
                                                  // Common.currentUser = userModel.getResult().get(0);
                                                   //                                                       startActivity(new Intent(UpdateInfoActivity.this,HomeActivity.class));
                                                   //                                                       finish();
                                                   Common.currentUser = userModel.getResult().get(0);
                                                   Intent intent = new Intent(UpdateInfoActivity.this, HomeActivity.class);
                                                   startActivity(intent);
                                                   finish();

                                               }
                                               else
                                               {
                                                   Toast.makeText(UpdateInfoActivity.this, "[GET USER RESULT]"+userModel.getMessage(), Toast.LENGTH_SHORT).show();
                                               }

                                                        dialog.dismiss();

                                                    },
                                                   throwable -> {
                                                       dialog.dismiss();
                                                       Toast.makeText(UpdateInfoActivity.this, "[GET USER]"+throwable.getMessage(), Toast.LENGTH_SHORT).show();
                                                   })
                                    );
                                }
                                else
                                {
                                    Toast.makeText(UpdateInfoActivity.this, "[UPDATE USER API RETURN]"+updateUserModel.getMessage(), Toast.LENGTH_SHORT).show();
                                }
                                dialog.dismiss();
                                    },
                                    throwable -> {
                                dialog.dismiss();
                                        Toast.makeText(UpdateInfoActivity.this, "[UPDATE USER API]"+throwable.getMessage(), Toast.LENGTH_SHORT).show();
                                    })
                    );
                }

                @Override
                public void onError(AccountKitError accountKitError) {
                    Toast.makeText(UpdateInfoActivity.this, "[ACCOUT KIT ERROR ]"+accountKitError.getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    });
}    
Emi-Marfe
  • 11
  • 6
  • you need to convert listener to observable, this link is helpful https://stackoverflow.com/questions/42118782/replace-callbacks-with-observables-from-rxjava – Alireza Tizfahm Fard Aug 17 '19 at 17:45

0 Answers0