diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/ArtistCatalogueAdapter.java b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/ArtistCatalogueAdapter.java index 77c3169a..b1defe42 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/ArtistCatalogueAdapter.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/ArtistCatalogueAdapter.java @@ -151,6 +151,9 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter artistAdapter.setItems(artistList)); + artistCatalogueViewModel.getArtistList().observe(getViewLifecycleOwner(), artistList -> { + artistAdapter.setItems(artistList); + artistAdapter.sort(Preferences.getArtistSortOrder()); + }); bind.artistCatalogueRecyclerView.setOnTouchListener((v, event) -> { hideKeyboard(v); @@ -192,6 +196,9 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback { } else if (menuItem.getItemId() == R.id.menu_artist_sort_random) { artistAdapter.sort(Constants.ARTIST_ORDER_BY_RANDOM); return true; + } else if (menuItem.getItemId() == R.id.menu_artist_sort_album_count) { + artistAdapter.sort(Constants.ARTIST_ORDER_BY_ALBUM_COUNT); + return true; } return false; diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt index bf2a1a72..c6a4e3a4 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt @@ -40,6 +40,7 @@ object Constants { const val ARTIST_STARRED = "ARTIST_STARRED" const val ARTIST_ORDER_BY_NAME = "ARTIST_ORDER_BY_NAME" const val ARTIST_ORDER_BY_RANDOM = "ARTIST_ORDER_BY_RANDOM" + const val ARTIST_ORDER_BY_ALBUM_COUNT = "ARTIST_ORDER_BY_ALBUM_COUNT" const val ARTIST_ORDER_BY_MOST_RECENTLY_STARRED = "ARTIST_ORDER_BY_MOST_RECENTLY_STARRED" const val ARTIST_ORDER_BY_LEAST_RECENTLY_STARRED = "ARTIST_ORDER_BY_LEAST_RECENTLY_STARRED" diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt index 4815fb83..42ffa524 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Preferences.kt @@ -79,6 +79,7 @@ object Preferences { private const val ALBUM_DETAIL = "album_detail" private const val ALBUM_SORT_ORDER = "album_sort_order" private const val DEFAULT_ALBUM_SORT_ORDER = Constants.ALBUM_ORDER_BY_NAME + private const val ARTIST_SORT_BY_ALBUM_COUNT= "artist_sort_by_album_count" @JvmStatic fun getServer(): String? { @@ -656,4 +657,14 @@ object Preferences { fun setAlbumSortOrder(sortOrder: String) { App.getInstance().preferences.edit().putString(ALBUM_SORT_ORDER, sortOrder).apply() } + + @JvmStatic + fun getArtistSortOrder(): String { + val sort_by_album_count = App.getInstance().preferences.getBoolean(ARTIST_SORT_BY_ALBUM_COUNT, false) + Log.d("Preferences", "getSortOrder") + if (sort_by_album_count) + return Constants.ARTIST_ORDER_BY_ALBUM_COUNT + else + return Constants.ARTIST_ORDER_BY_NAME + } } \ No newline at end of file diff --git a/app/src/main/res/menu/sort_artist_popup_menu.xml b/app/src/main/res/menu/sort_artist_popup_menu.xml index f072c452..4253d92a 100644 --- a/app/src/main/res/menu/sort_artist_popup_menu.xml +++ b/app/src/main/res/menu/sort_artist_popup_menu.xml @@ -6,4 +6,7 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c5b35a88..2dafec49 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -200,6 +200,7 @@ Artist Name Random + Album Count Recently added Recently played Most played @@ -527,4 +528,6 @@ Show album detail If enabled, show the album details like genre, song count etc. on the album page + Sort artists by album count + If enabled, sort the artists by album count. Sort by name if disabled. diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index 4610e255..a8caeb8b 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -116,6 +116,12 @@ android:summary="@string/settings_album_detail_summary" android:key="album_detail" /> + +