aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-08-27 13:11:02 -0700
committerScott Jackson <daneren2005@gmail.com>2014-08-27 13:11:02 -0700
commit3b07693d398de0dac28d6bae7125892815c2562a (patch)
treee7095adb71d8aa8740c29244bce6f84c3265b925 /src/github
parentd25274d4c310c62dca2340c31d702e23fd1b4f0c (diff)
downloaddsub-3b07693d398de0dac28d6bae7125892815c2562a.tar.gz
dsub-3b07693d398de0dac28d6bae7125892815c2562a.tar.bz2
dsub-3b07693d398de0dac28d6bae7125892815c2562a.zip
#377 Keep track of and display recent count between startups
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java58
1 files changed, 42 insertions, 16 deletions
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 7b1cbd4d..6e0c0c8c 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -251,6 +251,16 @@ public class MainFragment extends SubsonicFragment {
SubsonicFragment fragment = new SelectYearFragment();
replaceFragment(fragment);
} else {
+ // Clear out recently added count when viewing
+ if("newest".equals(type)) {
+ SharedPreferences.Editor editor = Util.getPreferences(Context).edit();
+ editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT, 0);
+ editor.commit();
+
+ // Clear immediately so doesn't still show when pressing back
+ setMostRecentCount(0);
+ }
+
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type);
@@ -445,10 +455,15 @@ public class MainFragment extends SubsonicFragment {
}
private void getMostRecentCount() {
+ // Use stashed value until after refresh occurs
+ SharedPreferences prefs = Util.getPreferences(context);
+ final int startCount = prefs.getInt(Constants.PREFERENCES_KEY_RECENT_COUNT, 0);
+ setMostRecentCount(startCount);
+
new SilentBackgroundTask<Integer>(context) {
@Override
public Integer doInBackground() {
- String recentAddedFile = "mostrecent" + (Util.getRestUrl(context, null, false)).hashCode() + ".ser";
+ String recentAddedFile = "recent_count" + (Util.getRestUrl(context, null, false)).hashCode() + ".ser";
ArrayList<String> recents = FileUtil.deserialize(context, recentAddedFile, ArrayList.class);
if(recents == null) {
recents = new ArrayList<String>();
@@ -468,31 +483,24 @@ public class MainFragment extends SubsonicFragment {
count++;
}
}
+ FileUtil.serialize(context, recents, recentAddedFile);
if(firstRun) {
return 0;
} else {
+ // Add the old count which will get cleared out after viewing recents
+ count += startCount;
+ SharedPreferences.Editor editor = Util.getPreferences(context).edit();
+ editor.putInt(Constants.PEFERENCES_KEY_RECENT_COUNT, count);
+ editor.commit();
+
return count;
}
}
@Override
public void done(Integer result) {
- TextView countView = rootView.findViewById(R.id.main_albums_recent_count);
-
- String displayValue;
- if(result < 0) {
- countView.setVisibility(View.GONE);
- } else {
- if(result < 10) {
- displayValue = "0" + result;
- } else {
- displayValue = "" + result;
- }
-
- countView.setText(displayValue);
- countView.setVisibility(View.VISIBLE);
- }
+ setMostRecentCount(result);
}
@Override
@@ -501,4 +509,22 @@ public class MainFragment extends SubsonicFragment {
}
}.execute();
}
+
+ private void setMostRecentCount(int count) {
+ TextView countView = rootView.findViewById(R.id.main_albums_recent_count);
+
+ if(count < 0) {
+ countView.setVisibility(View.GONE);
+ } else {
+ String displayValue;
+ if(result < 10) {
+ displayValue = "0" + count;
+ } else {
+ displayValue = "" + count;
+ }
+
+ countView.setText(displayValue);
+ countView.setVisibility(View.VISIBLE);
+ }
+ }
}