Tracks: fix sort by insertion date

Fixes #2925, 2920
This commit is contained in:
Duncan McNamara 2023-05-10 18:21:46 +02:00 committed by Nicolas Pomepuy
parent 6113d68fa5
commit 154f35e8ac
9 changed files with 35 additions and 13 deletions

View File

@ -16,6 +16,9 @@
<string name="sortby_date">Date</string>
<string name="sortby_last_modified_date">Recently added</string>
<string name="sortby_insertion">Insertion date</string>
<string name="sortby_date_last_modified">Recently added</string>
<string name="sortby_date_insertion">Insertion date</string>
<string name="sortby_date_release">Release date</string>
<string name="sortby_media_number">Media number</string>
<string name="sortby_number">Nb tracks</string>
<string name="searchable_hint">Search…</string>
@ -35,10 +38,14 @@
<string name="sortby_date_desc">Newest date first</string>
<string name="sortby_last_modified_date_asc">Oldest addition first</string>
<string name="sortby_last_modified_date_desc">Newest addition first</string>
<string name="sortby_insertion_asc">Oldest insertion first</string>
<string name="sortby_insertion_desc">Newest insertion first</string>
<string name="sortby_number_asc">More videos</string>
<string name="sortby_number_desc">Less videos</string>
<string name="sortby_date_insertion_asc">Oldest insertion date first</string>
<string name="sortby_date_insertion_desc">Newest insertion date first</string>
<string name="sortby_date_last_modified_asc">Oldest modification date first</string>
<string name="sortby_date_last_modified_desc">Newest modification date first</string>
<string name="sortby_date_release_asc">Oldest release date first</string>
<string name="sortby_date_release_desc">Newest release date first</string>
<plurals name="search_found_results_quantity">
<item quantity="one">%d result found</item>

View File

@ -328,7 +328,7 @@ abstract class BaseBrowserTvFragment<T> : Fragment(), BrowserFragmentInterface,
val canSortByFileNameName = (viewModel as SortableModel).canSortByFileNameName()
menu.menu.findItem(R.id.ml_menu_sortby_filename).isVisible = canSortByFileNameName
menu.menu.findItem(R.id.ml_menu_sortby_length).isVisible = (viewModel as SortableModel).canSortByDuration()
menu.menu.findItem(R.id.ml_menu_sortby_insertion_date).isVisible = (viewModel as SortableModel).canSortByInsertionDate() || (viewModel as SortableModel).canSortByReleaseDate() || (viewModel as SortableModel).canSortByLastModified()
menu.menu.findItem(R.id.ml_menu_sortby_insertion_date).isVisible = (viewModel as SortableModel).canSortByInsertionDate()
menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = (viewModel as SortableModel).canSortByReleaseDate()
menu.menu.findItem(R.id.ml_menu_sortby_last_modified).isVisible = (viewModel as SortableModel).canSortByLastModified()
menu.menu.findItem(R.id.ml_menu_sortby_number).isVisible = false

View File

@ -287,7 +287,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
}
R.id.ml_menu_display_options -> {
//filter all sorts and keep only applicable ones
val sorts = arrayListOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_FILENAME, Medialibrary.SORT_ARTIST, Medialibrary.SORT_ALBUM, Medialibrary.SORT_DURATION, Medialibrary.SORT_RELEASEDATE, Medialibrary.SORT_LASTMODIFICATIONDATE, Medialibrary.SORT_FILESIZE, Medialibrary.NbMedia).filter {
val sorts = arrayListOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_FILENAME, Medialibrary.SORT_ARTIST, Medialibrary.SORT_ALBUM, Medialibrary.SORT_DURATION, Medialibrary.SORT_RELEASEDATE, Medialibrary.SORT_LASTMODIFICATIONDATE, Medialibrary.SORT_FILESIZE, Medialibrary.NbMedia, Medialibrary.SORT_INSERTIONDATE).filter {
viewModel.providers[currentTab].canSortBy(it)
}
//Open the display settings Bottom sheet

View File

@ -233,10 +233,10 @@ class DisplaySettingsDialog : VLCBottomSheetDialogFragment() {
Medialibrary.SORT_FILENAME -> getString(if (desc) R.string.sortby_filename_desc else R.string.sortby_filename_asc)
Medialibrary.SORT_ARTIST -> getString(if (desc) R.string.sortby_artist_name_desc else R.string.sortby_artist_name_asc)
Medialibrary.SORT_DURATION -> getString(if (desc) R.string.sortby_length_desc else R.string.sortby_length_asc)
Medialibrary.SORT_INSERTIONDATE -> getString(if (desc) R.string.sortby_insertion_desc else R.string.sortby_insertion_asc)
Medialibrary.SORT_LASTMODIFICATIONDATE -> getString(if (desc) R.string.sortby_last_modified_date_desc else R.string.sortby_last_modified_date_asc)
Medialibrary.SORT_INSERTIONDATE -> getString(if (desc) R.string.sortby_date_insertion_desc else R.string.sortby_date_insertion_asc)
Medialibrary.SORT_LASTMODIFICATIONDATE -> getString(if (desc) R.string.sortby_date_last_modified_desc else R.string.sortby_date_last_modified_asc)
Medialibrary.SORT_ALBUM -> getString(if (desc) R.string.sortby_album_name_desc else R.string.sortby_album_name_asc)
Medialibrary.SORT_RELEASEDATE -> getString(if (desc) R.string.sortby_date_desc else R.string.sortby_date_asc)
Medialibrary.SORT_RELEASEDATE -> getString(if (desc) R.string.sortby_date_release_desc else R.string.sortby_date_release_asc)
Medialibrary.NbMedia -> getString(if (desc) R.string.sortby_number_asc else R.string.sortby_number_desc)
else -> throw IllegalStateException("Unsupported sort: $sort")
}

View File

@ -621,9 +621,9 @@ object UiTools {
menu.appendSortOrder(provider.context, R.id.ml_menu_sortby_artist_name, R.string.sortby_artist_name, sort == Medialibrary.SORT_ARTIST, desc)
menu.appendSortOrder(provider.context, R.id.ml_menu_sortby_album_name, R.string.sortby_album_name, sort == Medialibrary.SORT_ALBUM, desc)
menu.appendSortOrder(provider.context, R.id.ml_menu_sortby_length, R.string.sortby_length, sort == Medialibrary.SORT_DURATION, desc)
menu.appendSortOrder(provider.context, R.id.ml_menu_sortby_date, R.string.sortby_date, sort == Medialibrary.SORT_RELEASEDATE, desc)
menu.appendSortOrder(provider.context,R.id.ml_menu_sortby_last_modified, R.string.sortby_last_modified_date, sort == Medialibrary.SORT_LASTMODIFICATIONDATE, desc)
menu.appendSortOrder(provider.context,R.id.ml_menu_sortby_insertion_date, R.string.sortby_insertion, sort == Medialibrary.SORT_INSERTIONDATE, desc)
menu.appendSortOrder(provider.context, R.id.ml_menu_sortby_date, R.string.sortby_date_release, sort == Medialibrary.SORT_RELEASEDATE, desc)
menu.appendSortOrder(provider.context,R.id.ml_menu_sortby_last_modified, R.string.sortby_date_last_modified, sort == Medialibrary.SORT_LASTMODIFICATIONDATE, desc)
menu.appendSortOrder(provider.context,R.id.ml_menu_sortby_insertion_date, R.string.sortby_date_insertion, sort == Medialibrary.SORT_INSERTIONDATE, desc)
// item = menu.findItem(R.id.ml_menu_sortby_number); TODO sort by track number
// if (item != null) item.setTitle(sort == Medialibrary.SORT_ && !desc ? R.string.sortby_number_desc : R.string.sortby_number);
@ -639,8 +639,8 @@ object UiTools {
menu.appendSortOrder(sortable.requireActivity(), R.id.ml_menu_sortby_artist_name, R.string.sortby_artist_name, sort == Medialibrary.SORT_ARTIST, desc)
menu.appendSortOrder(sortable.requireActivity(), R.id.ml_menu_sortby_album_name, R.string.sortby_album_name, sort == Medialibrary.SORT_ALBUM, desc)
menu.appendSortOrder(sortable.requireActivity(), R.id.ml_menu_sortby_length, R.string.sortby_length, sort == Medialibrary.SORT_DURATION, desc)
menu.appendSortOrder(sortable.requireActivity(), R.id.ml_menu_sortby_date, R.string.sortby_date, sort == Medialibrary.SORT_RELEASEDATE, desc)
menu.appendSortOrder(sortable.requireActivity(),R.id.ml_menu_sortby_last_modified, R.string.sortby_last_modified_date, sort == Medialibrary.SORT_RELEASEDATE, desc)
menu.appendSortOrder(sortable.requireActivity(), R.id.ml_menu_sortby_date, R.string.sortby_date_release, sort == Medialibrary.SORT_RELEASEDATE, desc)
menu.appendSortOrder(sortable.requireActivity(),R.id.ml_menu_sortby_last_modified, R.string.sortby_date_last_modified, sort == Medialibrary.SORT_RELEASEDATE, desc)
// item = menu.findItem(R.id.ml_menu_sortby_number); TODO sort by track number
// if (item != null) item.setTitle(sort == Medialibrary.SORT_ && !desc ? R.string.sortby_number_desc : R.string.sortby_number);

View File

@ -18,7 +18,6 @@ interface Sortable : PopupMenu.OnMenuItemClickListener {
menu.inflate(R.menu.sort_options)
menu.menu.findItem(R.id.ml_menu_sortby_filename).isVisible = vm.canSortByFileNameName()
menu.menu.findItem(R.id.ml_menu_sortby_length).isVisible = vm.canSortByDuration()
menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = vm.canSortByInsertionDate() || vm.canSortByReleaseDate() || vm.canSortByLastModified()
menu.menu.findItem(R.id.ml_menu_sortby_date).isVisible = vm.canSortByReleaseDate()
menu.menu.findItem(R.id.ml_menu_sortby_last_modified).isVisible = vm.canSortByLastModified()
menu.menu.findItem(R.id.ml_menu_sortby_number).isVisible = false

View File

@ -36,6 +36,7 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, model: So
override fun canSortByAlbum() = parent !== null && parent !is Album && parent !is Playlist
override fun canSortByLastModified() = parent !is Playlist
override fun canSortByReleaseDate() = parent !is Playlist
override fun canSortByInsertionDate() = true
override fun canSortByName() = parent !is Playlist
override fun canSortByFileNameName() = parent !is Playlist
override fun canSortByTrackId() = parent is Album

View File

@ -152,6 +152,17 @@ object ModelsHelper {
}
} else null
}
SORT_INSERTIONDATE -> {
if (item is MediaWrapper) {
val timestamp = (item as? MediaWrapper)?.insertionDate ?: 0L
val category = getTimeCategory(timestamp)
if (aboveItem == null) getTimeCategoryString(context, category)
else {
val prevCat = getTimeCategory((aboveItem as? MediaWrapper)?.insertionDate ?: -1)
if (prevCat != category) getTimeCategoryString(context, category) else null
}
} else null
}
SORT_ARTIST -> {
val artist = (item as? MediaWrapper)?.artist ?: (item as? Album)?.albumArtist ?: ""
if (aboveItem == null) artist

View File

@ -580,6 +580,10 @@ public abstract class MediaWrapper extends MediaLibraryItem implements Parcelabl
return fileName.substring(0, end);
}
public long getInsertionDate() {
return mInsertionDate;
}
public String getReferenceArtist() {
return mAlbumArtist == null ? mArtist : mAlbumArtist;
}