allow sorting by date added

This commit is contained in:
Benoît Dardenne 2020-07-10 23:11:28 +02:00 committed by dkanada
commit e8ef0b972d
10 changed files with 24 additions and 3 deletions

View file

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

View file

@ -202,6 +202,8 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
break;
case SortMethod.YEAR:
return MusicUtil.getYearString(dataSet.get(position).year);
case SortMethod.ADDED:
return "";
case SortMethod.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 ARTIST = "ARTIST";
public static final String YEAR = "YEAR";
public static final String ADDED = "ADDED";
public static final String RANDOM = "RANDOM";
}

View file

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

View file

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

View file

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

View file

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

View file

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