11package com .hjq .demo .ui .activity ;
22
3+ import android .graphics .drawable .Drawable ;
34import android .view .Gravity ;
45import android .view .View ;
56import androidx .annotation .NonNull ;
3637public final class SettingActivity extends AppActivity
3738 implements SwitchButton .OnCheckedChangeListener {
3839
39- private SettingBar mLanguageView ;
40- private SettingBar mPhoneView ;
41- private SettingBar mPasswordView ;
40+ private SettingBar mChangeLanguageView ;
41+ private SettingBar mCheckUpdateView ;
42+ private SettingBar mModifyPhoneView ;
43+ private SettingBar mModifyPasswordView ;
44+ private SettingBar mReadAgreementView ;
45+ private SettingBar mAboutAppView ;
46+ private SettingBar mAutoLoginView ;
4247 private SettingBar mCleanCacheView ;
48+ private SettingBar mExitLoginView ;
49+
4350 private SwitchButton mAutoSwitchView ;
4451
4552 @ Override
@@ -49,28 +56,48 @@ protected int getLayoutId() {
4956
5057 @ Override
5158 protected void initView () {
52- mLanguageView = findViewById (R .id .sb_setting_language );
53- mPhoneView = findViewById (R .id .sb_setting_phone );
54- mPasswordView = findViewById (R .id .sb_setting_password );
55- mCleanCacheView = findViewById (R .id .sb_setting_cache );
59+ mChangeLanguageView = findViewById (R .id .sb_setting_change_language );
60+ mCheckUpdateView = findViewById (R .id .sb_setting_check_update );
61+ mModifyPhoneView = findViewById (R .id .sb_setting_modify_phone );
62+ mModifyPasswordView = findViewById (R .id .sb_setting_modify_password );
63+ mReadAgreementView = findViewById (R .id .sb_setting_read_agreement );
64+ mAboutAppView = findViewById (R .id .sb_setting_about_app );
65+ mAutoLoginView = findViewById (R .id .sb_setting_auto_login );
66+ mCleanCacheView = findViewById (R .id .sb_setting_clear_cache );
67+ mExitLoginView = findViewById (R .id .sb_setting_exit_login );
68+
5669 mAutoSwitchView = findViewById (R .id .sb_setting_switch );
5770
71+ // 适配 RTL 特性
72+ Drawable iconDrawable ;
73+ if (getResources ().getConfiguration ().getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ) {
74+ iconDrawable = getDrawable (R .drawable .arrows_left_ic );
75+ } else {
76+ iconDrawable = getDrawable (R .drawable .arrows_right_ic );
77+ }
78+ mChangeLanguageView .setEndDrawable (iconDrawable );
79+ mModifyPhoneView .setEndDrawable (iconDrawable );
80+ mModifyPasswordView .setEndDrawable (iconDrawable );
81+ mReadAgreementView .setEndDrawable (iconDrawable );
82+ mAboutAppView .setEndDrawable (iconDrawable );
83+ mAutoLoginView .setEndDrawable (iconDrawable );
84+ mCleanCacheView .setEndDrawable (iconDrawable );
85+ mExitLoginView .setEndDrawable (iconDrawable );
86+
5887 // 设置切换按钮的监听
5988 mAutoSwitchView .setOnCheckedChangeListener (this );
6089
61- setOnClickListener (R .id .sb_setting_language , R .id .sb_setting_update , R .id .sb_setting_phone ,
62- R .id .sb_setting_password , R .id .sb_setting_agreement , R .id .sb_setting_about ,
63- R .id .sb_setting_cache , R .id .sb_setting_auto , R .id .sb_setting_exit );
90+ setOnClickListener (mChangeLanguageView , mCheckUpdateView , mModifyPhoneView , mModifyPasswordView ,
91+ mReadAgreementView , mAboutAppView , mAutoLoginView , mCleanCacheView , mExitLoginView );
6492 }
6593
6694 @ Override
6795 protected void initData () {
6896 // 获取应用缓存大小
69- mCleanCacheView .setRightText (CacheDataManager .getTotalCacheSize (this ));
70-
71- mLanguageView .setRightText ("简体中文" );
72- mPhoneView .setRightText ("181****1413" );
73- mPasswordView .setRightText ("密码强度较低" );
97+ mCleanCacheView .setEndText (CacheDataManager .getTotalCacheSize (this ));
98+ mChangeLanguageView .setEndText ("简体中文" );
99+ mModifyPhoneView .setEndText ("181****1413" );
100+ mModifyPasswordView .setEndText ("密码强度较低" );
74101 }
75102
76103 @ Nullable
@@ -82,23 +109,22 @@ public View getImmersionBottomView() {
82109 @ SingleClick
83110 @ Override
84111 public void onClick (@ NonNull View view ) {
85- int viewId = view .getId ();
86- if (viewId == R .id .sb_setting_language ) {
112+ if (view == mChangeLanguageView ) {
87113
88114 // 底部选择框
89115 new MenuDialog .Builder (this )
90116 // 设置点击按钮后不关闭对话框
91117 //.setAutoDismiss(false)
92118 .setList (R .string .setting_language_simple , R .string .setting_language_complex )
93119 .setListener ((MenuDialog .OnListener <String >) (dialog , position , string ) -> {
94- mLanguageView . setRightText (string );
120+ mChangeLanguageView . setEndText (string );
95121 BrowserActivity .start (SettingActivity .this , "https://github.com/getActivity/MultiLanguages" );
96122 })
97123 .setGravity (Gravity .BOTTOM )
98124 .setAnimStyle (BaseDialog .ANIM_BOTTOM )
99125 .show ();
100126
101- } else if (viewId == R . id . sb_setting_update ) {
127+ } else if (view == mCheckUpdateView ) {
102128
103129 // 本地的版本码和服务器的进行比较
104130 if (20 > AppConfig .getVersionCode ()) {
@@ -113,32 +139,32 @@ public void onClick(@NonNull View view) {
113139 toast (R .string .update_no_update );
114140 }
115141
116- } else if (viewId == R . id . sb_setting_phone ) {
142+ } else if (view == mModifyPhoneView ) {
117143
118144 new SafeDialog .Builder (this )
119145 .setListener ((dialog , phone , code ) -> PhoneResetActivity .start (this , code ))
120146 .show ();
121147
122- } else if (viewId == R . id . sb_setting_password ) {
148+ } else if (view == mModifyPasswordView ) {
123149
124150 new SafeDialog .Builder (this )
125151 .setListener ((dialog , phone , code ) -> PasswordResetActivity .start (this , phone , code ))
126152 .show ();
127153
128- } else if (viewId == R . id . sb_setting_agreement ) {
154+ } else if (view == mReadAgreementView ) {
129155
130156 BrowserActivity .start (this , "https://github.com/getActivity/Donate" );
131157
132- } else if (viewId == R . id . sb_setting_about ) {
158+ } else if (view == mAboutAppView ) {
133159
134160 startActivity (AboutActivity .class );
135161
136- } else if (viewId == R . id . sb_setting_auto ) {
162+ } else if (view == mAutoLoginView ) {
137163
138164 // 自动登录
139165 mAutoSwitchView .setChecked (!mAutoSwitchView .isChecked ());
140166
141- } else if (viewId == R . id . sb_setting_cache ) {
167+ } else if (view == mCleanCacheView ) {
142168
143169 // 清除内存缓存(必须在主线程)
144170 GlideApp .get (this ).clearMemory ();
@@ -148,11 +174,11 @@ public void onClick(@NonNull View view) {
148174 GlideApp .get (SettingActivity .this ).clearDiskCache ();
149175 post (() -> {
150176 // 重新获取应用缓存大小
151- mCleanCacheView .setRightText (CacheDataManager .getTotalCacheSize (SettingActivity .this ));
177+ mCleanCacheView .setEndText (CacheDataManager .getTotalCacheSize (SettingActivity .this ));
152178 });
153179 });
154180
155- } else if (viewId == R . id . sb_setting_exit ) {
181+ } else if (view == mExitLoginView ) {
156182
157183 if (true ) {
158184 startActivity (LoginActivity .class );
0 commit comments