diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-12-23 20:11:52 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-12-23 20:11:52 -0800 |
commit | 01d29911c7affa298800cf93f7d7015263eb788e (patch) | |
tree | 89811eea0266e4e7c1376cb08fa743f3753cef03 /src/github/daneren2005 | |
parent | 0193bcb62b62271a00f7bc7a7400948470ea888c (diff) | |
download | dsub-01d29911c7affa298800cf93f7d7015263eb788e.tar.gz dsub-01d29911c7affa298800cf93f7d7015263eb788e.tar.bz2 dsub-01d29911c7affa298800cf93f7d7015263eb788e.zip |
#221, #225: Added By Year, default genres to album list if 4.9+
Diffstat (limited to 'src/github/daneren2005')
8 files changed, 145 insertions, 5 deletions
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index a190369d..65924685 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -142,6 +142,7 @@ public class MainFragment extends SubsonicFragment { final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent);
final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred);
final View albumsGenresButton = buttons.findViewById(R.id.main_albums_genres);
+ final View albumsYearButton = buttons.findViewById(R.id.main_albums_year);
final View dummyView = rootView.findViewById(R.id.main_dummy);
@@ -158,7 +159,7 @@ public class MainFragment extends SubsonicFragment { adapter.addView(offlineButton, true);
if (!Util.isOffline(context)) {
adapter.addView(albumsTitle, false);
- adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsStarredButton, albumsGenresButton, albumsRecentButton, albumsFrequentButton), true);
+ adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsStarredButton, albumsGenresButton, albumsYearButton, albumsRecentButton, albumsFrequentButton), true);
}
list.setAdapter(adapter);
registerForContextMenu(dummyView);
@@ -184,6 +185,8 @@ public class MainFragment extends SubsonicFragment { showAlbumList("starred");
} else if(view == albumsGenresButton) {
showAlbumList("genres");
+ } else if(view == albumsYearButton) {
+ showAlbumList("years");
}
}
});
@@ -219,6 +222,9 @@ public class MainFragment extends SubsonicFragment { if("genres".equals(type)) {
SubsonicFragment fragment = new SelectGenreFragment();
replaceFragment(fragment, R.id.home_layout);
+ } else if("years".equals(type)) {
+ SubsonicFragment fragment = new SelectYearFragment();
+ replaceFragment(fragment, R.id.home_layout);
} else {
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index cce14c31..4ed4123f 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -459,7 +459,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter setTitle(R.string.main_albums_frequent);
} else if ("starred".equals(albumListType)) {
setTitle(R.string.main_albums_starred);
- } else if("genres".equals(albumListType)) {
+ } else if("genres".equals(albumListType) || "years".equals(albumListType)) {
setTitle(albumListExtra);
}
@@ -469,6 +469,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter MusicDirectory result;
if ("starred".equals(albumListType)) {
result = service.getStarredList(context, this);
+ } else if(("genres".equals(albumListType) && Util.checkServerVersion(context, "1.10.0")) || "years".equals(albumListType)) {
+ result = service.getAlbumList(albumListType, albumListExtra, size, 0, context, this);
} else if("genres".equals(albumListType)) {
result = service.getSongsByGenre(albumListExtra, size, 0, context, this);
} else {
diff --git a/src/github/daneren2005/dsub/fragments/SelectYearFragment.java b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java new file mode 100644 index 00000000..acd3154a --- /dev/null +++ b/src/github/daneren2005/dsub/fragments/SelectYearFragment.java @@ -0,0 +1,79 @@ +/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 (C) Sindre Mehus
+*/
+package github.daneren2005.dsub.fragments;
+
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.util.Constants;
+
+/**
+ * Created by Scott on 12/23/13.
+ */
+public class SelectYearFragment extends SelectListFragment<Integer> {
+
+ @Override
+ public int getOptionsMenu() {
+ return R.menu.empty;
+ }
+
+ @Override
+ public ListAdapter getAdapter(List<Integer> objs) {
+ return new ArrayAdapter<Integer>(context, android.R.layout.simple_list_item_1, objs);
+ }
+
+ @Override
+ public List<Integer> getObjects(MusicService musicService) {
+ List<Integer> decades = new ArrayList<Integer>();
+ for(int i = 2010; i >= 1920; i -= 10) {
+ decades.add(i);
+ }
+
+ return decades;
+ }
+
+ @Override
+ public int getTitleResource() {
+ return R.string.main_albums_year;
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Integer decade = (Integer) parent.getItemAtPosition(position);
+
+ SubsonicFragment fragment = new SelectDirectoryFragment();
+ Bundle args = new Bundle();
+ args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, "years");
+ args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20);
+ args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
+ args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_EXTRA, Integer.toString(decade));
+ fragment.setArguments(args);
+
+ replaceFragment(fragment, R.id.fragment_list_layout);
+ }
+}
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index 3704d012..3c6168d2 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -235,7 +235,12 @@ public class CachedMusicService implements MusicService { return musicService.getAlbumList(type, size, offset, context, progressListener); } - @Override + @Override + public MusicDirectory getAlbumList(String type, String extra, int size, int offset, Context context, ProgressListener progressListener) throws Exception { + return musicService.getAlbumList(type, extra, size, offset, context, progressListener); + } + + @Override public MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception { return musicService.getStarredList(context, progressListener); } diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index b5b37354..1fb317ce 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -83,6 +83,8 @@ public interface MusicService { MusicDirectory getAlbumList(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getAlbumList(String type, String extra, int size, int offset, Context context, ProgressListener progressListener) throws Exception; + MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception; Bitmap getCoverArt(Context context, MusicDirectory.Entry entry, int size, int saveSize, ProgressListener progressListener) throws Exception; diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index 3386af70..0f6f0126 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -484,6 +484,11 @@ public class OfflineMusicService extends RESTMusicService { throw new OfflineException("Album lists not available in offline mode"); } + @Override + public MusicDirectory getAlbumList(String type, String extra, int size, int offset, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Album lists not available in offline mode"); + } + @Override public String getVideoUrl(int maxBitrate, Context context, String id) { return null; diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index c96f3569..5da92843 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -513,7 +513,44 @@ public class RESTMusicService implements MusicService { } } - @Override + @Override + public MusicDirectory getAlbumList(String type, String extra, int size, int offset, Context context, ProgressListener progressListener) throws Exception { + List<String> names = new ArrayList<String>(); + List<Object> values = new ArrayList<Object>(); + + names.add("size"); + names.add("offset"); + + values.add(size); + values.add(offset); + + if("genres".equals(type)) { + names.add("type"); + values.add("byGenre"); + + names.add("genre"); + values.add(extra); + } else if("years".equals(type)) { + names.add("type"); + values.add("byYear"); + + names.add("fromYear"); + names.add("toYear"); + + int decade = Integer.parseInt(extra); + values.add(decade); + values.add(decade + 10); + } + + Reader reader = getReader(context, progressListener, "getAlbumList", null, names, values); + try { + return new AlbumListParser(context).parse(reader, progressListener); + } finally { + Util.close(reader); + } + } + + @Override public MusicDirectory getStarredList(Context context, ProgressListener progressListener) throws Exception { Reader reader = getReader(context, progressListener, "getStarred", null); try { diff --git a/src/github/daneren2005/dsub/view/AlbumListAdapter.java b/src/github/daneren2005/dsub/view/AlbumListAdapter.java index 3ff8350b..1180b5c8 100644 --- a/src/github/daneren2005/dsub/view/AlbumListAdapter.java +++ b/src/github/daneren2005/dsub/view/AlbumListAdapter.java @@ -28,6 +28,8 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.util.Util;
+
import java.util.List;
public class AlbumListAdapter extends EndlessAdapter {
@@ -53,7 +55,9 @@ public class AlbumListAdapter extends EndlessAdapter { protected boolean cacheInBackground() throws Exception {
MusicService service = MusicServiceFactory.getMusicService(context);
MusicDirectory result;
- if("genres".equals(type)) {
+ if(("genres".equals(type) && Util.checkServerVersion(context, "1.10.0")) || "years".equals(type)) {
+ result = service.getAlbumList(type, extra, size, offset, context, null);
+ } else if("genres".equals(type)) {
result = service.getSongsByGenre(extra, size, offset, context, null);
} else {
result = service.getAlbumList(type, size, offset, context, null);
|