0

我正在尝试订阅以加载用户信息,但即使我的数据库中仍有用户,它也不起作用

已经检查并检查了任何人都可以帮助我吗

    compositeDisposable.add(myRestaurantAPI.getUser(Common.API_KEY, account.getId())
                                            .subscribeOn(Schedulers.io())
                                            .observeOn(AndroidSchedulers.mainThread())
                                            .subscribe(userModel -> {

                                                        Log.d(TAG, "AuthViewModel: viewmodel is working in splash screen...");

                                                        if (userModel.isSuccess()) // if user is in database
                                                        {
                                                            Log.d(TAG, "AuthViewModel: userModel is working in splash screen...");
                                                            Common.currentUser = userModel.getResult().get(0);
                                                            Intent intent = new Intent(SplashScreen.this, HomeActivity.class);
                                                            startActivity(intent);
                                                            finish();
                                                        } else // if user isnt available yet send them back to update activity
                                                        {
                                                            Intent intent = new Intent(SplashScreen.this, UpdateInfoActivity.class);
                                                            startActivity(intent);
                                                            finish();
                                                        }


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

我希望它从数据库加载并直接转到 HomeActivity 但它不断将我送回 UpdateInfoActivity .. 这是我的 API

    public interface IMyRestaurantAPI {
    @GET("user")
    Observable<UserModel> getUser(@Query("key") String apiKey,
                                  @Query("fbid") String fbid);
    @POST("user")
    @FormUrlEncoded
    Observable<UpdateUserModel> updateUserInfo(@Field("key") String apiKey,
                                               @Field("userPhone") String userPhone,
                                               @Field("userName") String userName,
                                               @Field("userAddress") String userAddress,
                                               @Field("fbid") String fbid);
}

这是我的模型

    public class UserModel { private boolean success;
private String message; private List<User> result;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<User> getResult() {
        return result;
    }

    public void setResult(List<User> result) {
        this.result = result;
    }
}

这是我的更新信息活动,它将数据获取到我的数据库,但也没有订阅

    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(myRestaurantAPI.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 -> {
                                            Log.d(TAG, "AuthViewModel: viewmodel is working in update111...");
                                    if (updateUserModel.isSuccess())
                                    {
                                        Log.d(TAG, "AuthViewModel: updateUserModel is working in update...");
                                        // refresh if it already has users before
                                        compositeDisposable.add(myRestaurantAPI.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();
                    }
                });
            }
        });  
4

0 回答 0