diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistCatalogueFragment.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistCatalogueFragment.java
index 208ef4d7..7e7ce759 100644
--- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistCatalogueFragment.java
+++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/ArtistCatalogueFragment.java
@@ -34,6 +34,7 @@ import com.cappielloantonio.tempo.interfaces.ClickCallback;
import com.cappielloantonio.tempo.ui.activity.MainActivity;
import com.cappielloantonio.tempo.ui.adapter.ArtistCatalogueAdapter;
import com.cappielloantonio.tempo.util.Constants;
+import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.ArtistCatalogueViewModel;
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
@@ -114,7 +115,10 @@ public class ArtistCatalogueFragment extends Fragment implements ClickCallback {
artistAdapter = new ArtistCatalogueAdapter(this);
artistAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
bind.artistCatalogueRecyclerView.setAdapter(artistAdapter);
- artistCatalogueViewModel.getArtistList().observe(getViewLifecycleOwner(), artistList -> artistAdapter.setItems(artistList));
+ artistCatalogueViewModel.getArtistList().observe(getViewLifecycleOwner(), artistList -> {
+ artistAdapter.setItems(artistList);
+ artistAdapter.sort(Preferences.getArtistSortOrder());
+ });
bind.artistCatalogueRecyclerView.setOnTouchListener((v, event) -> {
hideKeyboard(v);
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/values/strings.xml b/app/src/main/res/values/strings.xml
index b06c81c0..2dafec49 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -528,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" />
+
+