fix launcher shortcuts and shuffle button
This commit is contained in:
parent
3d40db2675
commit
d5f8d54199
11 changed files with 85 additions and 9 deletions
|
|
@ -229,6 +229,9 @@ public class QueryUtil {
|
|||
case SortMethod.RANDOM:
|
||||
query.setSortBy(new String[]{"Random"});
|
||||
break;
|
||||
case SortMethod.COUNT:
|
||||
query.setSortBy(new String[]{"PlayCount"});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package com.dkanada.gramophone.util;
|
||||
|
||||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.helper.sort.SortMethod;
|
||||
import com.dkanada.gramophone.helper.sort.SortOrder;
|
||||
import com.dkanada.gramophone.interfaces.MediaCallback;
|
||||
import com.dkanada.gramophone.model.Song;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
import org.jellyfin.apiclient.model.querying.ItemFields;
|
||||
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||
import org.jellyfin.apiclient.model.querying.ItemsResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ShortcutUtil {
|
||||
public static void getFrequent(MediaCallback<Song> callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
|
||||
QueryUtil.applySortMethod(query, SortMethod.COUNT);
|
||||
QueryUtil.applySortOrder(query, SortOrder.DESCENDING);
|
||||
|
||||
getSongs(query, callback);
|
||||
}
|
||||
|
||||
public static void getLatest(MediaCallback<Song> callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
|
||||
QueryUtil.applySortMethod(query, SortMethod.ADDED);
|
||||
QueryUtil.applySortOrder(query, SortOrder.DESCENDING);
|
||||
|
||||
getSongs(query, callback);
|
||||
}
|
||||
|
||||
public static void getShuffle(MediaCallback<Song> callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
|
||||
QueryUtil.applySortMethod(query, SortMethod.RANDOM);
|
||||
QueryUtil.applySortOrder(query, SortOrder.DESCENDING);
|
||||
|
||||
getSongs(query, callback);
|
||||
}
|
||||
|
||||
public static void getSongs(ItemQuery query, MediaCallback<Song> callback) {
|
||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
||||
query.setFields(new ItemFields[]{ItemFields.MediaSources});
|
||||
|
||||
query.setLimit(200);
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
|
||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult result) {
|
||||
List<Song> songs = new ArrayList<>();
|
||||
for (BaseItemDto itemDto : result.getItems()) {
|
||||
songs.add(new Song(itemDto));
|
||||
}
|
||||
|
||||
callback.onLoadMedia(songs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue