Commit 34d2cead authored by fallenstardust's avatar fallenstardust

优化登录联动与注销

parent 8f273a63
......@@ -58,8 +58,8 @@ public class DeckSquareMyDeckFragment extends Fragment {
} else {
binding.llMainUi.setVisibility(View.VISIBLE);
binding.llDialogLogin.setVisibility(View.GONE);
McUser mcUser = new McUser();
GlideCompat.with(getActivity()).load(ChatMessage.getAvatarUrl(SharedPreferenceUtil.getUserName())).into(binding.myDeckAvatar);//刷新头像图片
binding.tvMycardUserName.setText(SharedPreferenceUtil.getMyCardUserName());
GlideCompat.with(getActivity()).load(ChatMessage.getAvatarUrl(SharedPreferenceUtil.getMyCardUserName())).into(binding.myDeckAvatar);//刷新头像图片
}
binding.btnLogin.setOnClickListener(v -> attemptLogin());
binding.btnRegister.setOnClickListener(v -> WebActivity.open(getContext(), getString(R.string.register), MyCard.URL_MC_SIGN_UP));
......@@ -70,7 +70,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
deckListAdapter.loadData();
//其实仅仅是清除掉本机的token
binding.mcLogoutBtn.setOnClickListener(new View.OnClickListener() {
binding.llMcLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferenceUtil.deleteServerToken();
......@@ -138,6 +138,7 @@ public class DeckSquareMyDeckFragment extends Fragment {
LoginResponse result = DeckSquareApiUtil.login(username, password);//执行登录
SharedPreferenceUtil.setServerToken(result.token);
SharedPreferenceUtil.setServerUserId(result.user.id);
SharedPreferenceUtil.setMyCardUserName(result.user.username);
return result;
}).fail((e) -> {
......@@ -152,13 +153,18 @@ public class DeckSquareMyDeckFragment extends Fragment {
binding.llDialogLogin.setVisibility(View.GONE);
binding.progressBar.setVisibility(View.GONE);
binding.btnLogin.setEnabled(true);
YGOUtil.showTextToast(R.string.login_succeed);
//储存信息
String userName = result.user.username;
binding.tvMycardUserName.setText(userName);
McUser mcUser = new McUser();
mcUser.setUsername(result.user.username);
mcUser.setUsername(userName);
mcUser.setExternal_id(result.user.id);
mcUser.setAvatar_url(ChatMessage.getAvatarUrl(result.user.username));
mcUser.setAvatar_url(ChatMessage.getAvatarUrl(userName));
mcUser.setToken(result.token);
GlideCompat.with(getActivity()).load(mcUser.getAvatar_url()).into(binding.myDeckAvatar);//刷新头像图片
UserManagement.getDx().setMcUser(mcUser);
YGOUtil.showTextToast(R.string.login_succeed);
} else {
YGOUtil.showTextToast(R.string.logining_failed);
binding.llMainUi.setVisibility(View.GONE);
......
......@@ -340,10 +340,11 @@ public class MyCard {
McUser mcUser = null;
if (TextUtils.isEmpty(exception)) {
mcUser = new Gson().fromJson(userInfo, McUser.class);
Log.i("seesee mcuser.token",mcUser.getToken());
UserManagement.getDx().setMcUser(mcUser);
UserManagement.getDx().setMcUser(mcUser);//登录后,mcUser信息存在此
//另外保存一份token和id信息作为其他登录验证场景调用
SharedPreferenceUtil.setServerToken(mcUser.getToken());
SharedPreferenceUtil.setServerUserId(mcUser.getExternal_id());
SharedPreferenceUtil.setMyCardUserName(mcUser.getUsername());
}
if (mListener!=null)
mListener.onLogin(mcUser,exception);
......
......@@ -61,7 +61,7 @@ public class McUser implements Serializable {
return token;
}
public void setName(String token) {
public void setToken(String token) {
this.token = token;
}
......
......@@ -144,6 +144,7 @@
tools:layout_editor_absoluteY="16dp" />
<LinearLayout
android:id="@+id/ll_mc_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
......@@ -158,13 +159,22 @@
android:layout_marginStart="5dp"
android:src="@drawable/avatar"/>
<Button
android:id="@+id/mc_logout_btn"
<TextView
android:id="@+id/tv_mycard_user_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@color/holo_green_bright"
android:text="mycardUserName"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginEnd="5dp"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="5dp"
android:background="@color/transparent"
android:text="注销" />
android:src="@drawable/baseline_login_24"
android:background="@color/transparent" />
</LinearLayout>
</LinearLayout>
......
......@@ -15,53 +15,50 @@
android:padding="10dp">
<LinearLayout
android:id="@+id/ll_head_login"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@+id/ll_head_login"
android:layout_gravity="right"
android:layout_weight="1"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=""
android:textColor="@color/holo_green_bright"
android:textSize="15sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_name"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:lines="1"
android:text=""
android:textColor="@color/holo_orange_bright"
android:textSize="10sp"
android:visibility="gone" />
</FrameLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img_head"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/dp_10"
android:src="@drawable/avatar" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text=""
android:textColor="@color/holo_green_bright"
android:textSize="15sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_name"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:lines="1"
android:text=""
android:textColor="@color/holo_orange_bright"
android:textSize="10sp"
android:visibility="gone" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img_logout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_guide_right" />
android:src="@drawable/baseline_login_24" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatButton
......@@ -102,8 +99,8 @@
android:id="@+id/rl_chat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="@drawable/list_item_bg"
android:orientation="vertical"
android:padding="10dp">
......@@ -121,19 +118,19 @@
android:id="@+id/pb_chat_loading"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:visibility="gone"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/tv_message_s" />
android:layout_toRightOf="@id/tv_message_s"
android:visibility="gone" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp_10"
android:layout_toRightOf="@id/pb_chat_loading"
android:layout_centerVertical="true"
android:ellipsize="end"
android:lines="1"
android:text="@string/login_mycard"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment