Skip to content

Commit 6b723b0

Browse files
committed
add clean cache method
1 parent db3c02b commit 6b723b0

File tree

5 files changed

+355
-15
lines changed

5 files changed

+355
-15
lines changed

app/src/main/java/com/code4a/jlibrarydemo/home/frag/mine/MineFragment.java

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package com.code4a.jlibrarydemo.home.frag.mine;
22

3+
import android.content.Context;
34
import android.os.Bundle;
5+
import android.text.TextUtils;
46
import android.view.View;
57
import android.widget.ImageView;
68
import android.widget.TextView;
79

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;
815
import com.code4a.jlibrary.utils.ToastUtil;
916
import com.code4a.jlibrarydemo.R;
1017
import com.code4a.jlibrarydemo.home.frag.HomeBaseFragment;
@@ -31,18 +38,21 @@ public class MineFragment extends HomeBaseFragment implements View.OnClickListen
3138

3239
TextView feedBackTv;
3340
TextView userTv;
34-
TextView cacheTv;
41+
@BindView(R.id.cache_size_tv)
42+
TextView cacheSizeTv;
3543
TextView aboutTv;
3644
ImageView feedBackIv;
3745
ImageView userIv;
38-
ImageView cacheIv;
3946
ImageView aboutIv;
47+
@BindView(R.id.gear_loadingview)
48+
LoadingView mLoadingView;
4049

4150
@Override
4251
protected void initView(View view, Bundle savedInstanceState) {
4352
setTitle(R.string.mine);
4453

4554
initViewData();
55+
getCacheSize();
4656
}
4757

4858
private void initViewData() {
@@ -55,17 +65,13 @@ private void initViewData() {
5565
feedBackTv.setText(R.string.feedback);
5666
userTv = $(user, R.id.feedback_tv);
5767
userTv.setText(R.string.user);
58-
cacheTv = $(cache, R.id.feedback_tv);
59-
cacheTv.setText(R.string.cache);
6068
aboutTv = $(about, R.id.feedback_tv);
6169
aboutTv.setText(R.string.about_us);
6270

6371
feedBackIv = $(feedBack, R.id.feedback_icon);
6472
feedBackIv.setImageResource(R.mipmap.mine_feedback);
6573
userIv = $(user, R.id.feedback_icon);
6674
userIv.setImageResource(R.mipmap.mine_user);
67-
cacheIv = $(cache, R.id.feedback_icon);
68-
cacheIv.setImageResource(R.mipmap.mine_cache);
6975
aboutIv = $(about, R.id.feedback_icon);
7076
aboutIv.setImageResource(R.mipmap.mine_about);
7177
}
@@ -77,6 +83,75 @@ protected int getLayoutId() {
7783

7884
@Override
7985
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);
81156
}
82157
}

app/src/main/res/layout/fragment_mine.xml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
android:layout_marginBottom="2dp"
3434
android:layout_marginTop="58dp"
3535
android:gravity="center"
36-
android:text="9ADDFDFF-E8XA"
36+
android:text="code4a"
3737
android:textColor="@color/light_black"
3838
android:textSize="16sp" />
3939

@@ -54,9 +54,60 @@
5454
android:id="@+id/user"
5555
layout="@layout/fragment_mine_middle" />
5656

57-
<include
57+
<!-- <include
5858
android:id="@+id/cache"
59-
layout="@layout/fragment_mine_middle" />
59+
layout="@layout/fragment_mine_middle" />-->
60+
61+
<RelativeLayout
62+
android:id="@+id/cache"
63+
android:layout_width="match_parent"
64+
android:layout_height="56dp"
65+
android:background="@drawable/selector_mine_item"
66+
android:orientation="horizontal"
67+
android:padding="3dp">
68+
69+
<ImageView
70+
android:id="@+id/cache_icon"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:layout_alignParentLeft="true"
74+
android:layout_centerVertical="true"
75+
android:layout_marginLeft="6dp"
76+
android:src="@mipmap/mine_cache" />
77+
78+
<TextView
79+
android:id="@+id/cache_tv"
80+
android:layout_width="wrap_content"
81+
android:layout_height="wrap_content"
82+
android:layout_centerVertical="true"
83+
android:layout_marginLeft="6dp"
84+
android:layout_toRightOf="@id/cache_icon"
85+
android:text="@string/cache"
86+
android:textColor="@color/light_black"
87+
android:textSize="16sp" />
88+
89+
<TextView
90+
android:id="@+id/cache_size_tv"
91+
android:layout_width="wrap_content"
92+
android:layout_height="wrap_content"
93+
android:layout_alignParentRight="true"
94+
android:layout_centerVertical="true"
95+
android:layout_marginRight="25dp"
96+
android:text="0MB"
97+
android:textColor="@color/light_black"
98+
android:textSize="18sp"/>
99+
100+
<com.code4a.jlibrary.loading.LoadingView
101+
android:id="@+id/gear_loadingview"
102+
android:layout_width="50dp"
103+
android:layout_height="50dp"
104+
android:layout_centerVertical="true"
105+
android:layout_alignParentRight="true"
106+
android:layout_marginRight="25dp"
107+
android:background="@color/transparent"
108+
app:loading_renderer="GearLoadingRenderer"/>
109+
110+
</RelativeLayout>
60111

61112
<include
62113
android:id="@+id/about"

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<color name="main_color">#5CB85C</color>
1616
<color name="transparent">#00000000</color>
1717

18+
<color name="light_gray">#cccaca</color>
1819
<color name="swipe_background_color">#ffffff</color>
1920
<color name="video_thumbnail_placeholder_color">#cccccc</color>
2021
</resources>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
<string name="hot">热播</string>
77
<string name="catagory">精品</string>
88
<string name="mine">我的</string>
9-
<string name="feedback">意见投诉</string>
9+
<string name="feedback">意见反馈</string>
1010
<string name="cache">清除缓存</string>
11-
<string name="about_us">关于我们</string>
12-
<string name="user">用户协议</string>
11+
<string name="about_us">关于我</string>
12+
<string name="user">打赏我</string>
1313
<string name="hot_groom">热播推荐</string>
1414

15-
<color name="light_gray">#cccaca</color>
16-
1715
<string name="user_name">username</string>
1816
<string name="password">password</string>
1917
<string name="log_in">Log in</string>

0 commit comments

Comments
 (0)