1
1
package com .code4a .jlibrarydemo .home .frag .mine ;
2
2
3
+ import android .content .Context ;
3
4
import android .os .Bundle ;
5
+ import android .text .TextUtils ;
4
6
import android .view .View ;
5
7
import android .widget .ImageView ;
6
8
import android .widget .TextView ;
7
9
10
+ import com .code4a .jlibrary .loading .LoadingView ;
11
+ import com .code4a .jlibrary .tasks .BackgroundWork ;
12
+ import com .code4a .jlibrary .tasks .Completion ;
13
+ import com .code4a .jlibrary .tasks .Tasks ;
14
+ import com .code4a .jlibrary .utils .DataCleanUtil ;
8
15
import com .code4a .jlibrary .utils .ToastUtil ;
9
16
import com .code4a .jlibrarydemo .R ;
10
17
import com .code4a .jlibrarydemo .home .frag .HomeBaseFragment ;
@@ -31,18 +38,21 @@ public class MineFragment extends HomeBaseFragment implements View.OnClickListen
31
38
32
39
TextView feedBackTv ;
33
40
TextView userTv ;
34
- TextView cacheTv ;
41
+ @ BindView (R .id .cache_size_tv )
42
+ TextView cacheSizeTv ;
35
43
TextView aboutTv ;
36
44
ImageView feedBackIv ;
37
45
ImageView userIv ;
38
- ImageView cacheIv ;
39
46
ImageView aboutIv ;
47
+ @ BindView (R .id .gear_loadingview )
48
+ LoadingView mLoadingView ;
40
49
41
50
@ Override
42
51
protected void initView (View view , Bundle savedInstanceState ) {
43
52
setTitle (R .string .mine );
44
53
45
54
initViewData ();
55
+ getCacheSize ();
46
56
}
47
57
48
58
private void initViewData () {
@@ -55,17 +65,13 @@ private void initViewData() {
55
65
feedBackTv .setText (R .string .feedback );
56
66
userTv = $ (user , R .id .feedback_tv );
57
67
userTv .setText (R .string .user );
58
- cacheTv = $ (cache , R .id .feedback_tv );
59
- cacheTv .setText (R .string .cache );
60
68
aboutTv = $ (about , R .id .feedback_tv );
61
69
aboutTv .setText (R .string .about_us );
62
70
63
71
feedBackIv = $ (feedBack , R .id .feedback_icon );
64
72
feedBackIv .setImageResource (R .mipmap .mine_feedback );
65
73
userIv = $ (user , R .id .feedback_icon );
66
74
userIv .setImageResource (R .mipmap .mine_user );
67
- cacheIv = $ (cache , R .id .feedback_icon );
68
- cacheIv .setImageResource (R .mipmap .mine_cache );
69
75
aboutIv = $ (about , R .id .feedback_icon );
70
76
aboutIv .setImageResource (R .mipmap .mine_about );
71
77
}
@@ -77,6 +83,75 @@ protected int getLayoutId() {
77
83
78
84
@ Override
79
85
public void onClick (View v ) {
80
- ToastUtil .showShort (getHoldingActivity (), "用户点击了" );
86
+ switch (v .getId ()) {
87
+ case R .id .feedback :
88
+ break ;
89
+ case R .id .user :
90
+ break ;
91
+ case R .id .cache :
92
+ cleanCache ();
93
+ break ;
94
+ case R .id .about :
95
+ break ;
96
+ }
97
+ // ToastUtil.showShort(getHoldingActivity(), "用户点击了");
98
+ }
99
+
100
+ private void getCacheSize (){
101
+ showLoadingView ();
102
+ Tasks .executeInBackground (getHoldingActivity (), new BackgroundWork <String >() {
103
+ @ Override
104
+ public String doInBackground () throws Exception {
105
+ return DataCleanUtil .getCacheSize (getHoldingActivity ());
106
+ }
107
+ }, new Completion <String >() {
108
+ @ Override
109
+ public void onSuccess (Context context , String result ) {
110
+ if (!TextUtils .isEmpty (result )){
111
+ cacheSizeTv .setText (result );
112
+ hideLoadingView ();
113
+ }
114
+ }
115
+
116
+ @ Override
117
+ public void onError (Context context , Exception e ) {
118
+ cacheSizeTv .setText ("0MB" );
119
+ hideLoadingView ();
120
+ }
121
+ });
122
+ }
123
+
124
+ private void cleanCache () {
125
+ showLoadingView ();
126
+ Tasks .executeInBackground (getHoldingActivity (), new BackgroundWork <String >() {
127
+ @ Override
128
+ public String doInBackground () throws Exception {
129
+ DataCleanUtil .cleanApplicationData (getHoldingActivity ());
130
+ return null ;
131
+ }
132
+ }, new Completion <String >() {
133
+ @ Override
134
+ public void onSuccess (Context context , String result ) {
135
+ ToastUtil .showShort (getHoldingActivity (), "数据清除完成!" );
136
+ cacheSizeTv .setText ("0MB" );
137
+ hideLoadingView ();
138
+ }
139
+
140
+ @ Override
141
+ public void onError (Context context , Exception e ) {
142
+ cacheSizeTv .setText ("0MB" );
143
+ hideLoadingView ();
144
+ }
145
+ });
146
+ }
147
+
148
+ public void showLoadingView () {
149
+ mLoadingView .setVisibility (View .VISIBLE );
150
+ cacheSizeTv .setVisibility (View .GONE );
151
+ }
152
+
153
+ public void hideLoadingView () {
154
+ mLoadingView .setVisibility (View .GONE );
155
+ cacheSizeTv .setVisibility (View .VISIBLE );
81
156
}
82
157
}
0 commit comments