sort songs by track number in album view and refactor query utils
This commit is contained in:
parent
a0e8db7f75
commit
3517e145a6
5 changed files with 38 additions and 59 deletions
|
|
@ -38,6 +38,8 @@ import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||||
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||||
|
|
||||||
|
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
|
|
@ -96,9 +98,13 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
Album album = (Album) media.get(0);
|
Album album = (Album) media.get(0);
|
||||||
|
|
||||||
setAlbum(album);
|
setAlbum(album);
|
||||||
QueryUtil.getSongs(album.id, new MediaCallback() {
|
|
||||||
|
ItemQuery query = new ItemQuery();
|
||||||
|
query.setParentId(album.id);
|
||||||
|
query.setSortBy(new String[]{"IndexNumber"});
|
||||||
|
|
||||||
|
QueryUtil.getSongs(query, new MediaCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
album.songs = (List<Song>) media;
|
album.songs = (List<Song>) media;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ import com.kabouzeid.gramophone.util.PhonographColorUtil;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||||
|
|
||||||
|
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||||
|
|
||||||
public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implements PaletteColorHolder, CabHolder {
|
public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implements PaletteColorHolder, CabHolder {
|
||||||
public static final String EXTRA_ARTIST_ID = "extra_artist_id";
|
public static final String EXTRA_ARTIST_ID = "extra_artist_id";
|
||||||
|
|
||||||
|
|
@ -116,11 +118,28 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
Artist artist = (Artist) media.get(0);
|
Artist artist = (Artist) media.get(0);
|
||||||
QueryUtil.getAlbums(artist.id, new MediaCallback() {
|
|
||||||
|
ItemQuery query = new ItemQuery();
|
||||||
|
query.setArtistIds(new String[]{artist.id});
|
||||||
|
|
||||||
|
QueryUtil.getAlbums(query, new MediaCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
artist.albums = (List<Album>) media;
|
artist.albums = (List<Album>) media;
|
||||||
setArtist(artist);
|
setArtist(artist);
|
||||||
|
|
||||||
|
QueryUtil.getSongs(query, new MediaCallback() {
|
||||||
|
@Override
|
||||||
|
public void onLoadMedia(List<?> media) {
|
||||||
|
for (Album album : artist.albums) {
|
||||||
|
for (Song song : (List<Song>) media) {
|
||||||
|
if (song.albumId.equals(album.id)) album.songs.add(song);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setArtist(artist);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import com.kabouzeid.gramophone.model.Album;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||||
|
|
||||||
|
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -36,7 +38,7 @@ public class AlbumsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFra
|
||||||
List<Album> dataSet = getAdapter() == null ? new ArrayList<>() : getAdapter().getDataSet();
|
List<Album> dataSet = getAdapter() == null ? new ArrayList<>() : getAdapter().getDataSet();
|
||||||
|
|
||||||
AlbumAdapter adapter = new AlbumAdapter(getLibraryFragment().getMainActivity(), dataSet, itemLayoutRes, loadUsePalette(), getLibraryFragment());
|
AlbumAdapter adapter = new AlbumAdapter(getLibraryFragment().getMainActivity(), dataSet, itemLayoutRes, loadUsePalette(), getLibraryFragment());
|
||||||
QueryUtil.getAlbums(new MediaCallback() {
|
QueryUtil.getAlbums(new ItemQuery(), new MediaCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
dataSet.addAll((Collection<Album>) media);
|
dataSet.addAll((Collection<Album>) media);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||||
|
|
||||||
|
import org.jellyfin.apiclient.model.querying.ItemQuery;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -53,7 +55,7 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
||||||
getLibraryFragment());
|
getLibraryFragment());
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryUtil.getSongs(new MediaCallback() {
|
QueryUtil.getSongs(new ItemQuery(), new MediaCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadMedia(List<?> media) {
|
public void onLoadMedia(List<?> media) {
|
||||||
dataSet.addAll((Collection<Song>) media);
|
dataSet.addAll((Collection<Song>) media);
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,10 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class QueryUtil {
|
public class QueryUtil {
|
||||||
public static void getAlbums(MediaCallback callback) {
|
public static void getAlbums(ItemQuery query, MediaCallback callback) {
|
||||||
ItemQuery query = new ItemQuery();
|
|
||||||
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
||||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||||
query.setLimit(10);
|
query.setLimit(100);
|
||||||
query.setRecursive(true);
|
query.setRecursive(true);
|
||||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -56,59 +55,10 @@ public class QueryUtil {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getAlbums(String id, MediaCallback callback) {
|
public static void getSongs(ItemQuery query, MediaCallback callback) {
|
||||||
ItemQuery query = new ItemQuery();
|
|
||||||
query.setIncludeItemTypes(new String[]{"MusicAlbum"});
|
|
||||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
|
||||||
query.setArtistIds(new String[]{id});
|
|
||||||
query.setRecursive(true);
|
|
||||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(ItemsResult result) {
|
|
||||||
List<Album> albums = new ArrayList<>();
|
|
||||||
for (BaseItemDto itemDto : result.getItems()) {
|
|
||||||
albums.add(new Album(itemDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.onLoadMedia(albums);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Exception exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void getSongs(MediaCallback callback) {
|
|
||||||
ItemQuery query = new ItemQuery();
|
|
||||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
query.setIncludeItemTypes(new String[]{"Audio"});
|
||||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||||
query.setRecursive(true);
|
|
||||||
query.setLimit(100);
|
query.setLimit(100);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void getSongs(String album, MediaCallback callback) {
|
|
||||||
ItemQuery query = new ItemQuery();
|
|
||||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
|
||||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
|
||||||
query.setParentId(album);
|
|
||||||
query.setRecursive(true);
|
query.setRecursive(true);
|
||||||
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
App.getApiClient().GetItemsAsync(query, new Response<ItemsResult>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -131,7 +81,7 @@ public class QueryUtil {
|
||||||
public static void getArtists(MediaCallback callback) {
|
public static void getArtists(MediaCallback callback) {
|
||||||
ArtistsQuery query = new ArtistsQuery();
|
ArtistsQuery query = new ArtistsQuery();
|
||||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||||
query.setLimit(10);
|
query.setLimit(100);
|
||||||
query.setRecursive(true);
|
query.setRecursive(true);
|
||||||
App.getApiClient().GetAlbumArtistsAsync(query, new Response<ItemsResult>() {
|
App.getApiClient().GetAlbumArtistsAsync(query, new Response<ItemsResult>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue