diff options
Diffstat (limited to 'app/src/main/java/github')
24 files changed, 283 insertions, 129 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 51de1f6c..ca6dd168 100644 --- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -225,7 +225,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo bottomBar.setVisibility(View.GONE); nowPlayingToolbar.setVisibility(View.VISIBLE); setSupportActionBar(nowPlayingToolbar); - nowPlayingFragment.setPrimaryFragment(true); + + if(secondaryFragment == null) { + nowPlayingFragment.setPrimaryFragment(true); + } else { + secondaryFragment.setPrimaryFragment(true); + } drawerToggle.setDrawerIndicatorEnabled(false); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -396,14 +401,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo if(currentFragment instanceof SearchFragment) { String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY); boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); - boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false); if (query != null) { ((SearchFragment)currentFragment).search(query, autoplay); - } else { - if (requestsearch) { - onSearchRequested(); - } } getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY); } else { @@ -472,6 +472,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putString(Constants.MAIN_NOW_PLAYING, nowPlayingFragment.getTag()); + if(secondaryFragment != null) { + savedInstanceState.putString(Constants.MAIN_NOW_PLAYING_SECONDARY, secondaryFragment.getTag()); + } savedInstanceState.putInt(Constants.MAIN_SLIDE_PANEL_STATE, slideUpPanel.getPanelState().hashCode()); } @Override @@ -481,6 +484,19 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo String id = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING); FragmentManager fm = getSupportFragmentManager(); nowPlayingFragment = (NowPlayingFragment) fm.findFragmentByTag(id); + + String secondaryId = savedInstanceState.getString(Constants.MAIN_NOW_PLAYING_SECONDARY); + if(secondaryId != null) { + secondaryFragment = (SubsonicFragment) fm.findFragmentByTag(secondaryId); + + nowPlayingFragment.setPrimaryFragment(false); + secondaryFragment.setPrimaryFragment(true); + + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.hide(nowPlayingFragment); + trans.commit(); + } + if(drawerToggle != null && backStack.size() > 0) { drawerToggle.setDrawerIndicatorEnabled(false); } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java index 207dc0b2..5ed79e82 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java @@ -23,27 +23,32 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import java.io.Serializable; import java.util.List; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.MusicDirectory.Entry; import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistView; import github.daneren2005.dsub.view.FastScroller; +import github.daneren2005.dsub.view.SongView; import github.daneren2005.dsub.view.UpdateView; -public class ArtistAdapter extends SectionAdapter<Artist> implements FastScroller.BubbleTextGetter { +public class ArtistAdapter extends SectionAdapter<Serializable> implements FastScroller.BubbleTextGetter { + public static int VIEW_TYPE_SONG = 3; public static int VIEW_TYPE_ARTIST = 4; private List<MusicFolder> musicFolders; private OnMusicFolderChanged onMusicFolderChanged; - public ArtistAdapter(Context context, List<Artist> artists, OnItemClickedListener listener) { + public ArtistAdapter(Context context, List<Serializable> artists, OnItemClickedListener listener) { this(context, artists, null, listener, null); } - public ArtistAdapter(Context context, List<Artist> artists, List<MusicFolder> musicFolders, OnItemClickedListener onItemClickedListener, OnMusicFolderChanged onMusicFolderChanged) { + public ArtistAdapter(Context context, List<Serializable> artists, List<MusicFolder> musicFolders, OnItemClickedListener onItemClickedListener, OnMusicFolderChanged onMusicFolderChanged) { super(context, artists); this.musicFolders = musicFolders; this.onItemClickedListener = onItemClickedListener; @@ -110,17 +115,35 @@ public class ArtistAdapter extends SectionAdapter<Artist> implements FastScrolle @Override public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) { - return new UpdateView.UpdateViewHolder(new ArtistView(context)); + UpdateView updateView = null; + if(viewType == VIEW_TYPE_ARTIST) { + updateView = new ArtistView(context); + } else if(viewType == VIEW_TYPE_SONG) { + updateView = new SongView(context); + } + + return new UpdateView.UpdateViewHolder(updateView); } @Override - public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Artist item, int viewType) { - holder.getUpdateView().setObject(item); + public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Serializable item, int viewType) { + UpdateView view = holder.getUpdateView(); + if(viewType == VIEW_TYPE_ARTIST) { + view.setObject(item); + } else if(viewType == VIEW_TYPE_SONG) { + SongView songView = (SongView) view; + Entry entry = (Entry) item; + songView.setObject(entry, checkable && !entry.isVideo()); + } } @Override - public int getItemViewType(Artist item) { - return VIEW_TYPE_ARTIST; + public int getItemViewType(Serializable item) { + if(item instanceof Artist) { + return VIEW_TYPE_ARTIST; + } else { + return VIEW_TYPE_SONG; + } } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java index b07d4731..e75a5104 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/EntryGridAdapter.java @@ -44,6 +44,7 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { private ImageLoader imageLoader; private boolean largeAlbums; private boolean showArtist = false; + private boolean showAlbum = false; private boolean removeFromPlaylist = false; private View header; @@ -87,6 +88,7 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { albumView.setObject(entry, imageLoader); } else if(viewType == VIEW_TYPE_SONG) { SongView songView = (SongView) view; + songView.setShowAlbum(showAlbum); songView.setObject(entry, checkable && !entry.isVideo()); } } @@ -123,6 +125,10 @@ public class EntryGridAdapter extends SectionAdapter<Entry> { this.showArtist = showArtist; } + public void setShowAlbum(boolean showAlbum) { + this.showAlbum = showAlbum; + } + public void removeAt(int index) { sections.get(0).remove(index); if(header != null) { diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java index b1a692d5..6ebb34e3 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java @@ -78,7 +78,6 @@ public abstract class ExpandableSectionAdapter<T> extends SectionAdapter<T> { } else { visibleSection.addAll(fullSection.subList(0, defaultVisible)); this.sectionsExtras.add(fullSection.subList(defaultVisible, fullSection.size())); - Log.d(TAG, visibleSection.size() + " + " + this.sectionsExtras.get(i).size()); } this.sections.add(visibleSection); diff --git a/app/src/main/java/github/daneren2005/dsub/domain/Artist.java b/app/src/main/java/github/daneren2005/dsub/domain/Artist.java index 5809146d..ff4d86ce 100644 --- a/app/src/main/java/github/daneren2005/dsub/domain/Artist.java +++ b/app/src/main/java/github/daneren2005/dsub/domain/Artist.java @@ -130,12 +130,6 @@ public class Artist implements Serializable { } public int compare(Artist lhsArtist, Artist rhsArtist) { - if("root".equals(lhsArtist.getId())) { - return 1; - } else if("root".equals(rhsArtist.getId())) { - return -1; - } - String lhs = lhsArtist.getName().toLowerCase(); String rhs = rhsArtist.getName().toLowerCase(); diff --git a/app/src/main/java/github/daneren2005/dsub/domain/Indexes.java b/app/src/main/java/github/daneren2005/dsub/domain/Indexes.java index e15ccf9f..05e686ca 100644 --- a/app/src/main/java/github/daneren2005/dsub/domain/Indexes.java +++ b/app/src/main/java/github/daneren2005/dsub/domain/Indexes.java @@ -52,13 +52,6 @@ public class Indexes implements Serializable { this.shortcuts = shortcuts; this.artists = artists; this.entries = entries; - if(!entries.isEmpty()) { - Artist root = new Artist(); - root.setId("root"); - root.setName("Root"); - root.setIndex("#"); - artists.add(root); - } } public long getLastModified() { diff --git a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java index e4c9b17d..7f538484 100644 --- a/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java +++ b/app/src/main/java/github/daneren2005/dsub/domain/ServerInfo.java @@ -203,7 +203,7 @@ public class ServerInfo implements Serializable { } public static boolean hasArtistInfo(Context context) { - if(isStockSubsonic(context) && ServerInfo.checkServerVersion(context, "1.11")) { + if(!isMadsonic(context) && ServerInfo.checkServerVersion(context, "1.11")) { return true; } else if(isMadsonic(context)) { return checkServerVersion(context, "2.0"); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java index f3d675f0..8c2fa4bf 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/MainFragment.java @@ -1,6 +1,7 @@ package github.daneren2005.dsub.fragments; import android.content.Intent; +import android.content.pm.PackageInfo; import android.content.res.Resources; import android.net.Uri; import android.os.Build; @@ -63,6 +64,7 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.main, menu); + onFinishSetupOptionsMenu(menu); try { if (!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) { @@ -269,7 +271,7 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { private void getLogs() { try { - final String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; + final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); new LoadingTask<String>(context) { @Override protected String doInBackground() throws Throwable { @@ -372,10 +374,11 @@ public class MainFragment extends SelectRecyclerFragment<Integer> { footer += "\nDevice Name: " + Build.MANUFACTURER + " " + Build.PRODUCT; footer += "\nROM: " + Build.DISPLAY; footer += "\nLogs: " + logcat; + footer += "\nBuild Number: " + packageInfo.versionCode; Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "dsub.android@gmail.com", null)); - email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + version + " Error Logs"); + email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + packageInfo.versionName + " Error Logs"); email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here\n\n\n" + footer); startActivity(email); } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 87ccbd64..530c03b6 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -1244,7 +1244,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis this.currentPlaying = currentPlaying; setupSubtitle(currentPlayingIndex); - if(currentPlaying != null && currentPlaying.getSong() != null && (currentPlaying.getSong().isPodcast() || currentPlaying.getSong().isAudioBook())) { + if(currentPlaying != null && !currentPlaying.isSong()) { previousButton.setVisibility(View.GONE); nextButton.setVisibility(View.GONE); diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java index c891da34..eed714af 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java @@ -7,6 +7,7 @@ import java.util.List; import android.content.Intent; import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; @@ -125,18 +126,7 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.search, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_global_search: - context.startSearch(currentQuery, false, null, false); - return true; - } - - return super.onOptionsItemSelected(item); - + onFinishSetupOptionsMenu(menu); } @Override @@ -218,6 +208,14 @@ public class SearchFragment extends SubsonicFragment implements SectionAdapter.O } }; task.execute(); + + if(searchItem != null) { + MenuItemCompat.collapseActionView(searchItem); + } + } + + protected String getCurrentQuery() { + return currentQuery; } private void onArtistSelected(Artist artist, boolean autoplay) { diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 6890f572..c9b94c9a 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -17,6 +17,7 @@ import github.daneren2005.dsub.adapter.SectionAdapter; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.Indexes; import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.MusicDirectory.Entry; import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.domain.ServerInfo; import github.daneren2005.dsub.service.MusicService; @@ -29,12 +30,11 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -public class SelectArtistFragment extends SelectRecyclerFragment<Artist> implements ArtistAdapter.OnMusicFolderChanged { +public class SelectArtistFragment extends SelectRecyclerFragment<Serializable> implements ArtistAdapter.OnMusicFolderChanged { private static final String TAG = SelectArtistFragment.class.getSimpleName(); - private static final int MENU_GROUP_MUSIC_FOLDER = 10; private List<MusicFolder> musicFolders = null; - private List<MusicDirectory.Entry> entries; + private List<Entry> entries; private String groupId; private String groupName; @@ -80,48 +80,68 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Artist> impleme } @Override - public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Artist> updateView, Artist item) { + public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Serializable> updateView, Serializable item) { onCreateContextMenuSupport(menu, menuInflater, updateView, item); recreateContextMenu(menu); } @Override - public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Artist> updateView, Artist item) { + public boolean onContextItemSelected(MenuItem menuItem, UpdateView<Serializable> updateView, Serializable item) { return onContextItemSelected(menuItem, item); } @Override - public void onItemClicked(UpdateView<Artist> updateView, Artist artist) { + public void onItemClicked(UpdateView<Serializable> updateView, Serializable item) { SubsonicFragment fragment; - if((Util.isFirstLevelArtist(context) || Util.isOffline(context) || Util.isTagBrowsing(context)) || "root".equals(artist.getId()) || groupId != null) { - fragment = new SelectDirectoryFragment(); - Bundle args = new Bundle(); - args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - - if ("root".equals(artist.getId())) { - args.putSerializable(Constants.FRAGMENT_LIST, (Serializable) entries); - } - if(ServerInfo.checkServerVersion(context, "1.13") && !Util.isOffline(context)) { - args.putSerializable(Constants.INTENT_EXTRA_NAME_DIRECTORY, new MusicDirectory.Entry(artist)); + if(item instanceof Artist) { + Artist artist = (Artist) item; + + if ((Util.isFirstLevelArtist(context) || Util.isOffline(context) || Util.isTagBrowsing(context)) || groupId != null) { + fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + + if (ServerInfo.checkServerVersion(context, "1.13") && !Util.isOffline(context)) { + args.putSerializable(Constants.INTENT_EXTRA_NAME_DIRECTORY, new Entry(artist)); + } + args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); + + fragment.setArguments(args); + } else { + fragment = new SelectArtistFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); + if (ServerInfo.checkServerVersion(context, "1.13") && !Util.isOffline(context)) { + args.putSerializable(Constants.INTENT_EXTRA_NAME_DIRECTORY, new Entry(artist)); + } + + fragment.setArguments(args); } - args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); - fragment.setArguments(args); + replaceFragment(fragment); } else { - fragment = new SelectArtistFragment(); - Bundle args = new Bundle(); - args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true); - if(ServerInfo.checkServerVersion(context, "1.13") && !Util.isOffline(context)) { - args.putSerializable(Constants.INTENT_EXTRA_NAME_DIRECTORY, new MusicDirectory.Entry(artist)); + Entry entry = (Entry) item; + if (entry.isVideo()) { + playVideo(entry); + } else { + List<Entry> songs = new ArrayList<Entry>(); + + if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, true)) { + for (Entry song : entries) { + if (!song.isDirectory() && !song.isVideo()) { + songs.add(song); + } + } + playNow(songs, entry, 0); + } else { + songs.add(entry); + playNow(songs); + } } - - fragment.setArguments(args); } - - replaceFragment(fragment); } @Override @@ -158,13 +178,13 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Artist> impleme } @Override - public SectionAdapter getAdapter(List<Artist> objects) { + public SectionAdapter getAdapter(List<Serializable> objects) { return new ArtistAdapter(context, objects, musicFolders, this, this); } @Override - public List<Artist> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { - List<Artist> artists; + public List<Serializable> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + List<Serializable> items; if(groupId == null) { if (!Util.isOffline(context) && (!Util.isTagBrowsing(context) || ServerInfo.checkServerVersion(context, "1.14"))) { musicFolders = musicService.getMusicFolders(refresh, context, listener); @@ -181,14 +201,16 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Artist> impleme Indexes indexes = musicService.getIndexes(musicFolderId, refresh, context, listener); indexes.sortChildren(context); - artists = new ArrayList<>(indexes.getShortcuts().size() + indexes.getArtists().size()); - artists.addAll(indexes.getShortcuts()); - artists.addAll(indexes.getArtists()); + items = new ArrayList<>(indexes.getShortcuts().size() + indexes.getArtists().size()); + items.addAll(indexes.getShortcuts()); + items.addAll(indexes.getArtists()); entries = indexes.getEntries(); + items.addAll(entries); } else { - artists = new ArrayList<>(); + List<Artist> artists = new ArrayList<>(); + items = new ArrayList<>(); MusicDirectory dir = musicService.getMusicDirectory(groupId, groupName, refresh, context, listener); - for(MusicDirectory.Entry entry: dir.getChildren(true, false)) { + for(Entry entry: dir.getChildren(true, false)) { Artist artist = new Artist(); artist.setId(entry.getId()); artist.setName(entry.getTitle()); @@ -196,21 +218,17 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Artist> impleme artists.add(artist); } - entries = new ArrayList<>(); - entries.addAll(dir.getChildren(false, true)); - if(!entries.isEmpty()) { - Artist root = new Artist(); - root.setId("root"); - root.setName("Root"); - root.setIndex("#"); - artists.add(root); - } - - Indexes indexes = new Indexes(0, artists, new ArrayList<Artist>()); + Indexes indexes = new Indexes(0, new ArrayList<Artist>(), artists); indexes.sortChildren(context); + items.addAll(indexes.getArtists()); + + entries = dir.getChildren(false, true); + for(Entry entry: entries) { + items.add(entry); + } } - return artists; + return items; } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 67dcc6a2..de74d0ed 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -234,7 +234,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section if(!ServerInfo.hasTopSongs(context)) { menu.removeItem(R.id.menu_top_tracks); } - if(!ServerInfo.checkServerVersion(context, "1.11") || (id != null && "root".equals(id))) { + if(!ServerInfo.checkServerVersion(context, "1.11")) { menu.removeItem(R.id.menu_radio); menu.removeItem(R.id.menu_similar_artists); } else if(!ServerInfo.hasSimilarArtists(context)) { @@ -379,9 +379,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section @Override protected void refresh(boolean refresh) { - if(!"root".equals(id)) { - load(refresh); - } + load(refresh); } @Override @@ -747,11 +745,14 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section if(!artist) { entryGridAdapter.setShowArtist(true); } + if(topTracks) { + entryGridAdapter.setShowAlbum(true); + } // Show header if not album list type and not root and not artist // For Subsonic 5.1+ display a header for artists with getArtistInfo data if it exists boolean addedHeader = false; - if(albumListType == null && !"root".equals(id) && (!artist || artistInfo != null || artistInfoDelayed != null) && (share == null || entries.size() != albums.size())) { + if(albumListType == null && (!artist || artistInfo != null || artistInfoDelayed != null) && (share == null || entries.size() != albums.size())) { View header = createHeader(); if(header != null) { diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java index 7ae7fff8..0d4506ac 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectRecyclerFragment.java @@ -15,10 +15,15 @@ package github.daneren2005.dsub.fragments; +import android.app.SearchManager; +import android.app.SearchableInfo; +import android.content.Context; import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; @@ -102,6 +107,7 @@ public abstract class SelectRecyclerFragment<T> extends SubsonicFragment impleme } menuInflater.inflate(getOptionsMenu(), menu); + onFinishSetupOptionsMenu(menu); } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index f733c977..9cc27128 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -20,6 +20,9 @@ package github.daneren2005.dsub.fragments; import android.annotation.TargetApi; import android.app.Activity; +import android.app.SearchManager; +import android.app.SearchableInfo; +import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -37,6 +40,7 @@ import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; import android.util.Log; import android.view.GestureDetector; import android.view.Menu; @@ -125,6 +129,8 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected boolean artistOverride = false; protected SwipeRefreshLayout refreshLayout; protected boolean firstRun; + protected MenuItem searchItem; + protected SearchView searchView; public SubsonicFragment() { super(); @@ -177,15 +183,36 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR this.context = context; } + protected void onFinishSetupOptionsMenu(final Menu menu) { + searchItem = menu.findItem(R.id.menu_global_search); + if(searchItem != null) { + searchView = (SearchView) MenuItemCompat.getActionView(searchItem); + SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); + SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName()); + if(searchableInfo == null) { + Log.w(TAG, "Failed to get SearchableInfo"); + } else { + searchView.setSearchableInfo(searchableInfo); + } + + String currentQuery = getCurrentQuery(); + if(currentQuery != null) { + searchView.setOnSearchClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + searchView.setQuery(getCurrentQuery(), false); + } + }); + } + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_global_shuffle: onShuffleRequested(); return true; - case R.id.menu_global_search: - context.onSearchRequested(); - return true; case R.id.menu_exit: exit(); return true; @@ -1927,6 +1954,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return false; } + protected String getCurrentQuery() { + return null; + } + public abstract class RecursiveLoader extends LoadingTask<Boolean> { protected MusicService musicService; protected static final int MAX_SONGS = 500; diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java index 20126f01..e4bab798 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java @@ -84,6 +84,9 @@ public class DownloadFile implements BufferFile { public MusicDirectory.Entry getSong() { return song; } + public boolean isSong() { + return song.isSong(); + } public Context getContext() { return context; diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 98e678c1..7168083c 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -88,6 +88,7 @@ import android.support.v7.media.MediaRouteSelector; import android.support.v7.media.MediaRouter; import android.util.Log; import android.support.v4.util.LruCache; +import android.view.KeyEvent; /** * @author Sindre Mehus @@ -1169,8 +1170,8 @@ public class DownloadService extends Service { } // If only one song, just skip within song - if(size() == 1) { - seekTo(getPlayerPosition() - REWIND); + if(size() == 1 || (currentPlaying != null && !currentPlaying.isSong())) { + rewind(); return; } @@ -1195,8 +1196,8 @@ public class DownloadService extends Service { } public synchronized void next(boolean forceCutoff, boolean forceStart) { // If only one song, just skip within song - if(size() == 1) { - seekTo(getPlayerPosition() + FAST_FORWARD); + if(size() == 1 || (currentPlaying != null && !currentPlaying.isSong())) { + fastForward(); return; } else if(playerState == PREPARING || playerState == PREPARED) { return; @@ -2719,6 +2720,10 @@ public class DownloadService extends Service { wakeLock.acquire(ms); } + public void handleKeyEvent(KeyEvent keyEvent) { + lifecycleSupport.handleKeyEvent(keyEvent); + } + public void addOnSongChangedListener(OnSongChangedListener listener) { addOnSongChangedListener(listener, false); } diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 5e9e04fc..f8272356 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -386,7 +386,7 @@ public class DownloadServiceLifecycleSupport { return lastChange; } - private void handleKeyEvent(KeyEvent event) { + public void handleKeyEvent(KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() > 0) { switch (event.getKeyCode()) { case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS: diff --git a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java index 4c3a121d..1f9e5494 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RESTMusicService.java @@ -608,7 +608,7 @@ public class RESTMusicService implements MusicService { int decade = Integer.parseInt(extra); // Reverse chronological order only supported in 5.3+ - if(ServerInfo.checkServerVersion(context, "1.13", instance) && ServerInfo.isStockSubsonic(context, instance)) { + if(ServerInfo.checkServerVersion(context, "1.13", instance) && !ServerInfo.isMadsonic(context, instance)) { values.add(decade + 9); values.add(decade); } else { @@ -696,7 +696,13 @@ public class RESTMusicService implements MusicService { int instance = getInstance(context); String method; - if(ServerInfo.isMadsonic(context, instance)) { + if(ServerInfo.isMadsonic6(context, instance)) { + if (Util.isTagBrowsing(context, instance)) { + method = "getSimilarSongsID3"; + } else { + method = "getSimilarSongs"; + } + } else if(ServerInfo.isMadsonic(context, instance)) { method = "getPandoraSongs"; } else { if (Util.isTagBrowsing(context, instance)) { @@ -1942,7 +1948,7 @@ public class RESTMusicService implements MusicService { for (int i = 0; i < parameterNames.size(); i++) { builder.append("&").append(parameterNames.get(i)).append("="); String part = URLEncoder.encode(String.valueOf(parameterValues.get(i)), "UTF-8"); - part = part.replaceAll("\\%27", "'"); + part = part.replaceAll("\\%27", "'"); builder.append(part); } url = builder.toString(); diff --git a/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java b/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java index fce855fe..31e83200 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java +++ b/app/src/main/java/github/daneren2005/dsub/util/BackgroundTask.java @@ -208,8 +208,18 @@ public abstract class BackgroundTask<T> implements ProgressListener { handler.post(new Runnable() { @Override public void run() { - if(!isCancelled()) { - onDone(result); + if (!isCancelled()) { + try { + onDone(result); + } catch (Throwable t) { + if(!isCancelled()) { + try { + onError(t); + } catch(Exception e) { + // Don't care + } + } + } } taskStart.set(false); diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java index 230cce16..c8c580ff 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java @@ -191,6 +191,7 @@ public final class Constants { public static final String MAIN_BACK_STACK = "backStackIds"; public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize"; public static final String MAIN_NOW_PLAYING = "nowPlayingId"; + public static final String MAIN_NOW_PLAYING_SECONDARY = "nowPlayingSecondaryId"; public static final String MAIN_SLIDE_PANEL_STATE = "slidePanelState"; public static final String FRAGMENT_LIST = "fragmentList"; public static final String FRAGMENT_LIST2 = "fragmentList2"; diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java index c3f1a086..9f742ef0 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/Util.java +++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java @@ -412,13 +412,15 @@ public final class Util { String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); if(allowAltAddress && Util.isWifiConnected(context)) { String SSID = prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, ""); - String currentSSID = Util.getSSID(context); - - String[] ssidParts = SSID.split(","); - if("".equals(SSID) || SSID.equals(currentSSID) || Arrays.asList(ssidParts).contains(currentSSID)) { - String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); - if(internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { - serverUrl = internalUrl; + if(!SSID.isEmpty()) { + String currentSSID = Util.getSSID(context); + + String[] ssidParts = SSID.split(","); + if ("".equals(SSID) || SSID.equals(currentSSID) || Arrays.asList(ssidParts).contains(currentSSID)) { + String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null); + if (internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { + serverUrl = internalUrl; + } } } } @@ -919,6 +921,10 @@ public final class Util { return formatDate(context, dateString, true); } public static String formatDate(Context context, String dateString, boolean includeTime) { + if(dateString == null) { + return ""; + } + try { dateString = dateString.replace(' ', 'T'); boolean isDateNormalized = ServerInfo.checkServerVersion(context, "1.11"); diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java index d210fbb0..df468155 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java +++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java @@ -34,7 +34,10 @@ import android.media.session.PlaybackState; import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; +import android.support.annotation.NonNull; import android.support.v7.media.MediaRouter; +import android.util.Log; +import android.view.KeyEvent; import java.io.Serializable; import java.util.ArrayList; @@ -145,11 +148,17 @@ public class RemoteControlClientLP extends RemoteControlClientBase { position = downloadService.getPlayerPosition(); } builder.setState(newState, position, 1.0f); - builder.setActions(getPlaybackActions()); - DownloadFile downloadFile = downloadService.getCurrentPlaying(); + Entry entry = null; + boolean isSong = true; if(downloadFile != null) { - Entry entry = downloadFile.getSong(); + entry = downloadFile.getSong(); + isSong = entry.isSong(); + } + + builder.setActions(getPlaybackActions(isSong)); + + if(entry != null) { addCustomActions(entry, builder); builder.setActiveQueueItemId(entry.getId().hashCode()); } @@ -231,7 +240,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase { return mediaSession; } - protected long getPlaybackActions() { + protected long getPlaybackActions(boolean isSong) { long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SEEK_TO | @@ -239,10 +248,15 @@ public class RemoteControlClientLP extends RemoteControlClientBase { int currentIndex = downloadService.getCurrentPlayingIndex(); int size = downloadService.size(); - if(currentIndex > 0) { + if(isSong) { + if (currentIndex > 0) { + actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS; + } + if (currentIndex < size - 1) { + actions |= PlaybackState.ACTION_SKIP_TO_NEXT; + } + } else { actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS; - } - if(currentIndex < size - 1) { actions |= PlaybackState.ACTION_SKIP_TO_NEXT; } @@ -311,7 +325,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase { return null; } - + private void playFromParent(Entry parent) throws Exception { List<Entry> songs = new ArrayList<>(); getSongsRecursively(parent, songs); @@ -569,5 +583,18 @@ public class RemoteControlClientLP extends RemoteControlClientBase { downloadService.toggleStarred(); } } + + @Override + public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) { + if (getMediaSession() != null && Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonIntent.getAction())) { + KeyEvent keyEvent = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); + if (keyEvent != null) { + downloadService.handleKeyEvent(keyEvent); + return true; + } + } + + return super.onMediaButtonEvent(mediaButtonIntent); + } } } diff --git a/app/src/main/java/github/daneren2005/dsub/view/CardView.java b/app/src/main/java/github/daneren2005/dsub/view/CardView.java index b9e0bcce..d6bca330 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/CardView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/CardView.java @@ -61,7 +61,6 @@ public class CardView extends FrameLayout{ // clipPath is not supported with Hardware Acceleration before API 18 // http://stackoverflow.com/questions/8895677/work-around-canvas-clippath-that-is-not-supported-in-android-any-more/8895894#8895894 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && isHardwareAccelerated()) { - Log.d(TAG, "Change to software"); setLayerType(View.LAYER_TYPE_SOFTWARE, null); } } diff --git a/app/src/main/java/github/daneren2005/dsub/view/SongView.java b/app/src/main/java/github/daneren2005/dsub/view/SongView.java index 84e04a0b..8cb0c21c 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/SongView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/SongView.java @@ -71,6 +71,7 @@ public class SongView extends UpdateView2<MusicDirectory.Entry, Boolean> { private boolean showPodcast = false; private boolean isPlayed = false; private boolean isPlayedShown = false; + private boolean showAlbum = false; public SongView(Context context) { super(context); @@ -114,7 +115,11 @@ public class SongView extends UpdateView2<MusicDirectory.Entry, Boolean> { } } else if(song.getArtist() != null) { - artist.append(song.getArtist()); + if(showAlbum) { + artist.append(song.getAlbum()); + } else { + artist.append(song.getArtist()); + } } if(isPodcast) { @@ -354,4 +359,8 @@ public class SongView extends UpdateView2<MusicDirectory.Entry, Boolean> { public void setShowPodcast(boolean showPodcast) { this.showPodcast = showPodcast; } + + public void setShowAlbum(boolean showAlbum) { + this.showAlbum = showAlbum; + } } |