implement basic support for song fragment
This commit is contained in:
parent
876784495a
commit
c517718c2e
6 changed files with 55 additions and 65 deletions
|
|
@ -12,11 +12,6 @@ public class AudioFileCover {
|
|||
ImageOptions options = new ImageOptions();
|
||||
options.setImageType(ImageType.Primary);
|
||||
|
||||
try {
|
||||
this.location = App.getApiClient().GetImageUrl(item, options);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.location = "";
|
||||
}
|
||||
this.location = App.getApiClient().GetImageUrl(item, options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package com.kabouzeid.gramophone.model;
|
|||
import android.os.Parcel;
|
||||
|
||||
public class PlaylistSong extends Song {
|
||||
public static final PlaylistSong EMPTY_PLAYLIST_SONG = new PlaylistSong(-1, "", -1, -1, -1, "", -1, -1, "", -1, "", -1, -1);
|
||||
|
||||
public final int playlistId;
|
||||
public final int idInPlayList;
|
||||
|
||||
|
|
@ -24,7 +22,6 @@ public class PlaylistSong extends Song {
|
|||
|
||||
if (playlistId != that.playlistId) return false;
|
||||
return idInPlayList == that.idInPlayList;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -37,11 +34,7 @@ public class PlaylistSong extends Song {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() +
|
||||
"PlaylistSong{" +
|
||||
"playlistId=" + playlistId +
|
||||
", idInPlayList=" + idInPlayList +
|
||||
'}';
|
||||
return super.toString() + playlistId;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -53,12 +46,14 @@ public class PlaylistSong extends Song {
|
|||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
||||
dest.writeInt(this.playlistId);
|
||||
dest.writeInt(this.idInPlayList);
|
||||
}
|
||||
|
||||
protected PlaylistSong(Parcel in) {
|
||||
super(in);
|
||||
|
||||
this.playlistId = in.readInt();
|
||||
this.idInPlayList = in.readInt();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ public class Song implements Parcelable {
|
|||
public Song(BaseItemDto itemDto) {
|
||||
this.id = itemDto.getId();
|
||||
this.title = itemDto.getName();
|
||||
this.trackNumber = itemDto.getIndexNumber();
|
||||
this.year = itemDto.getProductionYear();
|
||||
this.trackNumber = itemDto.getIndexNumber() != null ? itemDto.getIndexNumber() : 0;
|
||||
this.year = itemDto.getProductionYear() != null ? itemDto.getProductionYear() : 0;
|
||||
this.duration = itemDto.getRunTimeTicks() / 10000;
|
||||
this.data = "";
|
||||
this.dateModified = 2;
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
NavigationUtil.goToArtist(AlbumDetailActivity.this, album.getArtistId());
|
||||
}
|
||||
});
|
||||
|
||||
setColors(DialogUtils.resolveColor(this, R.attr.defaultFooterColor));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,25 @@
|
|||
package com.kabouzeid.gramophone.ui.fragments.mainactivity.library.pager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.loader.content.Loader;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.adapter.song.ShuffleButtonSongAdapter;
|
||||
import com.kabouzeid.gramophone.adapter.song.SongAdapter;
|
||||
import com.kabouzeid.gramophone.interfaces.LoaderIds;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
|
||||
import com.kabouzeid.gramophone.interfaces.MediaCallback;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.gramophone.util.QueryUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager> implements LoaderManager.LoaderCallbacks<List<Song>> {
|
||||
|
||||
private static final int LOADER_ID = LoaderIds.SONGS_FRAGMENT;
|
||||
|
||||
public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager> {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getLoaderManager().initLoader(LOADER_ID, null, this);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -46,20 +36,32 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
|||
boolean usePalette = loadUsePalette();
|
||||
List<Song> dataSet = getAdapter() == null ? new ArrayList<>() : getAdapter().getDataSet();
|
||||
|
||||
SongAdapter adapter;
|
||||
if (getGridSize() <= getMaxGridSizeForList()) {
|
||||
return new ShuffleButtonSongAdapter(
|
||||
adapter = new ShuffleButtonSongAdapter(
|
||||
getLibraryFragment().getMainActivity(),
|
||||
dataSet,
|
||||
itemLayoutRes,
|
||||
usePalette,
|
||||
getLibraryFragment());
|
||||
} else {
|
||||
adapter = new SongAdapter(
|
||||
getLibraryFragment().getMainActivity(),
|
||||
dataSet,
|
||||
itemLayoutRes,
|
||||
usePalette,
|
||||
getLibraryFragment());
|
||||
}
|
||||
return new SongAdapter(
|
||||
getLibraryFragment().getMainActivity(),
|
||||
dataSet,
|
||||
itemLayoutRes,
|
||||
usePalette,
|
||||
getLibraryFragment());
|
||||
|
||||
QueryUtil.getSongs(new MediaCallback() {
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
dataSet.addAll((Collection<Song>) media);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -69,7 +71,7 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
|||
|
||||
@Override
|
||||
public void onMediaStoreChanged() {
|
||||
getLoaderManager().restartLoader(LOADER_ID, null, this);
|
||||
super.onMediaStoreChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -84,7 +86,6 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
|||
|
||||
@Override
|
||||
protected void setSortOrder(String sortOrder) {
|
||||
getLoaderManager().restartLoader(LOADER_ID, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -127,30 +128,4 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
|||
getLayoutManager().setSpanCount(gridSize);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<List<Song>> onCreateLoader(int id, Bundle args) {
|
||||
return new AsyncSongLoader(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<Song>> loader, List<Song> data) {
|
||||
getAdapter().swapDataSet(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<List<Song>> loader) {
|
||||
getAdapter().swapDataSet(new ArrayList<>());
|
||||
}
|
||||
|
||||
private static class AsyncSongLoader extends WrappedAsyncTaskLoader<List<Song>> {
|
||||
public AsyncSongLoader(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Song> loadInBackground() {
|
||||
return SongLoader.getAllSongs(getContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,30 @@ public class QueryUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void getSongs(MediaCallback callback) {
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setIncludeItemTypes(new String[]{"Audio"});
|
||||
query.setUserId(App.getApiClient().getCurrentUserId());
|
||||
query.setRecursive(true);
|
||||
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"});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue