Merge pull request #45 from bendardenne/sort-by-added

#22 Allow sorting by date added
This commit is contained in:
dkanada 2020-07-17 07:24:40 +09:00 committed by GitHub
commit 7b9e03e5f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 24 additions and 3 deletions

View file

@ -197,6 +197,8 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
break; break;
case SortMethod.YEAR: case SortMethod.YEAR:
return MusicUtil.getYearString(dataSet.get(position).year); return MusicUtil.getYearString(dataSet.get(position).year);
case SortMethod.ADDED:
return "";
case SortMethod.RANDOM: case SortMethod.RANDOM:
return activity.getResources().getString(R.string.random); return activity.getResources().getString(R.string.random);
} }

View file

@ -202,6 +202,8 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
break; break;
case SortMethod.YEAR: case SortMethod.YEAR:
return MusicUtil.getYearString(dataSet.get(position).year); return MusicUtil.getYearString(dataSet.get(position).year);
case SortMethod.ADDED:
return "";
case SortMethod.RANDOM: case SortMethod.RANDOM:
return activity.getResources().getString(R.string.random); return activity.getResources().getString(R.string.random);
} }

View file

@ -5,5 +5,6 @@ public class SortMethod {
public static final String ALBUM = "ALBUM"; public static final String ALBUM = "ALBUM";
public static final String ARTIST = "ARTIST"; public static final String ARTIST = "ARTIST";
public static final String YEAR = "YEAR"; public static final String YEAR = "YEAR";
public static final String ADDED = "ADDED";
public static final String RANDOM = "RANDOM"; public static final String RANDOM = "RANDOM";
} }

View file

@ -368,7 +368,9 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
.setChecked(currentSortMethod.equals(SortMethod.ARTIST)); .setChecked(currentSortMethod.equals(SortMethod.ARTIST));
sortMethodMenu.add(0, R.id.action_sort_method_year, 2, R.string.sort_method_year) sortMethodMenu.add(0, R.id.action_sort_method_year, 2, R.string.sort_method_year)
.setChecked(currentSortMethod.equals(SortMethod.YEAR)); .setChecked(currentSortMethod.equals(SortMethod.YEAR));
sortMethodMenu.add(0, R.id.action_sort_method_random, 3, R.string.sort_method_random) 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)); .setChecked(currentSortMethod.equals(SortMethod.RANDOM));
} else if (fragment instanceof SongsFragment) { } else if (fragment instanceof SongsFragment) {
sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_method_name) sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_method_name)
@ -379,7 +381,9 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
.setChecked(currentSortMethod.equals(SortMethod.ARTIST)); .setChecked(currentSortMethod.equals(SortMethod.ARTIST));
sortMethodMenu.add(0, R.id.action_sort_method_year, 3, R.string.sort_method_year) sortMethodMenu.add(0, R.id.action_sort_method_year, 3, R.string.sort_method_year)
.setChecked(currentSortMethod.equals(SortMethod.YEAR)); .setChecked(currentSortMethod.equals(SortMethod.YEAR));
sortMethodMenu.add(0, R.id.action_sort_method_random, 4, R.string.sort_method_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)); .setChecked(currentSortMethod.equals(SortMethod.RANDOM));
} }
@ -413,6 +417,9 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
case R.id.action_sort_method_year: case R.id.action_sort_method_year:
sortMethod = SortMethod.YEAR; sortMethod = SortMethod.YEAR;
break; break;
case R.id.action_sort_method_added:
sortMethod = SortMethod.ADDED;
break;
case R.id.action_sort_method_random: case R.id.action_sort_method_random:
sortMethod = SortMethod.RANDOM; sortMethod = SortMethod.RANDOM;
break; break;

View file

@ -82,6 +82,7 @@ public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extend
this.sortMethod = sortMethod; this.sortMethod = sortMethod;
saveSortMethod(sortMethod); saveSortMethod(sortMethod);
setSortMethod(sortMethod); setSortMethod(sortMethod);
invalidateAdapter();
} }
public boolean canUsePalette() { public boolean canUsePalette() {

View file

@ -38,6 +38,7 @@ public class AlbumsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFra
QueryUtil.getAlbums(new ItemQuery(), new MediaCallback() { QueryUtil.getAlbums(new ItemQuery(), new MediaCallback() {
@Override @Override
public void onLoadMedia(List<?> media) { public void onLoadMedia(List<?> media) {
dataSet.clear();
dataSet.addAll((Collection<Album>) media); dataSet.addAll((Collection<Album>) media);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }

View file

@ -58,6 +58,7 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
QueryUtil.getSongs(new ItemQuery(), new MediaCallback() { QueryUtil.getSongs(new ItemQuery(), new MediaCallback() {
@Override @Override
public void onLoadMedia(List<?> media) { public void onLoadMedia(List<?> media) {
dataSet.clear();
dataSet.addAll((Collection<Song>) media); dataSet.addAll((Collection<Song>) media);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }

View file

@ -12,6 +12,7 @@ import com.dkanada.gramophone.model.Song;
import org.jellyfin.apiclient.interaction.Response; import org.jellyfin.apiclient.interaction.Response;
import org.jellyfin.apiclient.model.dto.BaseItemDto; import org.jellyfin.apiclient.model.dto.BaseItemDto;
import org.jellyfin.apiclient.model.dto.BaseItemType; import org.jellyfin.apiclient.model.dto.BaseItemType;
import org.jellyfin.apiclient.model.entities.SortOrder;
import org.jellyfin.apiclient.model.querying.ArtistsQuery; import org.jellyfin.apiclient.model.querying.ArtistsQuery;
import org.jellyfin.apiclient.model.querying.ItemFields; import org.jellyfin.apiclient.model.querying.ItemFields;
import org.jellyfin.apiclient.model.querying.ItemQuery; import org.jellyfin.apiclient.model.querying.ItemQuery;
@ -221,6 +222,9 @@ public class QueryUtil {
case SortMethod.YEAR: case SortMethod.YEAR:
query.setSortBy(new String[]{"ProductionYear"}); query.setSortBy(new String[]{"ProductionYear"});
break; break;
case SortMethod.ADDED:
query.setSortBy(new String[]{"DateCreated"});
break;
case SortMethod.RANDOM: case SortMethod.RANDOM:
query.setSortBy(new String[]{"Random"}); query.setSortBy(new String[]{"Random"});
break; break;

View file

@ -10,8 +10,9 @@
<item name="action_sort_method_album" type="id" /> <item name="action_sort_method_album" type="id" />
<item name="action_sort_method_artist" type="id" /> <item name="action_sort_method_artist" type="id" />
<item name="action_sort_method_year" type="id" /> <item name="action_sort_method_year" type="id" />
<item name="action_sort_method_added" type="id" />
<item name="action_sort_method_random" type="id" /> <item name="action_sort_method_random" type="id" />
<item name="action_multi_select_adapter_check_all" type="id" /> <item name="action_multi_select_adapter_check_all" type="id" />
</resources> </resources>

View file

@ -208,6 +208,7 @@
<string name="sort_method_artist">Artist</string> <string name="sort_method_artist">Artist</string>
<string name="sort_method_album">Album</string> <string name="sort_method_album">Album</string>
<string name="sort_method_year">Year</string> <string name="sort_method_year">Year</string>
<string name="sort_method_added">Added</string>
<string name="sort_method_random">Random</string> <string name="sort_method_random">Random</string>
<string name="finish_current_music_sleep_timer">Finish last song</string> <string name="finish_current_music_sleep_timer">Finish last song</string>