Skip to content

Commit

Permalink
feat: implemented additional sorting options for albums in the catalo…
Browse files Browse the repository at this point in the history
…g screen
  • Loading branch information
CappielloAntonio committed Nov 20, 2024
1 parent 0f471a7 commit 780f1c3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.os.Parcelable
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import java.time.Instant
import java.time.LocalDate
import java.util.*

@Keep
Expand All @@ -17,12 +19,12 @@ open class AlbumID3 : Parcelable {
var coverArtId: String? = null
var songCount: Int? = 0
var duration: Int? = 0
var playCount: Long? = null
var playCount: Long? = 0
var created: Date? = null
var starred: Date? = null
var year: Int = 0
var genre: String? = null
var played: String? = null
var played: Date? = Date(0)
var userRating: Int? = 0
var recordLabels: List<RecordLabel>? = null
var musicBrainzId: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public void sort(String order) {
albums.sort(Comparator.comparing(AlbumID3::getCreated));
Collections.reverse(albums);
break;
case Constants.ALBUM_ORDER_BY_RECENTLY_PLAYED:
albums.sort(Comparator.comparing(AlbumID3::getPlayed));
Collections.reverse(albums);
break;
case Constants.ALBUM_ORDER_BY_MOST_PLAYED:
albums.sort(Comparator.comparing(AlbumID3::getPlayCount));
Collections.reverse(albums);
break;
}

notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ private void showPopupMenu(View view, int menuResource) {
} else if (menuItem.getItemId() == R.id.menu_album_sort_recently_added) {
albumAdapter.sort(Constants.ALBUM_ORDER_BY_RECENTLY_ADDED);
return true;
} else if (menuItem.getItemId() == R.id.menu_album_sort_recently_played) {
albumAdapter.sort(Constants.ALBUM_ORDER_BY_RECENTLY_PLAYED);
return true;
} else if (menuItem.getItemId() == R.id.menu_album_sort_most_played) {
albumAdapter.sort(Constants.ALBUM_ORDER_BY_MOST_PLAYED);
return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object Constants {
const val ALBUM_ORDER_BY_YEAR = "ALBUM_ORDER_BY_YEAR"
const val ALBUM_ORDER_BY_RANDOM = "ALBUM_ORDER_BY_RANDOM"
const val ALBUM_ORDER_BY_RECENTLY_ADDED = "ALBUM_ORDER_BY_RECENTLY_ADDED"
const val ALBUM_ORDER_BY_RECENTLY_PLAYED = "ALBUM_ORDER_BY_RECENTLY_PLAYED"
const val ALBUM_ORDER_BY_MOST_PLAYED = "ALBUM_ORDER_BY_MOST_PLAYED"

const val ARTIST_DOWNLOADED = "ARTIST_DOWNLOADED"
const val ARTIST_STARRED = "ARTIST_STARRED"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/sort_album_popup_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
<item
android:id="@+id/menu_album_sort_recently_added"
android:title="@string/menu_sort_recently_added" />
<item
android:id="@+id/menu_album_sort_recently_played"
android:title="@string/menu_sort_recently_played" />
<item
android:id="@+id/menu_album_sort_most_played"
android:title="@string/menu_sort_most_played" />
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
<string name="menu_sort_name">Name</string>
<string name="menu_sort_random">Random</string>
<string name="menu_sort_recently_added">Recently added</string>
<string name="menu_sort_recently_played">Recently played</string>
<string name="menu_sort_most_played">Most played</string>
<string name="menu_pin_button">Add to home screen</string>
<string name="menu_unpin_button">Remove from home screen</string>
<string name="menu_sort_year">Year</string>
Expand Down

0 comments on commit 780f1c3

Please sign in to comment.