replace playlist song object with generic song
This commit is contained in:
parent
6592a0e0d5
commit
c873566a6c
10 changed files with 33 additions and 338 deletions
|
|
@ -21,7 +21,6 @@ import com.kabouzeid.gramophone.dialogs.DeletePlaylistDialog;
|
|||
import com.kabouzeid.gramophone.helper.menu.PlaylistMenuHelper;
|
||||
import com.kabouzeid.gramophone.helper.menu.SongsMenuHelper;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.model.playlist.AbsSmartPlaylist;
|
||||
|
|
@ -153,14 +152,6 @@ public class PlaylistAdapter extends AbsMultiSelectAdapter<PlaylistAdapter.ViewH
|
|||
@NonNull
|
||||
private List<Song> getSongList(@NonNull List<Playlist> playlists) {
|
||||
final List<Song> songs = new ArrayList<>();
|
||||
for (Playlist playlist : playlists) {
|
||||
if (playlist instanceof AbsSmartPlaylist) {
|
||||
songs.addAll(((AbsSmartPlaylist) playlist).getSongs(activity));
|
||||
} else {
|
||||
songs.addAll(PlaylistSongLoader.getPlaylistSongList(activity, playlist.id.hashCode()));
|
||||
}
|
||||
}
|
||||
|
||||
return songs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,9 @@ import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableI
|
|||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.RemoveFromPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.interfaces.CabHolder;
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.ViewUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -26,8 +24,8 @@ public class OrderablePlaylistSongAdapter extends PlaylistSongAdapter implements
|
|||
|
||||
private OnMoveItemListener onMoveItemListener;
|
||||
|
||||
public OrderablePlaylistSongAdapter(@NonNull AppCompatActivity activity, @NonNull List<PlaylistSong> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder, @Nullable OnMoveItemListener onMoveItemListener) {
|
||||
super(activity, (List<Song>) (List) dataSet, itemLayoutRes, usePalette, cabHolder);
|
||||
public OrderablePlaylistSongAdapter(@NonNull AppCompatActivity activity, @NonNull List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder, @Nullable OnMoveItemListener onMoveItemListener) {
|
||||
super(activity, (List<Song>) dataSet, itemLayoutRes, usePalette, cabHolder);
|
||||
setMultiSelectMenuRes(R.menu.menu_playlists_songs_selection);
|
||||
this.onMoveItemListener = onMoveItemListener;
|
||||
}
|
||||
|
|
@ -42,14 +40,14 @@ public class OrderablePlaylistSongAdapter extends PlaylistSongAdapter implements
|
|||
position--;
|
||||
|
||||
if (position < 0) return -2;
|
||||
return ((List<PlaylistSong>) (List) dataSet).get(position).idInPlayList; // important!
|
||||
return dataSet.get(position).id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMultipleItemAction(@NonNull MenuItem menuItem, @NonNull List<Song> selection) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.action_remove_from_playlist:
|
||||
RemoveFromPlaylistDialog.create((List<PlaylistSong>) (List) selection).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||
RemoveFromPlaylistDialog.create((List<Song>) (List) selection).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +115,7 @@ public class OrderablePlaylistSongAdapter extends PlaylistSongAdapter implements
|
|||
protected boolean onSongMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_remove_from_playlist:
|
||||
RemoveFromPlaylistDialog.create((PlaylistSong) getSong()).show(activity.getSupportFragmentManager(), "REMOVE_FROM_PLAYLIST");
|
||||
RemoveFromPlaylistDialog.create(getSong()).show(activity.getSupportFragmentManager(), "REMOVE_FROM_PLAYLIST");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import android.text.Html;
|
|||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -17,14 +17,14 @@ import java.util.List;
|
|||
public class RemoveFromPlaylistDialog extends DialogFragment {
|
||||
|
||||
@NonNull
|
||||
public static RemoveFromPlaylistDialog create(PlaylistSong song) {
|
||||
List<PlaylistSong> list = new ArrayList<>();
|
||||
public static RemoveFromPlaylistDialog create(Song song) {
|
||||
List<Song> list = new ArrayList<>();
|
||||
list.add(song);
|
||||
return create(list);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static RemoveFromPlaylistDialog create(List<PlaylistSong> songs) {
|
||||
public static RemoveFromPlaylistDialog create(List<Song> songs) {
|
||||
RemoveFromPlaylistDialog dialog = new RemoveFromPlaylistDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelableArrayList("songs", new ArrayList<>(songs));
|
||||
|
|
@ -36,7 +36,7 @@ public class RemoveFromPlaylistDialog extends DialogFragment {
|
|||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
//noinspection unchecked
|
||||
final List<PlaylistSong> songs = getArguments().getParcelableArrayList("songs");
|
||||
final List<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
int title;
|
||||
CharSequence content;
|
||||
if (songs.size() > 1) {
|
||||
|
|
@ -54,7 +54,7 @@ public class RemoveFromPlaylistDialog extends DialogFragment {
|
|||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((dialog, which) -> {
|
||||
if (getActivity() == null) return;
|
||||
PlaylistsUtil.removeFromPlaylist(getActivity(), songs);
|
||||
PlaylistsUtil.removeFromPlaylist(getActivity(), songs.get(0), songs.get(0).id);
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,21 @@
|
|||
package com.kabouzeid.gramophone.helper;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
|
@ -108,18 +97,12 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playSongAt(final int position) {
|
||||
if (musicService != null) {
|
||||
musicService.playSongAt(position);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void setPosition(final int position) {
|
||||
if (musicService != null) {
|
||||
musicService.setPosition(position);
|
||||
|
|
@ -132,27 +115,18 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playNextSong() {
|
||||
if (musicService != null) {
|
||||
musicService.playNextSong(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void playPreviousSong() {
|
||||
if (musicService != null) {
|
||||
musicService.playPreviousSong(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void back() {
|
||||
if (musicService != null) {
|
||||
musicService.back(true);
|
||||
|
|
@ -169,9 +143,6 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void openQueue(final List<Song> queue, final int startPosition, final boolean startPlaying) {
|
||||
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
|
||||
musicService.openQueue(queue, startPosition, startPlaying);
|
||||
|
|
@ -181,9 +152,6 @@ public class MusicPlayerRemote {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Async
|
||||
*/
|
||||
public static void openAndShuffleQueue(final List<Song> queue, boolean startPlaying) {
|
||||
int startPosition = 0;
|
||||
if (!queue.isEmpty()) {
|
||||
|
|
@ -203,8 +171,10 @@ public class MusicPlayerRemote {
|
|||
} else {
|
||||
setPosition(startPosition);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -292,6 +262,7 @@ public class MusicPlayerRemote {
|
|||
musicService.setShuffleMode(shuffleMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -304,9 +275,11 @@ public class MusicPlayerRemote {
|
|||
queue.add(song);
|
||||
openQueue(queue, 0, false);
|
||||
}
|
||||
|
||||
Toast.makeText(musicService, musicService.getResources().getString(R.string.added_title_to_queue), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -317,10 +290,12 @@ public class MusicPlayerRemote {
|
|||
} else {
|
||||
openQueue(songs, 0, false);
|
||||
}
|
||||
|
||||
final String toast = songs.size() == 1 ? musicService.getResources().getString(R.string.added_title_to_queue) : musicService.getResources().getString(R.string.added_x_titles_to_queue, songs.size());
|
||||
Toast.makeText(musicService, toast, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -333,9 +308,11 @@ public class MusicPlayerRemote {
|
|||
queue.add(song);
|
||||
openQueue(queue, 0, false);
|
||||
}
|
||||
|
||||
Toast.makeText(musicService, musicService.getResources().getString(R.string.added_title_to_queue), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -346,10 +323,12 @@ public class MusicPlayerRemote {
|
|||
} else {
|
||||
openQueue(songs, 0, false);
|
||||
}
|
||||
|
||||
final String toast = songs.size() == 1 ? musicService.getResources().getString(R.string.added_title_to_queue) : musicService.getResources().getString(R.string.added_x_titles_to_queue, songs.size());
|
||||
Toast.makeText(musicService, toast, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -358,6 +337,7 @@ public class MusicPlayerRemote {
|
|||
musicService.removeSong(song);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -366,6 +346,7 @@ public class MusicPlayerRemote {
|
|||
musicService.removeSong(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -374,6 +355,7 @@ public class MusicPlayerRemote {
|
|||
musicService.moveSong(from, to);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -382,96 +364,7 @@ public class MusicPlayerRemote {
|
|||
musicService.clearQueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getAudioSessionId() {
|
||||
if (musicService != null) {
|
||||
return musicService.getAudioSessionId();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void playFromUri(Uri uri) {
|
||||
if (musicService != null) {
|
||||
List<Song> songs = null;
|
||||
if (uri.getScheme() != null && uri.getAuthority() != null) {
|
||||
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
|
||||
String songId = null;
|
||||
if (uri.getAuthority().equals("com.android.providers.media.documents")) {
|
||||
songId = getSongIdFromMediaProvider(uri);
|
||||
} else if (uri.getAuthority().equals("media")) {
|
||||
songId = uri.getLastPathSegment();
|
||||
}
|
||||
if (songId != null) {
|
||||
songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
musicService,
|
||||
MediaStore.Audio.AudioColumns._ID + "=?",
|
||||
new String[]{songId}
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (songs == null) {
|
||||
File songFile = null;
|
||||
if (uri.getAuthority() != null && uri.getAuthority().equals("com.android.externalstorage.documents")) {
|
||||
songFile = new File(Environment.getExternalStorageDirectory(), uri.getPath().split(":", 2)[1]);
|
||||
}
|
||||
if (songFile == null) {
|
||||
String path = getFilePathFromUri(musicService, uri);
|
||||
if (path != null)
|
||||
songFile = new File(path);
|
||||
}
|
||||
if (songFile == null && uri.getPath() != null) {
|
||||
songFile = new File(uri.getPath());
|
||||
}
|
||||
if (songFile != null) {
|
||||
songs = SongLoader.getSongs(SongLoader.makeSongCursor(
|
||||
musicService,
|
||||
MediaStore.Audio.AudioColumns.DATA + "=?",
|
||||
new String[]{songFile.getAbsolutePath()}
|
||||
));
|
||||
}
|
||||
}
|
||||
if (songs != null && !songs.isEmpty()) {
|
||||
openQueue(songs, 0, true);
|
||||
} else {
|
||||
//TODO the file is not listed in the media store
|
||||
}
|
||||
}
|
||||
}
|
||||
@Nullable
|
||||
private static String getFilePathFromUri(Context context, Uri uri)
|
||||
{
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
final String[] projection = {
|
||||
column
|
||||
};
|
||||
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, null, null,
|
||||
null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int column_index = cursor.getColumnIndexOrThrow(column);
|
||||
return cursor.getString(column_index);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private static String getSongIdFromMediaProvider(Uri uri) {
|
||||
return DocumentsContract.getDocumentId(uri).split(":")[1];
|
||||
}
|
||||
|
||||
public static boolean isServiceConnected() {
|
||||
return musicService != null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,22 +5,15 @@ import android.content.Context;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.DeletePlaylistDialog;
|
||||
import com.kabouzeid.gramophone.dialogs.RenamePlaylistDialog;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.misc.WeakContextAsyncTask;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.model.playlist.AbsSmartPlaylist;
|
||||
import com.kabouzeid.gramophone.util.PlaylistsUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -50,9 +43,7 @@ public class PlaylistMenuHelper {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private static List<? extends Song> getPlaylistSongs(@NonNull Activity activity, Playlist playlist) {
|
||||
return playlist instanceof AbsSmartPlaylist ?
|
||||
((AbsSmartPlaylist) playlist).getSongs(activity) :
|
||||
PlaylistSongLoader.getPlaylistSongList(activity, playlist.id.hashCode());
|
||||
private static List<Song> getPlaylistSongs(@NonNull Activity activity, Playlist playlist) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
package com.kabouzeid.gramophone.loader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistSongLoader {
|
||||
|
||||
@NonNull
|
||||
public static List<PlaylistSong> getPlaylistSongList(@NonNull final Context context, final int playlistId) {
|
||||
List<PlaylistSong> songs = new ArrayList<>();
|
||||
Cursor cursor = makePlaylistSongCursor(context, playlistId);
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
songs.add(getPlaylistSongFromCursorImpl(cursor, playlistId));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return songs;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static PlaylistSong getPlaylistSongFromCursorImpl(@NonNull Cursor cursor, int playlistId) {
|
||||
final int id = cursor.getInt(0);
|
||||
final String title = cursor.getString(1);
|
||||
final int trackNumber = cursor.getInt(2);
|
||||
final int year = cursor.getInt(3);
|
||||
final long duration = cursor.getLong(4);
|
||||
final String data = cursor.getString(5);
|
||||
final int dateModified = cursor.getInt(6);
|
||||
final int albumId = cursor.getInt(7);
|
||||
final String albumName = cursor.getString(8);
|
||||
final int artistId = cursor.getInt(9);
|
||||
final String artistName = cursor.getString(10);
|
||||
final int idInPlaylist = cursor.getInt(11);
|
||||
|
||||
return new PlaylistSong(id, title, trackNumber, year, duration, data, dateModified, albumId, albumName, artistId, artistName, playlistId, idInPlaylist);
|
||||
}
|
||||
|
||||
public static Cursor makePlaylistSongCursor(@NonNull final Context context, final int playlistId) {
|
||||
try {
|
||||
return context.getContentResolver().query(
|
||||
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
|
||||
new String[]{
|
||||
MediaStore.Audio.Playlists.Members.AUDIO_ID,// 0
|
||||
AudioColumns.TITLE,// 1
|
||||
AudioColumns.TRACK,// 2
|
||||
AudioColumns.YEAR,// 3
|
||||
AudioColumns.DURATION,// 4
|
||||
AudioColumns.DATA,// 5
|
||||
AudioColumns.DATE_MODIFIED,// 6
|
||||
AudioColumns.ALBUM_ID,// 7
|
||||
AudioColumns.ALBUM,// 8
|
||||
AudioColumns.ARTIST_ID,// 9
|
||||
AudioColumns.ARTIST,// 10
|
||||
MediaStore.Audio.Playlists.Members._ID // 11
|
||||
}, SongLoader.BASE_SELECTION, null,
|
||||
MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER);
|
||||
} catch (SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package com.kabouzeid.gramophone.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
public class PlaylistSong extends Song {
|
||||
public final int playlistId;
|
||||
public final int idInPlayList;
|
||||
|
||||
public PlaylistSong(int id, String title, int trackNumber, int year, long duration, String data, int dateModified, int albumId, String albumName, int artistId, String artistName, final int playlistId, final int idInPlayList) {
|
||||
super("", title, trackNumber, year, duration, data, dateModified, "", albumName, "", artistName);
|
||||
this.playlistId = playlistId;
|
||||
this.idInPlayList = idInPlayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
PlaylistSong that = (PlaylistSong) o;
|
||||
|
||||
if (playlistId != that.playlistId) return false;
|
||||
return idInPlayList == that.idInPlayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + playlistId;
|
||||
result = 31 * result + idInPlayList;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + playlistId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
public static final Creator<PlaylistSong> CREATOR = new Creator<PlaylistSong>() {
|
||||
public PlaylistSong createFromParcel(Parcel source) {
|
||||
return new PlaylistSong(source);
|
||||
}
|
||||
|
||||
public PlaylistSong[] newArray(int size) {
|
||||
return new PlaylistSong[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kabouzeid.gramophone.provider;
|
||||
|
||||
import android.content.ContentValues;
|
||||
|
|
@ -30,11 +31,6 @@ import com.kabouzeid.gramophone.model.Song;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Andrew Neal, modified for Phonograph by Karim Abou Zeid
|
||||
* <p/>
|
||||
* This keeps track of the music playback and history state of the playback service
|
||||
*/
|
||||
public class QueueStore extends SQLiteOpenHelper {
|
||||
@Nullable
|
||||
private static QueueStore sInstance = null;
|
||||
|
|
@ -43,11 +39,6 @@ public class QueueStore extends SQLiteOpenHelper {
|
|||
public static final String ORIGINAL_PLAYING_QUEUE_TABLE_NAME = "original_playing_queue";
|
||||
private static final int VERSION = 3;
|
||||
|
||||
/**
|
||||
* Constructor of <code>MusicPlaybackState</code>
|
||||
*
|
||||
* @param context The {@link Context} to use
|
||||
*/
|
||||
public QueueStore(final Context context) {
|
||||
super(context, DATABASE_NAME, null, VERSION);
|
||||
}
|
||||
|
|
@ -59,7 +50,7 @@ public class QueueStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
private void createTable(@NonNull final SQLiteDatabase db, final String tableName) {
|
||||
//noinspection StringBufferReplaceableByString
|
||||
// noinspection StringBufferReplaceableByString
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("CREATE TABLE IF NOT EXISTS ");
|
||||
builder.append(tableName);
|
||||
|
|
@ -103,7 +94,6 @@ public class QueueStore extends SQLiteOpenHelper {
|
|||
|
||||
@Override
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
// not necessary yet
|
||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
onCreate(db);
|
||||
|
|
@ -111,21 +101,17 @@ public class QueueStore extends SQLiteOpenHelper {
|
|||
|
||||
@Override
|
||||
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// If we ever have downgrade, drop the table to be safe
|
||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context The {@link Context} to use
|
||||
* @return A new instance of this class.
|
||||
*/
|
||||
@NonNull
|
||||
public static synchronized QueueStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new QueueStore(context.getApplicationContext());
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
|
@ -134,12 +120,6 @@ public class QueueStore extends SQLiteOpenHelper {
|
|||
saveQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME, originalPlayingQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the existing database and saves the queue into the db so that when the
|
||||
* app is restarted, the tracks you were listening to is restored
|
||||
*
|
||||
* @param queue the queue to save
|
||||
*/
|
||||
private synchronized void saveQueue(final String tableName, @NonNull final List<Song> queue) {
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
database.beginTransaction();
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import com.bumptech.glide.request.animation.GlideAnimation;
|
|||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.glide.CustomGlideRequest;
|
||||
import com.kabouzeid.gramophone.model.playlist.AbsSmartPlaylist;
|
||||
import com.kabouzeid.gramophone.widgets.AppWidgetBig;
|
||||
import com.kabouzeid.gramophone.widgets.AppWidgetCard;
|
||||
import com.kabouzeid.gramophone.widgets.AppWidgetClassic;
|
||||
|
|
@ -49,7 +48,6 @@ import com.kabouzeid.gramophone.widgets.AppWidgetSmall;
|
|||
import com.kabouzeid.gramophone.glide.BlurTransformation;
|
||||
import com.kabouzeid.gramophone.helper.ShuffleHelper;
|
||||
import com.kabouzeid.gramophone.helper.StopWatch;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
import com.kabouzeid.gramophone.provider.QueueStore;
|
||||
|
|
@ -297,19 +295,10 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
Playlist playlist = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST);
|
||||
int shuffleMode = intent.getIntExtra(INTENT_EXTRA_SHUFFLE_MODE, getShuffleMode());
|
||||
if (playlist != null) {
|
||||
List<Song> playlistSongs;
|
||||
if (playlist instanceof AbsSmartPlaylist) {
|
||||
playlistSongs = ((AbsSmartPlaylist) playlist).getSongs(getApplicationContext());
|
||||
} else {
|
||||
//noinspection unchecked
|
||||
playlistSongs = (List) PlaylistSongLoader.getPlaylistSongList(getApplicationContext(), playlist.id.hashCode());
|
||||
}
|
||||
List<Song> playlistSongs = new ArrayList<>();
|
||||
if (!playlistSongs.isEmpty()) {
|
||||
if (shuffleMode == SHUFFLE_MODE_SHUFFLE) {
|
||||
int startPosition = 0;
|
||||
if (!playlistSongs.isEmpty()) {
|
||||
startPosition = new Random().nextInt(playlistSongs.size());
|
||||
}
|
||||
int startPosition = new Random().nextInt(playlistSongs.size());
|
||||
openQueue(playlistSongs, startPosition, true);
|
||||
setShuffleMode(shuffleMode);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
import com.kabouzeid.gramophone.model.PlaylistSong;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -31,9 +30,6 @@ public class PlaylistsUtil {
|
|||
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final Song song, String playlistId) {
|
||||
}
|
||||
|
||||
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final List<PlaylistSong> songs) {
|
||||
}
|
||||
|
||||
public static boolean moveItem(@NonNull final Context context, String playlistId, int from, int to) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue