load songs on album details activity
This commit is contained in:
parent
ef0f5e500a
commit
422aab0334
4 changed files with 52 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class Album implements Parcelable {
|
||||
public final List<Song> songs;
|
||||
public List<Song> songs;
|
||||
|
||||
public String id;
|
||||
public String title;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.kabouzeid.gramophone.model;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
|
@ -21,6 +23,20 @@ public class Song implements Parcelable {
|
|||
public final String artistId;
|
||||
public final String artistName;
|
||||
|
||||
public Song(BaseItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.title = itemDto.getName();
|
||||
this.trackNumber = itemDto.getIndexNumber();
|
||||
this.year = itemDto.getProductionYear();
|
||||
this.duration = itemDto.getRunTimeTicks();
|
||||
this.data = "";
|
||||
this.dateModified = 2;
|
||||
this.albumId = itemDto.getAlbumId();
|
||||
this.albumName = itemDto.getAlbum();
|
||||
this.artistId = itemDto.getAlbumArtists().get(0).getId();
|
||||
this.artistName = itemDto.getAlbumArtists().get(0).getName();
|
||||
}
|
||||
|
||||
public Song(String id, String title, int trackNumber, int year, long duration, String data, long dateModified, String albumId, String albumName, String artistId, String artistName) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.kabouzeid.gramophone.glide.CustomPaletteTarget;
|
|||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.interfaces.MediaCallback;
|
||||
import com.kabouzeid.gramophone.interfaces.PaletteColorHolder;
|
||||
import com.kabouzeid.gramophone.misc.SimpleObservableScrollViewCallbacks;
|
||||
|
|
@ -96,7 +95,16 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
QueryUtil.getAlbum(getIntent().getExtras().getString(EXTRA_ALBUM_ID), new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
setAlbum((Album) media.get(0));
|
||||
Album album = (Album) media.get(0);
|
||||
|
||||
setAlbum(album);
|
||||
QueryUtil.getSongs(album.id, new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
album.songs = (List<Song>) media;
|
||||
setAlbum(album);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.kabouzeid.gramophone.App;
|
|||
import com.kabouzeid.gramophone.interfaces.MediaCallback;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
|
@ -54,6 +55,30 @@ public class QueryUtil {
|
|||
});
|
||||
}
|
||||
|
||||
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);
|
||||
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 getArtists(MediaCallback callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setIncludeItemTypes(new String[]{"MusicArtist"});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue