Skip to content

Commit 39176a3

Browse files
committed
首页增加了刷新选项
1 parent 8c23d35 commit 39176a3

File tree

8 files changed

+63
-4
lines changed

8 files changed

+63
-4
lines changed

apk/app-release.apk

2.76 KB
Binary file not shown.

app/src/main/groovy/zhou/gank/io/App.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class App extends Application {
7474
}
7575
VectorDrawableCompat.enableResourceInterceptionFor(getResources(),
7676
R.drawable.ic_favorite_white_48px,
77-
R.drawable.ic_info_48px,
77+
R.drawable.ic_info_48px,R.drawable.ic_refresh_48px,
7878
R.drawable.ic_dashboard_48px, R.drawable.ic_event_48px,
7979
R.drawable.ic_extension_48px, R.drawable.ic_settings_black_48px,
8080
R.drawable.ic_menu_white_48px, R.drawable.ic_view_module_48px,

app/src/main/groovy/zhou/gank/io/data/TimeProvider.groovy

+20-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,32 @@ class TimeProvider implements DataProvider<GankDaily> {
2121
private String key
2222
private File file
2323
private boolean noticeable
24+
private boolean needCache
2425

2526
TimeProvider(int year, int month, int day) {
2627
this.year = year
2728
this.month = month
2829
this.day = day
2930
key = HashKit.md5("year:$year,month:$month,day:$day-cache")
3031
file = new File(App.cacheFile(), key)
32+
33+
Calendar now = Calendar.getInstance()
34+
int y = now.get(Calendar.YEAR)
35+
if (year < y) {
36+
needCache = true
37+
} else if (year == y) {
38+
int m = now.get(Calendar.MONTH) + 1
39+
if (month < m) {
40+
needCache = true
41+
} else if (month == m) {
42+
int d = now.get(Calendar.DAY_OF_MONTH)
43+
needCache = day <= d
44+
} else {
45+
needCache = false
46+
}
47+
} else {
48+
needCache = false
49+
}
3150
}
3251

3352
@Override
@@ -103,7 +122,7 @@ class TimeProvider implements DataProvider<GankDaily> {
103122

104123
@Override
105124
public boolean needCache() {
106-
return true
125+
return needCache
107126
}
108127

109128
@Override

app/src/main/groovy/zhou/gank/io/ui/fragment/DailyFragment.groovy

+17-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import android.support.v7.widget.LinearLayoutManager
1313
import android.support.v7.widget.RecyclerView
1414
import android.support.v7.widget.Toolbar
1515
import android.view.LayoutInflater
16+
import android.view.Menu
17+
import android.view.MenuInflater
1618
import android.view.MenuItem
1719
import android.view.View
1820
import android.view.ViewGroup
@@ -42,6 +44,7 @@ class DailyFragment extends BaseFragment {
4244
boolean isMain = false
4345
int year, month, day
4446
int count
47+
MenuItem refresh
4548

4649

4750
@Override
@@ -107,6 +110,7 @@ class DailyFragment extends BaseFragment {
107110

108111

109112
protected void setUpData(GankDaily daily) {
113+
refresh?.setVisible(true)
110114
if (daily != null) {
111115
if (daily.isEmpty()) {
112116
if (isMain) {
@@ -169,9 +173,9 @@ class DailyFragment extends BaseFragment {
169173
setSuccess()
170174
}
171175
} else {
172-
if(daily){
176+
if (daily) {
173177
println("not null")
174-
}else {
178+
} else {
175179
println("is null")
176180
}
177181
// Error
@@ -180,6 +184,13 @@ class DailyFragment extends BaseFragment {
180184
}
181185
}
182186

187+
@Override
188+
void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
189+
super.onCreateOptionsMenu(menu, inflater)
190+
inflater.inflate(R.menu.menu_daily, menu)
191+
refresh = menu.findItem(R.id.menu_refresh)
192+
}
193+
183194
@Override
184195
boolean onOptionsItemSelected(MenuItem item) {
185196
switch (item.getItemId()) {
@@ -190,6 +201,9 @@ class DailyFragment extends BaseFragment {
190201
noticeActivity(Config.Action.FINISH)
191202
}
192203
return true;
204+
case R.id.menu_refresh:
205+
requestDaily()
206+
return true
193207
}
194208
return super.onOptionsItemSelected(item);
195209
}
@@ -202,6 +216,7 @@ class DailyFragment extends BaseFragment {
202216
def requestDaily() {
203217
setTitle(getString(R.string.loading))
204218
setLoading()
219+
refresh?.setVisible(false)
205220
DataManager.getInstance().get(provider, this.&setUpData)
206221
}
207222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:better="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
3+
tools:ignore="NewApi"
4+
android:viewportWidth="48"
5+
better:viewportWidth="48"
6+
android:viewportHeight="48"
7+
better:viewportHeight="48"
8+
android:width="48dp"
9+
android:height="48dp">
10+
<path
11+
android:pathData="M35.3 12.7C32.41 9.8 28.42 8 24 8 15.16 8 8.02 15.16 8.02 24c0 8.84 7.14 16 15.98 16 7.45 0 13.69 -5.1 15.46 -12l-4.16 0c-1.65 4.66 -6.07 8 -11.3 8 -6.63 0 -12 -5.37 -12 -12 0 -6.63 5.37 -12 12 -12 3.31 0 6.28 1.38 8.45 3.55L26 22 40 22 40 8 35.3 12.7Z"
12+
better:pathData="M35.3 12.7C32.41 9.8 28.42 8 24 8 15.16 8 8.02 15.16 8.02 24c0 8.84 7.14 16 15.98 16 7.45 0 13.69 -5.1 15.46 -12l-4.16 0c-1.65 4.66 -6.07 8 -11.3 8 -6.63 0 -12 -5.37 -12 -12 0 -6.63 5.37 -12 12 -12 3.31 0 6.28 1.38 8.45 3.55L26 22 40 22 40 8 35.3 12.7Z"
13+
android:fillColor="#ffffff"
14+
better:fillColor="#ffffff" />
15+
</vector>

app/src/main/res/menu/menu_daily.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:id="@+id/menu_refresh"
5+
android:icon="@drawable/ic_refresh_48px"
6+
android:showAsAction="collapseActionView|ifRoom"
7+
android:title="@string/text_refresh" />
8+
</menu>

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

+1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@
4949
<string name="success_delete">Deleted successfully</string>
5050
<string name="success_uncollect">Cancel the collection success</string>
5151
<string name="text_loading_failure">Failure load, click reload</string>
52+
<string name="text_refresh">Refresh</string>
5253
</resources>

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<string name="loading">加载中。。。</string>
55
<string name="no_data">没有数据!</string>
66
<string name="error">出错了!</string>
7+
<string name="text_refresh">刷新</string>
78

89
<string name="text_no_data" translatable="false">今天没有干货哦</string>
910
<string name="text_error" translatable="false">加载干货失败。。。点击重新加载</string>

0 commit comments

Comments
 (0)