diff --git a/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/LibraryFragment.java b/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/LibraryFragment.java index 9d566c69..09bae8b5 100644 --- a/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/LibraryFragment.java +++ b/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/LibraryFragment.java @@ -184,14 +184,8 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde menu.findItem(R.id.action_colored_footers).setChecked(absLibraryRecyclerViewCustomGridSizeFragment.usePalette()); menu.findItem(R.id.action_colored_footers).setEnabled(absLibraryRecyclerViewCustomGridSizeFragment.canUsePalette()); - // TODO the API doesn't support artist sorting - if (currentFragment instanceof ArtistsFragment) { - menu.removeItem(R.id.action_sort_method); - menu.removeItem(R.id.action_sort_order); - } else { - setUpSortMethodMenu(absLibraryRecyclerViewCustomGridSizeFragment, menu.findItem(R.id.action_sort_method).getSubMenu()); - setUpSortOrderMenu(absLibraryRecyclerViewCustomGridSizeFragment, menu.findItem(R.id.action_sort_order).getSubMenu()); - } + setUpSortMethodMenu(absLibraryRecyclerViewCustomGridSizeFragment, menu.findItem(R.id.action_sort_method).getSubMenu()); + setUpSortOrderMenu(absLibraryRecyclerViewCustomGridSizeFragment, menu.findItem(R.id.action_sort_order).getSubMenu()); } else { menu.removeItem(R.id.action_grid_size); menu.removeItem(R.id.action_colored_footers); @@ -344,32 +338,28 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde SortMethod currentSortMethod = fragment.getSortMethod(); sortMethodMenu.clear(); + sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_method_name) + .setChecked(currentSortMethod.equals(SortMethod.NAME)); + if (fragment instanceof AlbumsFragment) { - sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_method_name) - .setChecked(currentSortMethod.equals(SortMethod.NAME)); sortMethodMenu.add(0, R.id.action_sort_method_artist, 1, R.string.sort_method_artist) .setChecked(currentSortMethod.equals(SortMethod.ARTIST)); sortMethodMenu.add(0, R.id.action_sort_method_year, 2, R.string.sort_method_year) .setChecked(currentSortMethod.equals(SortMethod.YEAR)); - sortMethodMenu.add(0, R.id.action_sort_method_added, 3, R.string.sort_method_added) - .setChecked(currentSortMethod.equals(SortMethod.ADDED)); - sortMethodMenu.add(0, R.id.action_sort_method_random, 4, R.string.sort_method_random) - .setChecked(currentSortMethod.equals(SortMethod.RANDOM)); } else if (fragment instanceof SongsFragment) { - sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_method_name) - .setChecked(currentSortMethod.equals(SortMethod.NAME)); sortMethodMenu.add(0, R.id.action_sort_method_album, 1, R.string.sort_method_album) .setChecked(currentSortMethod.equals(SortMethod.ALBUM)); sortMethodMenu.add(0, R.id.action_sort_method_artist, 2, R.string.sort_method_artist) .setChecked(currentSortMethod.equals(SortMethod.ARTIST)); sortMethodMenu.add(0, R.id.action_sort_method_year, 3, R.string.sort_method_year) .setChecked(currentSortMethod.equals(SortMethod.YEAR)); - sortMethodMenu.add(0, R.id.action_sort_method_added, 4, R.string.sort_method_added) - .setChecked(currentSortMethod.equals(SortMethod.ADDED)); - sortMethodMenu.add(0, R.id.action_sort_method_random, 5, R.string.sort_method_random) - .setChecked(currentSortMethod.equals(SortMethod.RANDOM)); } + sortMethodMenu.add(0, R.id.action_sort_method_added, 4, R.string.sort_method_added) + .setChecked(currentSortMethod.equals(SortMethod.ADDED)); + sortMethodMenu.add(0, R.id.action_sort_method_random, 5, R.string.sort_method_random) + .setChecked(currentSortMethod.equals(SortMethod.RANDOM)); + sortMethodMenu.setGroupCheckable(0, true, true); } diff --git a/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/pager/ArtistsFragment.java b/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/pager/ArtistsFragment.java index f454f787..3af5121b 100644 --- a/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/pager/ArtistsFragment.java +++ b/app/src/main/java/com/dkanada/gramophone/fragments/mainactivity/library/pager/ArtistsFragment.java @@ -51,6 +51,9 @@ public class ArtistsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFr query.setStartIndex(getAdapter().getItemCount()); query.setParentId(QueryUtil.currentLibrary.getId()); + query.setSortBy(new String[]{PreferenceUtil.getInstance(App.getInstance()).getArtistSortMethod().getApi()}); + query.setSortOrder(PreferenceUtil.getInstance(App.getInstance()).getArtistSortOrder().getApi()); + return query; } @@ -95,12 +98,12 @@ public class ArtistsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFr @Override protected SortMethod loadSortMethod() { - return SortMethod.NAME; + return PreferenceUtil.getInstance(getActivity()).getArtistSortMethod(); } @Override protected void saveSortMethod(SortMethod sortMethod) { - // not supported through API + PreferenceUtil.getInstance(getActivity()).setArtistSortMethod(sortMethod); } @Override @@ -109,12 +112,12 @@ public class ArtistsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFr @Override protected SortOrder loadSortOrder() { - return SortOrder.ASCENDING; + return PreferenceUtil.getInstance(getActivity()).getArtistSortOrder(); } @Override protected void saveSortOrder(SortOrder sortOrder) { - // not supported through API + PreferenceUtil.getInstance(getActivity()).setArtistSortOrder(sortOrder); } @Override diff --git a/app/src/main/java/com/dkanada/gramophone/util/PreferenceUtil.java b/app/src/main/java/com/dkanada/gramophone/util/PreferenceUtil.java index 43018eb4..1c72a017 100644 --- a/app/src/main/java/com/dkanada/gramophone/util/PreferenceUtil.java +++ b/app/src/main/java/com/dkanada/gramophone/util/PreferenceUtil.java @@ -43,9 +43,11 @@ public final class PreferenceUtil { public static final String ALBUM_SORT_METHOD = "album_sort_method"; public static final String SONG_SORT_METHOD = "song_sort_method"; + public static final String ARTIST_SORT_METHOD = "artist_sort_method"; public static final String ALBUM_SORT_ORDER = "album_sort_order"; public static final String SONG_SORT_ORDER = "song_sort_order"; + public static final String ARTIST_SORT_ORDER = "artist_sort_order"; public static final String ALBUM_GRID_SIZE = "album_grid_size"; public static final String ALBUM_GRID_SIZE_LAND = "album_grid_size_land"; @@ -271,6 +273,14 @@ public final class PreferenceUtil { mPreferences.edit().putString(SONG_SORT_ORDER, sortOrder.toString()).apply(); } + public final SortOrder getArtistSortOrder() { + return SortOrder.valueOf(mPreferences.getString(ARTIST_SORT_ORDER, SortOrder.ASCENDING.toString())); + } + + public void setArtistSortOrder(SortOrder sortOrder) { + mPreferences.edit().putString(ARTIST_SORT_ORDER, sortOrder.toString()).apply(); + } + public final SortMethod getAlbumSortMethod() { return SortMethod.valueOf(mPreferences.getString(ALBUM_SORT_METHOD, SortMethod.RANDOM.toString())); } @@ -287,6 +297,14 @@ public final class PreferenceUtil { mPreferences.edit().putString(SONG_SORT_METHOD, sortMethod.toString()).apply(); } + public final SortMethod getArtistSortMethod() { + return SortMethod.valueOf(mPreferences.getString(ARTIST_SORT_METHOD, SortMethod.NAME.toString())); + } + + public void setArtistSortMethod(SortMethod sortMethod) { + mPreferences.edit().putString(ARTIST_SORT_METHOD, sortMethod.toString()).apply(); + } + public int getLastSleepTimerValue() { return mPreferences.getInt(SLEEP_TIMER_LAST_VALUE, 30); }