Skip to content

Commit

Permalink
add onResume method
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthonyeef committed Nov 14, 2015
1 parent c940ee2 commit 52ff847
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" scope="TEST" name="multidex-instrumentation-1.0.1" level="project" />
<orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="library-1.0.18" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="picasso-2.4.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="sdk-1.3.4" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "0.9.1"
versionName "0.9.2"

manifestPlaceholders = [UMENG_CHANNEL_VALUE: "GitHub"]
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.umeng.analytics.MobclickAgent;

import im.fir.sdk.FIR;
Expand All @@ -20,7 +16,7 @@ public class MyApplication extends Application {
public static final String TAG = Application.class.getSimpleName();

private static MyApplication mInstance;
private RequestQueue mRequestQueue;
/* private RequestQueue mRequestQueue;*/
private static Date mDate;

@Override
Expand All @@ -38,15 +34,15 @@ public static synchronized MyApplication getInstance() {
public static Context getAppContext() {
return mInstance.getApplicationContext();
}

/*
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
}*/

public <T> void addToRequestQueue(Request<T> request, String tag) {
/* public <T> void addToRequestQueue(Request<T> request, String tag) {
request.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(request);
}
Expand All @@ -60,7 +56,7 @@ public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}*/

public static void setDate(Date date) {
mDate = date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
public class FanfouUtils {
public static ArrayList<Fanfou> loadFanfouDailyFeeds(RequestQueue requestQueue, String date) {
JSONObject response = Requestor.requestJSON(requestQueue, UrlUtils.getRequestUrlHead() + date + UrlUtils.getRequestUrlDailyEnd());
// Log.v("Getting response from", UrlUtils.getRequestUrlFanfouDaily());
// Log.v("Loading", response.toString());
ArrayList<Fanfou> fanfous = Parser.parseFanfouJSON(response);

return fanfous;
Expand All @@ -27,8 +25,6 @@ public static ArrayList<Fanfou> loadFanfouDailyFeeds(RequestQueue requestQueue,
public static ArrayList<Fanfou> loadFanfouWeeklyFeeds(RequestQueue requestQueue, String date) {

JSONObject response = Requestor.requestJSON(requestQueue, UrlUtils.getRequestUrlHead() + date + UrlUtils.getRequestUrlWeeklyEnd());
// Log.v("Getting response from", UrlUtils.getRequestUrlFanfouWeekly());
// Log.v("Loading", response.toString());
ArrayList<Fanfou> fanfous = Parser.parseFanfouJSON(response);

return fanfous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public View onCreateView(final LayoutInflater inflater, ViewGroup container,
@Override
public void run() {
if (HttpUtils.isNetworkConnected(getContext())) {
mSwipeRefreshLayout.setRefreshing(true);
Snackbar.make(mRecyclerView, getString(R.string.action_loading) + temp, Snackbar.LENGTH_SHORT).show();
fetchData(temp);
} else {
Snackbar.make(view, "Hey you don't have internet yet.", Snackbar.LENGTH_LONG).show();
Snackbar.make(view, getString(R.string.network_notworking), Snackbar.LENGTH_LONG).show();
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}
Expand All @@ -90,6 +92,13 @@ public void run() {
return view;
}

@Override
public void onResume() {
super.onResume();
if (listFanfous.isEmpty()){
fetchData(temp);
}
}
@Override
public void onDestroy() {
super.onDestroy();
Expand All @@ -98,6 +107,7 @@ public void onDestroy() {

public void onEvent(Date date) {
MyApplication.setDate(date);
Snackbar.make(mRecyclerView, getString(R.string.action_loading) + MyApplication.getDate().getDate(), Snackbar.LENGTH_SHORT).show();
fetchData(MyApplication.getDate().getDate());
}
@Override
Expand All @@ -116,9 +126,10 @@ public void onRefresh() {
@Override
public void run() {
if(HttpUtils.isNetworkConnected(getContext())) {
Snackbar.make(mRecyclerView, getString(R.string.action_loading) + temp, Snackbar.LENGTH_SHORT).show();
fetchData(temp);
} else {
Snackbar.make(getView(), "Hey you don't have internet yet.", Snackbar.LENGTH_LONG).show();
Snackbar.make(getView(), getString(R.string.network_notworking), Snackbar.LENGTH_LONG).show();
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}
Expand Down Expand Up @@ -196,8 +207,6 @@ private void startActivity(int position) {
}

public void fetchData(String date) {
// Toast.makeText(getContext(), "Start loading Fanfou on date:" + date, Toast.LENGTH_SHORT).show();
Snackbar.make(mRecyclerView, "Loading Fanfou on date:" + date, Snackbar.LENGTH_SHORT).show();
mSwipeRefreshLayout.setRefreshing(true);
new TaskLoadFanfouDaily(date).execute();
mFanfouAdapter.setFanfous(listFanfous);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public void run() {
return view;
}

@Override
public void onResume() {
super.onResume();
if (listFanfous.isEmpty()){
new TaskLoadFanfouWeekly().execute();
}
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Created by anthonyeef on 10/17/15.
*/
public class VolleySingleton {
private static VolleySingleton instance = null;
public static VolleySingleton instance = null;
private RequestQueue mRequestQueue;
private VolleySingleton() {
mRequestQueue = Volley.newRequestQueue(MyApplication.getAppContext());
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<resources>
<string name="app_name">饭否精选</string>
<string name="action_settings">设置</string>
<string name="action_loading">正在加载该日饭否精选--></string>
<string name="network_notworking">请先检查下网络数据</string>

<string name="name">Screen Name</string>
<string name="timestamp">Timestamp</string>
Expand All @@ -15,5 +17,10 @@
<string name="action_visit_repo">查看 GitHub repository</string>
<string name="changelog">更新记录</string>
<string name="developer">开发者</string>
<string name="coder"> \u0040Anthonyeef</string>

<string name="blog_address">https://anthonyeef.github.io</string>
<string name="project_address">https://anthonyeef.github.io/project/android/fanfoudaily</string>
<string name="project_github">https://github.com/Anthonyeef/FanfouDaily</string>

</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>
<string name="app_name">FanfouDaily</string>
<string name="action_settings">Settings</string>
<string name="action_loading">Loading Fanfou on date: </string>
<string name="network_notworking">Hey you don\'t have internet yet.</string>

<string name="name">Screen Name</string>
<string name="timestamp">Timestamp</string>
Expand All @@ -15,8 +17,9 @@
<string name="changelog">Changelog</string>
<string name="developer">Developer</string>

<string name="coder"> \u0040Anthonyeef</string>

<string name="blog_address">https://anthonyeef.github.io</string>
<string name="project_address">https://anthonyeef.github.io/FanfouDaily</string>
<string name="project_address">https://anthonyeef.github.io/project/android/fanfoudaily</string>
<string name="project_github">https://github.com/Anthonyeef/FanfouDaily</string>

</resources>
6 changes: 2 additions & 4 deletions app/src/main/res/xml/main_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
<intent android:action="android.intent.action.VIEW"
android:data="@string/project_github"/>
</Preference>
<Preference
android:key="changelog"
android:title="@string/changelog"/>
<Preference
android:key="developer"
android:title="@string/developer">
android:title="@string/developer"
android:summary="@string/coder">
</Preference>
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 52ff847

Please sign in to comment.