From 30b678fe56cf44218b25397aa8579a01d87090ec Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 6 Mar 2015 17:38:39 -0800 Subject: #463 Add videos section --- res/layout/main_buttons.xml | 12 ++++ res/values/strings.xml | 1 + .../daneren2005/dsub/fragments/MainFragment.java | 12 ++++ .../dsub/fragments/SelectVideoFragment.java | 82 ++++++++++++++++++++++ .../dsub/service/CachedMusicService.java | 5 ++ .../daneren2005/dsub/service/MusicService.java | 2 + .../dsub/service/OfflineMusicService.java | 5 ++ .../daneren2005/dsub/service/RESTMusicService.java | 11 +++ .../dsub/service/parser/VideosParser.java | 53 ++++++++++++++ 9 files changed, 183 insertions(+) create mode 100644 src/github/daneren2005/dsub/fragments/SelectVideoFragment.java create mode 100644 src/github/daneren2005/dsub/service/parser/VideosParser.java diff --git a/res/layout/main_buttons.xml b/res/layout/main_buttons.xml index 29f2acdb..e18589d9 100644 --- a/res/layout/main_buttons.xml +++ b/res/layout/main_buttons.xml @@ -77,6 +77,13 @@ android:layout_gravity="right"/> + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 99dd17b3..fb780817 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -73,6 +73,7 @@ Genres Decades Alphabetically + Videos @string/main.albums_genres Press back again to exit Completed scan of Server diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index ac29b274..7225f551 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -154,6 +154,7 @@ public class MainFragment extends SubsonicFragment { offlineButton.setText(Util.isOffline(context) ? R.string.main_online : R.string.main_offline); final View albumsTitle = buttons.findViewById(R.id.main_albums); + final View videoTitle = buttons.findViewById(R.id.main_video_section); 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); @@ -164,6 +165,7 @@ public class MainFragment extends SubsonicFragment { final View albumsGenresButton = buttons.findViewById(R.id.main_albums_genres); final View albumsYearButton = buttons.findViewById(R.id.main_albums_year); final View albumsAlphabeticalButton = buttons.findViewById(R.id.main_albums_alphabetical); + final View videosButton = buttons.findViewById(R.id.main_videos); final View dummyView = rootView.findViewById(R.id.main_dummy); @@ -201,6 +203,10 @@ public class MainFragment extends SubsonicFragment { adapter.addView(albumsHighestButton, true); } adapter.addViews(Arrays.asList(albumsStarredButton, albumsGenresButton, albumsYearButton, albumsRecentButton, albumsFrequentButton), true); + if(ServerInfo.checkServerVersion(context, "1.8") && !Util.isTagBrowsing(context)) { + adapter.addView(videoTitle, false); + adapter.addView(videosButton, true); + } } list.setAdapter(adapter); registerForContextMenu(dummyView); @@ -230,6 +236,8 @@ public class MainFragment extends SubsonicFragment { showAlbumList("years"); } else if(view == albumsAlphabeticalButton) { showAlbumList("alphabeticalByName"); + } else if(view == videosButton) { + showVideos(); } } }); @@ -301,6 +309,10 @@ public class MainFragment extends SubsonicFragment { replaceFragment(fragment); } } + private void showVideos() { + SubsonicFragment fragment = new SelectVideoFragment(); + replaceFragment(fragment); + } private void showOfflineSyncDialog(final int scrobbleCount, final int starsCount) { String syncDefault = Util.getSyncDefault(context); diff --git a/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java b/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java new file mode 100644 index 00000000..0c8519e8 --- /dev/null +++ b/src/github/daneren2005/dsub/fragments/SelectVideoFragment.java @@ -0,0 +1,82 @@ +/* + 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 . + Copyright 2015 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.fragments; + +import android.view.ContextMenu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; + +import java.util.List; + +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.util.ProgressListener; +import github.daneren2005.dsub.view.EntryAdapter; + +public class SelectVideoFragment extends SelectListFragment { + @Override + public int getOptionsMenu() { + return R.menu.empty; + } + + @Override + public ArrayAdapter getAdapter(List objs) { + return new EntryAdapter(context, null, objs, false); + } + + @Override + public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + MusicDirectory dir = musicService.getVideos(refresh, context, listener); + return dir.getChildren(); + } + + @Override + public int getTitleResource() { + return R.string.main_videos; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); + playVideo(entry); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + Object entry = listView.getItemAtPosition(info.position); + + onCreateContextMenu(menu, view, menuInfo, entry); + recreateContextMenu(menu); + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + if (menuItem.getGroupId() != getSupportTag()) { + return false; + } + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Object entry = listView.getItemAtPosition(info.position); + + return onContextItemSelected(menuItem, entry); + } +} diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java index dec3c665..79399483 100644 --- a/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -918,6 +918,11 @@ public class CachedMusicService implements MusicService { return musicService.getBitmap(url, size, context, progressListener, task); } + @Override + public MusicDirectory getVideos(boolean refresh, Context context, ProgressListener progressListener) throws Exception { + return musicService.getVideos(refresh, context, progressListener); + } + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return musicService.processOfflineSyncs(context, progressListener); diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java index 2c5a7f2a..b4b99911 100644 --- a/src/github/daneren2005/dsub/service/MusicService.java +++ b/src/github/daneren2005/dsub/service/MusicService.java @@ -183,6 +183,8 @@ public interface MusicService { ArtistInfo getArtistInfo(String id, boolean refresh, Context context, ProgressListener progressListener) throws Exception; Bitmap getBitmap(String url, int size, Context context, ProgressListener progressListener, SilentBackgroundTask task) throws Exception; + + MusicDirectory getVideos(boolean refresh, Context context, ProgressListener progressListener) throws Exception; int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception; diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java index c0fc89fe..c66ba598 100644 --- a/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -798,6 +798,11 @@ public class OfflineMusicService implements MusicService { throw new OfflineException(ERRORMSG); } + @Override + public MusicDirectory getVideos(boolean refresh, Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException(ERRORMSG); + } + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ throw new OfflineException(ERRORMSG); diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 40a2f849..036cb0ca 100644 --- a/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -92,6 +92,7 @@ import github.daneren2005.dsub.service.parser.SearchResultParser; import github.daneren2005.dsub.service.parser.ShareParser; import github.daneren2005.dsub.service.parser.StarredListParser; import github.daneren2005.dsub.service.parser.UserParser; +import github.daneren2005.dsub.service.parser.VideosParser; import github.daneren2005.dsub.service.ssl.SSLSocketFactory; import github.daneren2005.dsub.service.ssl.TrustSelfSignedStrategy; import github.daneren2005.dsub.util.BackgroundTask; @@ -1525,6 +1526,16 @@ public class RESTMusicService implements MusicService { } } + @Override + public MusicDirectory getVideos(boolean refresh, Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "getVideos", null); + try { + return new VideosParser(context, getInstance(context)).parse(reader, progressListener); + } finally { + Util.close(reader); + } + } + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener); diff --git a/src/github/daneren2005/dsub/service/parser/VideosParser.java b/src/github/daneren2005/dsub/service/parser/VideosParser.java new file mode 100644 index 00000000..f22c4a4a --- /dev/null +++ b/src/github/daneren2005/dsub/service/parser/VideosParser.java @@ -0,0 +1,53 @@ +/* + 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 . + Copyright 2015 (C) Scott Jackson +*/ + +package github.daneren2005.dsub.service.parser; + +import android.content.Context; + +import org.xmlpull.v1.XmlPullParser; + +import java.io.Reader; + +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.util.ProgressListener; + +public class VideosParser extends MusicDirectoryEntryParser { + public VideosParser(Context context, int instance) { + super(context, instance); + } + + public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception { + init(reader); + + MusicDirectory dir = new MusicDirectory(); + int eventType; + do { + eventType = nextParseEvent(); + if (eventType == XmlPullParser.START_TAG) { + String name = getElementName(); + if ("video".equals(name)) { + MusicDirectory.Entry entry = parseEntry(""); + dir.addChild(entry); + } else if ("error".equals(name)) { + handleError(); + } + } + } while (eventType != XmlPullParser.END_DOCUMENT); + + validate(); + return dir; + } +} -- cgit v1.2.3