diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-27 20:07:57 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-27 20:07:57 -0700 |
commit | 265b76c093b6f75e5e9517a1aa1710f30de1b41f (patch) | |
tree | 924aa3eb26b9484059ba0527958ac0ad76cc7939 | |
parent | 35ad6f8dc17cf3e5231981ac025ad6ef6fcea3a4 (diff) | |
download | dsub-265b76c093b6f75e5e9517a1aa1710f30de1b41f.tar.gz dsub-265b76c093b6f75e5e9517a1aa1710f30de1b41f.tar.bz2 dsub-265b76c093b6f75e5e9517a1aa1710f30de1b41f.zip |
#377 Finish up recently added dev
-rw-r--r-- | src/github/daneren2005/dsub/fragments/MainFragment.java | 22 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Constants.java | 1 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 6e0c0c8c..7485da71 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -21,6 +21,7 @@ import android.widget.CheckBox; import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
@@ -42,6 +43,7 @@ import java.util.List; public class MainFragment extends SubsonicFragment {
private static final String TAG = MainFragment.class.getSimpleName();
private LayoutInflater inflater;
+ private TextView countView;
private static final int MENU_GROUP_SERVER = 10;
private static final int MENU_ITEM_SERVER_BASE = 100;
@@ -152,6 +154,7 @@ public class MainFragment extends SubsonicFragment { final View albumsTitle = buttons.findViewById(R.id.main_albums);
final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest);
+ countView = (TextView) buttons.findViewById(R.id.main_albums_recent_count);
final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random);
final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest);
final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent);
@@ -207,7 +210,10 @@ public class MainFragment extends SubsonicFragment { }
});
setTitle(R.string.common_appname);
- getMostRecentCount();
+
+ if(!Util.isOffline(context)) {
+ getMostRecentCount();
+ }
}
private void setActiveServer(int instance) {
@@ -253,7 +259,7 @@ public class MainFragment extends SubsonicFragment { } else {
// Clear out recently added count when viewing
if("newest".equals(type)) {
- SharedPreferences.Editor editor = Util.getPreferences(Context).edit();
+ SharedPreferences.Editor editor = Util.getPreferences(context).edit();
editor.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT, 0);
editor.commit();
@@ -462,7 +468,7 @@ public class MainFragment extends SubsonicFragment { new SilentBackgroundTask<Integer>(context) {
@Override
- public Integer doInBackground() {
+ public Integer doInBackground() throws Exception {
String recentAddedFile = "recent_count" + (Util.getRestUrl(context, null, false)).hashCode() + ".ser";
ArrayList<String> recents = FileUtil.deserialize(context, recentAddedFile, ArrayList.class);
if(recents == null) {
@@ -478,7 +484,7 @@ public class MainFragment extends SubsonicFragment { // Count how many new albums are in the list
int count = 0;
for(MusicDirectory.Entry album: recentlyAdded.getChildren()) {
- if(!recents.contains(album.getId()) {
+ if(!recents.contains(album.getId())) {
recents.add(album.getId());
count++;
}
@@ -491,7 +497,7 @@ public class MainFragment extends SubsonicFragment { // 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.putInt(Constants.PREFERENCES_KEY_RECENT_COUNT, count);
editor.commit();
return count;
@@ -511,13 +517,11 @@ public class MainFragment extends SubsonicFragment { }
private void setMostRecentCount(int count) {
- TextView countView = rootView.findViewById(R.id.main_albums_recent_count);
-
- if(count < 0) {
+ if(count <= 0) {
countView.setVisibility(View.GONE);
} else {
String displayValue;
- if(result < 10) {
+ if(count < 10) {
displayValue = "0" + count;
} else {
displayValue = "" + count;
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 80ee6419..5fb872f2 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -144,6 +144,7 @@ public final class Constants { public static final String PREFERENCES_KEY_PLAYLIST_NAME = "suggestedPlaylistName"; public static final String PREFERENCES_KEY_PLAYLIST_ID = "suggestedPlaylistId"; public static final String PREFERENCES_KEY_SERVER_SYNC = "serverSync"; + public static final String PREFERENCES_KEY_RECENT_COUNT = "mostRecentCount"; public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount"; public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; |