diff options
-rw-r--r-- | res/menu/select_artist.xml | 5 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 138 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 6 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Constants.java | 1 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/util/Util.java | 17 |
6 files changed, 138 insertions, 32 deletions
diff --git a/res/menu/select_artist.xml b/res/menu/select_artist.xml index 127736d6..8e1cdba3 100644 --- a/res/menu/select_artist.xml +++ b/res/menu/select_artist.xml @@ -14,6 +14,11 @@ compat:showAsAction="ifRoom|withText"/> <item + android:id="@+id/menu_first_level_artist" + android:title="@string/menu.first_level_artist" + android:checkable="true"/> + + <item android:id="@+id/menu_exit" android:title="@string/menu.exit"/> </menu> diff --git a/res/values/strings.xml b/res/values/strings.xml index 6caa152f..054d5047 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -55,6 +55,8 @@ <br/>When songs are downloaded by DSub, they can be deleted to make room for new downloads. Permanently cached music on the other hand will never be automatically deleted.
<p/><font color="red">ChromeCast fails</font>:
<br/>Try setting the option Settings -> Playback -> Use device proxy. It is a work around for Chromecast not accepting self-signed certificates.
+ <p/><font color="red">First level in Library are actually groups of artists</font>:
+ <br/>In the option menu, deselect "First level artists". This will make it so that the entire first level of directories shown will be treated like groups of artists instead of the artists themselves.
]]>
</string>
<string name="main.select_server">Select server</string>
@@ -110,6 +112,7 @@ <string name="menu.similar_artists">Similar Artists</string>
<string name="menu.show_missing">Show missing</string>
<string name="menu.start_radio">Start Radio</string>
+ <string name="menu.first_level_artist">First level artists</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
diff --git a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 6477f6cc..9b6e86d3 100644 --- a/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -1,8 +1,9 @@ package github.daneren2005.dsub.fragments;
+import android.annotation.TargetApi;
+import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
-import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
@@ -11,11 +12,9 @@ import android.view.MenuInflater; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
-import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.Artist;
@@ -23,11 +22,8 @@ import github.daneren2005.dsub.domain.Indexes; import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicFolder;
import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
-import github.daneren2005.dsub.util.BackgroundTask;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
-import github.daneren2005.dsub.util.TabBackgroundTask;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.ArtistAdapter;
@@ -44,6 +40,12 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { private TextView folderName;
private List<MusicFolder> musicFolders = null;
private List<MusicDirectory.Entry> entries;
+ private String groupId;
+ private String groupName;
+
+ public SelectArtistFragment() {
+ super();
+ }
@Override
public void onCreate(Bundle bundle) {
@@ -61,8 +63,20 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { outState.putSerializable(Constants.FRAGMENT_LIST2, (Serializable) musicFolders);
}
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
+ Bundle args = getArguments();
+ if(args != null) {
+ groupId = args.getString(Constants.INTENT_EXTRA_NAME_ID);
+ groupName = args.getString(Constants.INTENT_EXTRA_NAME_NAME);
+
+ if(groupName != null) {
+ setTitle(groupName);
+ context.invalidateOptionsMenu();
+ }
+ }
+
folderButton = null;
super.onCreateView(inflater, container, bundle);
@@ -71,7 +85,7 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { }
if(objects != null && currentTask == null) {
- if (Util.isOffline(context) || Util.isTagBrowsing(context)) {
+ if (Util.isOffline(context) || Util.isTagBrowsing(context) || groupId != null) {
folderButton.setVisibility(View.GONE);
}
setMusicFolders();
@@ -140,15 +154,25 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { selectFolder();
} else {
Artist artist = (Artist) parent.getItemAtPosition(position);
- SubsonicFragment 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);
+
+ SubsonicFragment fragment;
+ if(Util.isFirstLevelArtist(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);
+ }
+ 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());
+ fragment.setArguments(args);
}
- args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
- fragment.setArguments(args);
replaceFragment(fragment);
}
@@ -160,11 +184,39 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { }
@Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ super.onCreateOptionsMenu(menu, menuInflater);
+
+ if(Util.isOffline(context) || Util.isTagBrowsing(context) || groupId != null) {
+ menu.removeItem(R.id.menu_first_level_artist);
+ } else {
+ if (Util.isFirstLevelArtist(context)) {
+ menu.findItem(R.id.menu_first_level_artist).setChecked(true);
+ }
+ }
+ }
+
+ @Override
public int getOptionsMenu() {
return R.menu.select_artist;
}
@Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if(super.onOptionsItemSelected(item)) {
+ return true;
+ }
+
+ switch (item.getItemId()) {
+ case R.id.menu_first_level_artist:
+ toggleFirstLevelArtist();
+ break;
+ }
+
+ return false;
+ }
+
+ @Override
public ArrayAdapter getAdapter(List<Artist> objects) {
createMusicFolderButton();
return new ArtistAdapter(context, objects);
@@ -172,29 +224,52 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { @Override
public List<Artist> getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
- if(!Util.isOffline(context) && !Util.isTagBrowsing(context)) {
- musicFolders = musicService.getMusicFolders(refresh, context, listener);
+ List<Artist> artists;
+ if(groupId == null) {
+ if (!Util.isOffline(context) && !Util.isTagBrowsing(context)) {
+ musicFolders = musicService.getMusicFolders(refresh, context, listener);
+
+ // Hide folders option if there is only one
+ if (musicFolders.size() == 1) {
+ musicFolders = null;
+ Util.setSelectedMusicFolderId(context, null);
+ }
+ }
+ String musicFolderId = Util.getSelectedMusicFolderId(context);
+
+ Indexes indexes = musicService.getIndexes(musicFolderId, refresh, context, listener);
+ artists = new ArrayList<Artist>(indexes.getShortcuts().size() + indexes.getArtists().size());
+ artists.addAll(indexes.getShortcuts());
+ artists.addAll(indexes.getArtists());
+ entries = indexes.getEntries();
+ } else {
+ artists = new ArrayList<Artist>();
+ MusicDirectory dir = musicService.getMusicDirectory(groupId, groupName, refresh, context, listener);
+ for(MusicDirectory.Entry entry: dir.getChildren(true, false)) {
+ Artist artist = new Artist();
+ artist.setId(entry.getId());
+ artist.setName(entry.getTitle());
+ artist.setStarred(entry.isStarred());
+ artists.add(artist);
+ }
- // Hide folders option if there is only one
- if(musicFolders.size() == 1) {
- musicFolders = null;
- Util.setSelectedMusicFolderId(context, null);
+ entries = new ArrayList<MusicDirectory.Entry>();
+ entries.addAll(dir.getChildren(false, true));
+ if(!entries.isEmpty()) {
+ Artist root = new Artist();
+ root.setId("root");
+ root.setName("Root");
+ root.setIndex("#");
+ artists.add(root);
}
}
- String musicFolderId = Util.getSelectedMusicFolderId(context);
-
- Indexes indexes = musicService.getIndexes(musicFolderId, refresh, context, listener);
- List<Artist> artists = new ArrayList<Artist>(indexes.getShortcuts().size() + indexes.getArtists().size());
- artists.addAll(indexes.getShortcuts());
- artists.addAll(indexes.getArtists());
- entries = indexes.getEntries();
return artists;
}
@Override
public int getTitleResource() {
- return R.string.button_bar_browse;
+ return groupId == null ? R.string.button_bar_browse : 0;
}
private void createMusicFolderButton() {
@@ -252,4 +327,9 @@ public class SelectArtistFragment extends SelectListFragment<Artist> { private void selectFolder() {
folderButton.showContextMenu();
}
+
+ private void toggleFirstLevelArtist() {
+ Util.toggleFirstLevelArtist(context);
+ context.invalidateOptionsMenu();
+ }
}
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index aa34ca4b..327f1828 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -520,7 +520,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter // Update the fragment pointers so other stuff works correctly
SelectDirectoryFragment.this.id = dir.getId();
SelectDirectoryFragment.this.name = dir.getName();
- } else if(id != null && directory == null && dir.getParent() != null) {
+ } else if(id != null && directory == null && dir.getParent() != null && !artist) {
// View Album, try to lookup parent to get a complete entry to use for starring
MusicDirectory parentDir = getMusicDirectory(dir.getParent(), name, refresh, true, service, this);
for(Entry child: parentDir.getChildren()) {
@@ -1514,7 +1514,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star);
- if(directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)) {
+ if(directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true) && artistInfo == null) {
starButton.setImageResource(directory.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
starButton.setOnClickListener(new View.OnClickListener() {
@Override
@@ -1533,7 +1533,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter View ratingBarWrapper = header.findViewById(R.id.select_album_rate_wrapper);
final RatingBar ratingBar = (RatingBar) header.findViewById(R.id.select_album_rate);
- if(directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true) && !Util.isOffline(context)) {
+ if(directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true) && !Util.isOffline(context) && artistInfo == null) {
ratingBar.setRating(directory.getRating());
ratingBarWrapper.setOnClickListener(new View.OnClickListener() {
@Override
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java index 9622e84c..7ab2b736 100644 --- a/src/github/daneren2005/dsub/util/Constants.java +++ b/src/github/daneren2005/dsub/util/Constants.java @@ -155,6 +155,7 @@ public final class Constants { public static final String PREFERENCES_KEY_CAST_PROXY = "castProxy"; public static final String PREFERENCES_KEY_DISABLE_EXIT_PROMPT = "disableExitPrompt"; public static final String PREFERENCES_KEY_RENAME_DUPLICATES = "renameDuplicates"; + public static final String PREFERENCES_KEY_FIRST_LEVEL_ARTIST = "firstLevelArtist"; public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount"; public static final String OFFLINE_SCROBBLE_ID = "scrobbleID"; diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index 4d2a9a1a..20cca368 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -575,6 +575,23 @@ public final class Util { return prefs.getBoolean(Constants.PREFERENCES_KEY_CAST_PROXY, false); } + public static boolean isFirstLevelArtist(Context context) { + SharedPreferences prefs = getPreferences(context); + return prefs.getBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), true); + } + public static void toggleFirstLevelArtist(Context context) { + SharedPreferences prefs = Util.getPreferences(context); + SharedPreferences.Editor editor = prefs.edit(); + + if(prefs.getBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), true)) { + editor.putBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), false); + } else { + editor.putBoolean(Constants.PREFERENCES_KEY_FIRST_LEVEL_ARTIST + getActiveServer(context), true); + } + + editor.commit(); + } + /** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p/> |