Skip to content

Commit

Permalink
首页增加了刷新选项
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhoujay committed Sep 30, 2015
1 parent 8c23d35 commit 39176a3
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 4 deletions.
Binary file modified apk/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/groovy/zhou/gank/io/App.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class App extends Application {
}
VectorDrawableCompat.enableResourceInterceptionFor(getResources(),
R.drawable.ic_favorite_white_48px,
R.drawable.ic_info_48px,
R.drawable.ic_info_48px,R.drawable.ic_refresh_48px,
R.drawable.ic_dashboard_48px, R.drawable.ic_event_48px,
R.drawable.ic_extension_48px, R.drawable.ic_settings_black_48px,
R.drawable.ic_menu_white_48px, R.drawable.ic_view_module_48px,
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/groovy/zhou/gank/io/data/TimeProvider.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,32 @@ class TimeProvider implements DataProvider<GankDaily> {
private String key
private File file
private boolean noticeable
private boolean needCache

TimeProvider(int year, int month, int day) {
this.year = year
this.month = month
this.day = day
key = HashKit.md5("year:$year,month:$month,day:$day-cache")
file = new File(App.cacheFile(), key)

Calendar now = Calendar.getInstance()
int y = now.get(Calendar.YEAR)
if (year < y) {
needCache = true
} else if (year == y) {
int m = now.get(Calendar.MONTH) + 1
if (month < m) {
needCache = true
} else if (month == m) {
int d = now.get(Calendar.DAY_OF_MONTH)
needCache = day <= d
} else {
needCache = false
}
} else {
needCache = false
}
}

@Override
Expand Down Expand Up @@ -103,7 +122,7 @@ class TimeProvider implements DataProvider<GankDaily> {

@Override
public boolean needCache() {
return true
return needCache
}

@Override
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/groovy/zhou/gank/io/ui/fragment/DailyFragment.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -42,6 +44,7 @@ class DailyFragment extends BaseFragment {
boolean isMain = false
int year, month, day
int count
MenuItem refresh


@Override
Expand Down Expand Up @@ -107,6 +110,7 @@ class DailyFragment extends BaseFragment {


protected void setUpData(GankDaily daily) {
refresh?.setVisible(true)
if (daily != null) {
if (daily.isEmpty()) {
if (isMain) {
Expand Down Expand Up @@ -169,9 +173,9 @@ class DailyFragment extends BaseFragment {
setSuccess()
}
} else {
if(daily){
if (daily) {
println("not null")
}else {
} else {
println("is null")
}
// Error
Expand All @@ -180,6 +184,13 @@ class DailyFragment extends BaseFragment {
}
}

@Override
void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_daily, menu)
refresh = menu.findItem(R.id.menu_refresh)
}

@Override
boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
Expand All @@ -190,6 +201,9 @@ class DailyFragment extends BaseFragment {
noticeActivity(Config.Action.FINISH)
}
return true;
case R.id.menu_refresh:
requestDaily()
return true
}
return super.onOptionsItemSelected(item);
}
Expand All @@ -202,6 +216,7 @@ class DailyFragment extends BaseFragment {
def requestDaily() {
setTitle(getString(R.string.loading))
setLoading()
refresh?.setVisible(false)
DataManager.getInstance().get(provider, this.&setUpData)
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_refresh_48px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:ignore="NewApi"
android:viewportWidth="48"
better:viewportWidth="48"
android:viewportHeight="48"
better:viewportHeight="48"
android:width="48dp"
android:height="48dp">
<path
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"
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"
android:fillColor="#ffffff"
better:fillColor="#ffffff" />
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/menu/menu_daily.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_refresh"
android:icon="@drawable/ic_refresh_48px"
android:showAsAction="collapseActionView|ifRoom"
android:title="@string/text_refresh" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
<string name="success_delete">Deleted successfully</string>
<string name="success_uncollect">Cancel the collection success</string>
<string name="text_loading_failure">Failure load, click reload</string>
<string name="text_refresh">Refresh</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="loading">加载中。。。</string>
<string name="no_data">没有数据!</string>
<string name="error">出错了!</string>
<string name="text_refresh">刷新</string>

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

0 comments on commit 39176a3

Please sign in to comment.