Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ItemSortBy constants instead of hardcoded strings #1564

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jellyfin.androidtv.databinding.DreamLibraryBinding
import org.jellyfin.androidtv.di.systemApiClient
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.ClockBehavior
import org.jellyfin.apiclient.model.querying.ItemSortBy
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.exception.ApiClientException
import org.jellyfin.sdk.api.client.extensions.imageApi
Expand Down Expand Up @@ -78,7 +79,7 @@ class LibraryDreamService : DreamService() {
val response by api.itemsApi.getItemsByUserId(
includeItemTypes = listOf("Movie", "Series"),
recursive = true,
sortBy = listOf("Random"),
sortBy = listOf(ItemSortBy.Random),
limit = 1,
imageTypes = listOf(ImageType.BACKDROP)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jellyfin.androidtv.constant.GridDirection
import org.jellyfin.androidtv.constant.ImageType
import org.jellyfin.androidtv.constant.PosterSize
import org.jellyfin.apiclient.model.entities.SortOrder
import org.jellyfin.apiclient.model.querying.ItemSortBy
import org.jellyfin.sdk.api.client.ApiClient

class LibraryPreferences(
Expand All @@ -24,7 +25,7 @@ class LibraryPreferences(
val filterUnwatchedOnly = Preference.boolean("FilterUnwatchedOnly", false)

// Item sorting
val sortBy = Preference.string("SortBy", "SortName")
val sortBy = Preference.string("SortBy", ItemSortBy.SortName)
val sortOrder = Preference.enum("SortOrder", SortOrder.Ascending)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jellyfin.androidtv.preference

import org.jellyfin.apiclient.model.querying.ItemSortBy
import org.jellyfin.sdk.api.client.ApiClient

class LiveTvPreferences(
Expand All @@ -9,7 +10,7 @@ class LiveTvPreferences(
api = api,
) {
companion object {
val channelOrder = Preference.string("livetv-channelorder", "DatePlayed")
val channelOrder = Preference.string("livetv-channelorder", ItemSortBy.DatePlayed)
val colorCodeGuide = Preference.boolean("guide-colorcodedbackgrounds", false)
val favsAtTop = Preference.boolean("livetv-favoritechannelsattop", true)
val showHDIndicator = Preference.boolean("guide-indicator-hd", false)
Expand Down
15 changes: 8 additions & 7 deletions app/src/main/java/org/jellyfin/androidtv/ui/GridFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jellyfin.androidtv.util.InfoLayoutHelper;
import org.jellyfin.androidtv.util.Utils;
import org.jellyfin.apiclient.model.entities.SortOrder;
import org.jellyfin.apiclient.model.querying.ItemSortBy;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -95,13 +96,13 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

sortOptions = new HashMap<>();
{
sortOptions.put(0, new SortOption(getString(R.string.lbl_name), "SortName", SortOrder.Ascending));
sortOptions.put(1, new SortOption(getString(R.string.lbl_date_added), "DateCreated,SortName", SortOrder.Descending));
sortOptions.put(2, new SortOption(getString(R.string.lbl_premier_date), "PremiereDate,SortName", SortOrder.Descending));
sortOptions.put(3, new SortOption(getString(R.string.lbl_rating), "OfficialRating,SortName", SortOrder.Ascending));
sortOptions.put(4, new SortOption(getString(R.string.lbl_community_rating), "CommunityRating,SortName", SortOrder.Descending));
sortOptions.put(5,new SortOption(getString(R.string.lbl_critic_rating), "CriticRating,SortName", SortOrder.Descending));
sortOptions.put(6, new SortOption(getString(R.string.lbl_last_played), "DatePlayed,SortName", SortOrder.Descending));
sortOptions.put(0, new SortOption(getString(R.string.lbl_name), ItemSortBy.SortName, SortOrder.Ascending));
sortOptions.put(1, new SortOption(getString(R.string.lbl_date_added), ItemSortBy.DateCreated + "," + ItemSortBy.SortName, SortOrder.Descending));
sortOptions.put(2, new SortOption(getString(R.string.lbl_premier_date), ItemSortBy.PremiereDate + "," + ItemSortBy.SortName, SortOrder.Descending));
sortOptions.put(3, new SortOption(getString(R.string.lbl_rating), ItemSortBy.OfficialRating + "," + ItemSortBy.SortName, SortOrder.Ascending));
sortOptions.put(4, new SortOption(getString(R.string.lbl_community_rating), ItemSortBy.CommunityRating + "," + ItemSortBy.SortName, SortOrder.Descending));
sortOptions.put(5,new SortOption(getString(R.string.lbl_critic_rating), ItemSortBy.CriticRating + "," + ItemSortBy.SortName, SortOrder.Descending));
sortOptions.put(6, new SortOption(getString(R.string.lbl_last_played), ItemSortBy.DatePlayed + "," + ItemSortBy.SortName, SortOrder.Descending));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.jellyfin.apiclient.interaction.EmptyResponse;
import org.jellyfin.apiclient.model.dto.BaseItemType;
import org.jellyfin.apiclient.model.entities.CollectionType;
import org.jellyfin.apiclient.model.querying.ItemSortBy;
import org.jellyfin.sdk.model.api.BaseItemDto;

import java.util.UUID;
Expand Down Expand Up @@ -558,7 +559,7 @@ protected void setupRetrieveListeners() {
public void onResponse() {
setStatusText(mFolder.getName());
updateCounter(mGridAdapter.getTotalItems() > 0 ? 1 : 0);
mLetterButton.setVisibility("SortName".equals(mGridAdapter.getSortBy()) ? View.VISIBLE : View.GONE);
mLetterButton.setVisibility(ItemSortBy.SortName.equals(mGridAdapter.getSortBy()) ? View.VISIBLE : View.GONE);
setItem(null);
if (mGridAdapter.getTotalItems() == 0) {
mToolBar.requestFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.jellyfin.apiclient.model.querying.ArtistsQuery;
import org.jellyfin.apiclient.model.querying.ItemFields;
import org.jellyfin.apiclient.model.querying.ItemQuery;
import org.jellyfin.apiclient.model.querying.ItemSortBy;
import org.jellyfin.apiclient.model.querying.ItemsResult;
import org.jellyfin.apiclient.model.querying.LatestItemsQuery;
import org.jellyfin.apiclient.model.querying.NextUpQuery;
Expand Down Expand Up @@ -397,7 +398,7 @@ public void setSortBy(GridFragment.SortOption option) {
mQuery.setSortOrder(option.order);
break;
}
if (!"SortName".equals(option.value)) {
if (!ItemSortBy.SortName.equals(option.value)) {
setStartLetter(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.jellyfin.apiclient.model.dto.BaseItemDto;
import org.jellyfin.apiclient.model.dto.UserItemDataDto;
import org.jellyfin.apiclient.model.livetv.ChannelInfoDto;
import org.jellyfin.apiclient.model.querying.ItemSortBy;
import org.koin.java.KoinJavaComponent;

import java.util.ArrayList;
Expand Down Expand Up @@ -615,7 +616,7 @@ public void onClick(View v) {
mSortBy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mCurrentSort = position == 0 ? "DatePlayed" : "Number";
mCurrentSort = position == 0 ? ItemSortBy.DatePlayed : ItemSortBy.SortName;
}

@Override
Expand All @@ -641,7 +642,7 @@ public void show() {
mRepeat.setChecked(prefs.get(LiveTvPreferences.Companion.getShowRepeatIndicator()));
mColorCode.setChecked(prefs.get(LiveTvPreferences.Companion.getColorCodeGuide()));
mPremiere.setChecked(prefs.get(LiveTvPreferences.Companion.getShowPremiereIndicator()));
mSortBy.setSelection(prefs.get(LiveTvPreferences.Companion.getChannelOrder()).equals("DatePlayed") ? 0 : 1);
mSortBy.setSelection(prefs.get(LiveTvPreferences.Companion.getChannelOrder()).equals(ItemSortBy.DatePlayed) ? 0 : 1);

mPopup.showAtLocation(mTimelineScroller, Gravity.NO_GRAVITY, mTimelineScroller.getRight(), mSummary.getTop()-20);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jellyfin.apiclient.model.livetv.ProgramQuery;
import org.jellyfin.apiclient.model.livetv.TimerInfoDto;
import org.jellyfin.apiclient.model.livetv.TimerQuery;
import org.jellyfin.apiclient.model.querying.ItemSortBy;
import org.jellyfin.apiclient.model.querying.ItemsResult;
import org.jellyfin.apiclient.model.results.ChannelInfoDtoResult;
import org.jellyfin.apiclient.model.results.TimerInfoDtoResult;
Expand Down Expand Up @@ -130,8 +131,8 @@ private static void loadAllChannelsInternal(final Response<Integer> outerRespons
query.setUserId(TvApp.getApplication().getCurrentUser().getId());
query.setAddCurrentProgram(true);
if (liveTvPreferences.get(LiveTvPreferences.Companion.getFavsAtTop())) query.setEnableFavoriteSorting(true);
query.setSortOrder("DatePlayed".equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder())) ? SortOrder.Descending : null);
query.setSortBy(new String[] {"DatePlayed".equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder())) ? "DatePlayed" : "SortName"});
query.setSortOrder(ItemSortBy.DatePlayed.equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder())) ? SortOrder.Descending : null);
query.setSortBy(new String[] {ItemSortBy.DatePlayed.equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder())) ? ItemSortBy.DatePlayed : ItemSortBy.SortName});
Timber.d("*** About to load channels");
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetLiveTvChannelsAsync(query, new Response<ChannelInfoDtoResult>() {
@Override
Expand Down Expand Up @@ -169,7 +170,7 @@ public static int sortChannels() {
int ndx = 0;
if (allChannels != null) {
//Sort by last played - if selected
if ("DatePlayed".equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder()))) {
if (ItemSortBy.DatePlayed.equals(liveTvPreferences.get(LiveTvPreferences.Companion.getChannelOrder()))) {
Collections.sort(allChannels, Collections.reverseOrder(new Comparator<ChannelInfoDto>() {
@Override
public int compare(ChannelInfoDto lhs, ChannelInfoDto rhs) {
Expand Down Expand Up @@ -210,7 +211,7 @@ public static void getProgramsAsync(int startNdx, int endNdx, final Calendar sta
endNdx = endNdx > channelIds.length ? channelIds.length : endNdx+1; //array copy range final ndx is exclusive
query.setChannelIds(Arrays.copyOfRange(channelIds, startNdx, endNdx));
query.setEnableImages(false);
query.setSortBy(new String[] {"StartDate"});
query.setSortBy(new String[] {ItemSortBy.StartDate});
Calendar end = (Calendar) endTime.clone();
end.setTimeZone(TimeZone.getTimeZone("Z"));
end.add(Calendar.SECOND, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jellyfin.apiclient.model.dto.UserItemDataDto;
import org.jellyfin.apiclient.model.entities.SortOrder;
import org.jellyfin.apiclient.model.querying.ItemFilter;
import org.jellyfin.apiclient.model.querying.ItemSortBy;
import org.jellyfin.apiclient.model.querying.ItemsResult;
import org.koin.java.KoinJavaComponent;

Expand Down Expand Up @@ -375,7 +376,7 @@ public void onError(Exception exception) {
query.setRecursive(true);
query.setIsVirtualUnaired(false);
query.setIsMissing(false);
query.setSortBy(new String[]{"SortName"});
query.setSortBy(new String[]{ItemSortBy.SortName});
query.setSortOrder(SortOrder.Ascending);
query.setLimit(1);
query.setExcludeItemTypes(new String[] {"Series","Season","Folder","MusicAlbum","Playlist","BoxSet"});
Expand Down