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