Commit fba63ef07b8a41faa0b26fbe874d8fc4df7271c6
1 parent
8a424516
修改我的页面更新数据逻辑
Showing
1 changed file
with
16 additions
and
8 deletions
app/src/main/java/com/cnlive/gundam/main/ui/fragment/ConfigFragment.java
| ... | ... | @@ -18,6 +18,7 @@ import com.cnlive.gundam.user.activity.LoginActivity; |
| 18 | 18 | import com.cnlive.gundam.user.activity.UserPersonalActivity; |
| 19 | 19 | import com.cnlive.gundam.user.auth.UserService; |
| 20 | 20 | import com.cnlive.gundam.user.model.User; |
| 21 | +import com.cnlive.gundam.user.util.ToastUtil; | |
| 21 | 22 | import com.cnlive.libs.user.IUserService; |
| 22 | 23 | import com.cnlive.libs.user.UserUtil; |
| 23 | 24 | import com.cnlive.libs.user.model.UserData; |
| ... | ... | @@ -29,7 +30,8 @@ import com.cnlive.libs.util.data.network.Callback; |
| 29 | 30 | |
| 30 | 31 | public class ConfigFragment extends Fragment implements View.OnClickListener { |
| 31 | 32 | private UserFragmentBinding binding; |
| 32 | - private User activeAccountInfo; | |
| 33 | + | |
| 34 | + private User user; | |
| 33 | 35 | |
| 34 | 36 | @Nullable |
| 35 | 37 | @Override |
| ... | ... | @@ -89,14 +91,16 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { |
| 89 | 91 | @Override |
| 90 | 92 | public void onResume() { |
| 91 | 93 | super.onResume(); |
| 92 | - notifyUI(UserService.getInstance(getActivity()).getActiveAccountInfo().getUid() != 0); | |
| 94 | + user = UserService.getInstance(getActivity()).getActiveAccountInfo(); | |
| 95 | + boolean isLogin = user != null && user.getUid() != 0; | |
| 96 | + notifyUI(isLogin); | |
| 97 | + if (!isLogin) return; | |
| 98 | + updateUserInfo(); | |
| 93 | 99 | } |
| 94 | 100 | |
| 95 | 101 | private void notifyUI(boolean isLogin) { |
| 96 | 102 | if(isLogin){ |
| 97 | - activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); | |
| 98 | - updateUserInfo(activeAccountInfo); | |
| 99 | - activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); | |
| 103 | + User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo(); | |
| 100 | 104 | Glide.with(getActivity()).load(activeAccountInfo.getFaceurl()).into(binding.headImg); |
| 101 | 105 | binding.tvNickname.setText(activeAccountInfo.getNickname()); |
| 102 | 106 | }else{ |
| ... | ... | @@ -105,9 +109,7 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { |
| 105 | 109 | } |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | - | |
| 109 | - | |
| 110 | - private void updateUserInfo(User user) { | |
| 112 | + private void updateUserInfo() { | |
| 111 | 113 | UserUtil.queryUserInfo(String.valueOf(user.getUid()), String.valueOf(user.getUid()), new Callback() { |
| 112 | 114 | @Override |
| 113 | 115 | public void onState(int i, String s, Object obj) { |
| ... | ... | @@ -115,6 +117,12 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { |
| 115 | 117 | UserData userData = (UserData) obj; |
| 116 | 118 | UserService userService = UserService.getInstance(getActivity()); |
| 117 | 119 | userService.setActiveAccountInfo(userData.getData()); |
| 120 | + notifyUI(true); | |
| 121 | + } else if (i == IUserService.ERROR_TOKEN_INVALID) { | |
| 122 | + ToastUtil.show(getActivity(), getString(R.string.user_token_invalid)); | |
| 123 | + UserService userService = UserService.getInstance(getActivity()); | |
| 124 | + userService.clearUser(); | |
| 125 | + notifyUI(false); | |
| 118 | 126 | } |
| 119 | 127 | } |
| 120 | 128 | }); | ... | ... |