44
55import android .content .Intent ;
66import android .os .Bundle ;
7+ import android .view .Gravity ;
8+ import android .view .View ;
9+ import android .view .ViewGroup ;
710import android .widget .Button ;
11+ import android .widget .LinearLayout ;
12+ import android .widget .Space ;
813import android .widget .TextView ;
914
15+ import java .util .HashMap ;
16+ import java .util .List ;
17+ import java .util .Map ;
18+
1019import cn .authing .guard .Authing ;
20+ import cn .authing .guard .activity .UpdateCustomDataActivity ;
1121import cn .authing .guard .data .UserInfo ;
1222import cn .authing .guard .util .Util ;
1323
1424public class MainActivity extends AppCompatActivity {
1525
26+ private TextView tvNickName ;
27+ private TextView tvName ;
28+ private TextView tvUserName ;
29+ private TextView tvPhone ;
30+ private TextView tvEmail ;
31+
32+ private Map <String , TextView > customDataViews = new HashMap <>();
33+
1634 @ Override
1735 protected void onCreate (Bundle savedInstanceState ) {
1836 super .onCreate (savedInstanceState );
1937 setContentView (R .layout .activity_main );
2038
21- UserInfo userInfo = (UserInfo ) getIntent ().getSerializableExtra ("user" );
22- TextView tv = findViewById (R .id .tv_nick_name );
23- setText (tv , userInfo .getNickname ());
24-
25- tv = findViewById (R .id .tv_name );
26- setText (tv , userInfo .getName ());
27-
28- tv = findViewById (R .id .tv_username );
29- setText (tv , userInfo .getUsername ());
30-
31- tv = findViewById (R .id .tv_phone );
32- setText (tv , userInfo .getPhone_number ());
33-
34- tv = findViewById (R .id .tv_email );
35- setText (tv , userInfo .getEmail ());
36-
39+ tvNickName = findViewById (R .id .tv_nick_name );
40+ tvName = findViewById (R .id .tv_name );
41+ tvUserName = findViewById (R .id .tv_username );
42+ tvPhone = findViewById (R .id .tv_phone );
43+ tvEmail = findViewById (R .id .tv_email );
3744
3845 TextView tvChangePassword = findViewById (R .id .tv_change_password );
3946 tvChangePassword .setOnClickListener ((v )->{
@@ -42,17 +49,82 @@ protected void onCreate(Bundle savedInstanceState) {
4249 finish ();
4350 });
4451
52+ UserInfo userInfo = Authing .getCurrentUser ();
53+ if (userInfo == null ) {
54+ return ;
55+ }
56+ LinearLayout customData = findViewById (R .id .ll_custom_data );
57+ setupCustomDataUI (customData , userInfo );
58+
4559 Button btn = findViewById (R .id .btn_logout );
4660 btn .setOnClickListener (v -> logout ());
4761 }
4862
63+ @ Override
64+ protected void onResume () {
65+ super .onResume ();
66+ UserInfo userInfo = Authing .getCurrentUser ();
67+ if (userInfo == null ) {
68+ return ;
69+ }
70+
71+ setText (tvNickName , userInfo .getNickname ());
72+ setText (tvName , userInfo .getName ());
73+ setText (tvUserName , userInfo .getUsername ());
74+ setText (tvPhone , userInfo .getPhone_number ());
75+ setText (tvEmail , userInfo .getEmail ());
76+
77+ for (UserInfo .CustomData data : userInfo .getCustomData ()) {
78+ TextView tv = customDataViews .get (data .getKey ());
79+ tv .setText (data .getValue ());
80+ }
81+ }
82+
83+ private void setupCustomDataUI (LinearLayout container , UserInfo user ) {
84+ int padding = (int )getResources ().getDimension (R .dimen .authing_form_start_end_margin );
85+ for (UserInfo .CustomData data : user .getCustomData ()) {
86+ LinearLayout layout = new LinearLayout (this );
87+ layout .setOrientation (LinearLayout .HORIZONTAL );
88+ LinearLayout .LayoutParams lp = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , (int )Util .dp2px (this , 48 ));
89+ layout .setLayoutParams (lp );
90+ layout .setPadding (padding , 0 , padding , 0 );
91+ layout .setGravity (Gravity .CENTER_VERTICAL );
92+ container .addView (layout );
93+
94+ TextView tvLabel = new TextView (this );
95+ tvLabel .setText (data .getLabel ());
96+ tvLabel .setTextSize (16 );
97+ layout .addView (tvLabel );
98+
99+ Space space = new Space (this );
100+ LinearLayout .LayoutParams lpSpace = new LinearLayout .LayoutParams (0 , ViewGroup .LayoutParams .WRAP_CONTENT , 1 );
101+ space .setLayoutParams (lpSpace );
102+ layout .addView (space );
103+
104+ TextView tvValue = new TextView (this );
105+ tvValue .setTextSize (16 );
106+ layout .addView (tvValue );
107+ customDataViews .put (data .getKey (), tvValue );
108+
109+ View sep = new View (this );
110+ LinearLayout .LayoutParams lpSep = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , 1 );
111+ int m = (int )getResources ().getDimension (R .dimen .authing_form_start_end_margin );
112+ lpSep .setMargins (m , 0 , 0 , 0 );
113+ sep .setBackgroundColor (0xffdddddd );
114+ sep .setLayoutParams (lpSep );
115+ container .addView (sep );
116+
117+ layout .setOnClickListener ((v -> {
118+ goUpdateUserData (data );
119+ }));
120+ }
121+ }
122+
49123 private void logout () {
50- Authing .logout ((ok , data )->{
51- if (ok ) {
52- Intent intent = new Intent (this , SampleListActivity .class );
53- startActivity (intent );
54- finish ();
55- }
124+ Authing .logout ((code , message , data )->{
125+ Intent intent = new Intent (this , SampleListActivity .class );
126+ startActivity (intent );
127+ finish ();
56128 });
57129 }
58130
@@ -63,4 +135,10 @@ private void setText(TextView tv, String s) {
63135 tv .setText (s );
64136 }
65137 }
138+
139+ private void goUpdateUserData (UserInfo .CustomData data ) {
140+ Intent intent = new Intent (this , UpdateCustomDataActivity .class );
141+ intent .putExtra ("data" , data );
142+ startActivity (intent );
143+ }
66144}
0 commit comments