store favorite and primary with queue and fix sort method references
This commit is contained in:
parent
821181d819
commit
65a311e83b
8 changed files with 73 additions and 69 deletions
|
|
@ -14,10 +14,10 @@ import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
|
||||||
*/
|
|
||||||
public class SongLoader {
|
public class SongLoader {
|
||||||
|
public static final String QUEUE_PRIMARY = "image";
|
||||||
|
public static final String QUEUE_FAVORITE = "favorite";
|
||||||
|
|
||||||
protected static final String BASE_SELECTION = AudioColumns.IS_MUSIC + "=1" + " AND " + AudioColumns.TITLE + " != ''";
|
protected static final String BASE_SELECTION = AudioColumns.IS_MUSIC + "=1" + " AND " + AudioColumns.TITLE + " != ''";
|
||||||
protected static final String[] BASE_PROJECTION = new String[]{
|
protected static final String[] BASE_PROJECTION = new String[]{
|
||||||
BaseColumns._ID,
|
BaseColumns._ID,
|
||||||
|
|
@ -29,6 +29,8 @@ public class SongLoader {
|
||||||
AudioColumns.ALBUM,
|
AudioColumns.ALBUM,
|
||||||
AudioColumns.ARTIST_ID,
|
AudioColumns.ARTIST_ID,
|
||||||
AudioColumns.ARTIST,
|
AudioColumns.ARTIST,
|
||||||
|
QUEUE_PRIMARY,
|
||||||
|
QUEUE_FAVORITE,
|
||||||
};
|
};
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -37,18 +39,6 @@ public class SongLoader {
|
||||||
return getSongs(cursor);
|
return getSongs(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static List<Song> getSongs(@NonNull final Context context, final String query) {
|
|
||||||
Cursor cursor = makeSongCursor(context, AudioColumns.TITLE + " LIKE ?", new String[]{"%" + query + "%"});
|
|
||||||
return getSongs(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static Song getSong(@NonNull final Context context, final int queryId) {
|
|
||||||
Cursor cursor = makeSongCursor(context, AudioColumns._ID + "=?", new String[]{String.valueOf(queryId)});
|
|
||||||
return getSong(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static List<Song> getSongs(@Nullable final Cursor cursor) {
|
public static List<Song> getSongs(@Nullable final Cursor cursor) {
|
||||||
List<Song> songs = new ArrayList<>();
|
List<Song> songs = new ArrayList<>();
|
||||||
|
|
@ -58,8 +48,7 @@ public class SongLoader {
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor != null)
|
if (cursor != null) cursor.close();
|
||||||
cursor.close();
|
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +82,10 @@ public class SongLoader {
|
||||||
final String artistId = cursor.getString(7);
|
final String artistId = cursor.getString(7);
|
||||||
final String artistName = cursor.getString(8);
|
final String artistName = cursor.getString(8);
|
||||||
|
|
||||||
return new Song(id, title, trackNumber, year, duration, albumId, albumName, artistId, artistName);
|
final String primary = cursor.getString(9);
|
||||||
|
final boolean favorite = Boolean.valueOf(cursor.getString(10));
|
||||||
|
|
||||||
|
return new Song(id, title, trackNumber, year, duration, albumId, albumName, artistId, artistName, primary, favorite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import android.os.Parcelable;
|
||||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||||
|
|
||||||
public class Song implements Parcelable {
|
public class Song implements Parcelable {
|
||||||
public static final Song EMPTY_SONG = new Song(null, "", -1, -1, -1, null, "", null, "");
|
public static final Song EMPTY_SONG = new Song(null, "", -1, -1, -1, null, "", null, "", null, false);
|
||||||
|
|
||||||
public final String id;
|
public final String id;
|
||||||
public final String title;
|
public final String title;
|
||||||
|
|
@ -45,7 +45,7 @@ public class Song implements Parcelable {
|
||||||
this.favorite = itemDto.getUserData() != null && itemDto.getUserData().getIsFavorite();
|
this.favorite = itemDto.getUserData() != null && itemDto.getUserData().getIsFavorite();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song(String id, String title, int trackNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName) {
|
public Song(String id, String title, int trackNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName, String primary, boolean favorite) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.trackNumber = trackNumber;
|
this.trackNumber = trackNumber;
|
||||||
|
|
@ -58,8 +58,8 @@ public class Song implements Parcelable {
|
||||||
this.artistId = artistId;
|
this.artistId = artistId;
|
||||||
this.artistName = artistName;
|
this.artistName = artistName;
|
||||||
|
|
||||||
this.primary = null;
|
this.primary = primary;
|
||||||
this.favorite = false;
|
this.favorite = favorite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public class QueueStore extends SQLiteOpenHelper {
|
||||||
public static final String DATABASE_NAME = "music_playback_state.db";
|
public static final String DATABASE_NAME = "music_playback_state.db";
|
||||||
public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue";
|
public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue";
|
||||||
public static final String ORIGINAL_PLAYING_QUEUE_TABLE_NAME = "original_playing_queue";
|
public static final String ORIGINAL_PLAYING_QUEUE_TABLE_NAME = "original_playing_queue";
|
||||||
private static final int VERSION = 4;
|
private static final int VERSION = 5;
|
||||||
|
|
||||||
public QueueStore(final Context context) {
|
public QueueStore(final Context context) {
|
||||||
super(context, DATABASE_NAME, null, VERSION);
|
super(context, DATABASE_NAME, null, VERSION);
|
||||||
|
|
@ -81,6 +81,12 @@ public class QueueStore extends SQLiteOpenHelper {
|
||||||
builder.append(" INT NOT NULL,");
|
builder.append(" INT NOT NULL,");
|
||||||
|
|
||||||
builder.append(AudioColumns.ARTIST);
|
builder.append(AudioColumns.ARTIST);
|
||||||
|
builder.append(" STRING NOT NULL,");
|
||||||
|
|
||||||
|
builder.append(SongLoader.QUEUE_PRIMARY);
|
||||||
|
builder.append(" STRING NOT NULL,");
|
||||||
|
|
||||||
|
builder.append(SongLoader.QUEUE_FAVORITE);
|
||||||
builder.append(" STRING NOT NULL);");
|
builder.append(" STRING NOT NULL);");
|
||||||
|
|
||||||
db.execSQL(builder.toString());
|
db.execSQL(builder.toString());
|
||||||
|
|
@ -143,9 +149,12 @@ public class QueueStore extends SQLiteOpenHelper {
|
||||||
values.put(AudioColumns.ALBUM, song.albumName);
|
values.put(AudioColumns.ALBUM, song.albumName);
|
||||||
values.put(AudioColumns.ARTIST_ID, song.artistId);
|
values.put(AudioColumns.ARTIST_ID, song.artistId);
|
||||||
values.put(AudioColumns.ARTIST, song.artistName);
|
values.put(AudioColumns.ARTIST, song.artistName);
|
||||||
|
values.put(SongLoader.QUEUE_PRIMARY, song.primary);
|
||||||
|
values.put(SongLoader.QUEUE_FAVORITE, song.favorite);
|
||||||
|
|
||||||
database.insert(tableName, null, values);
|
database.insert(tableName, null, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
database.setTransactionSuccessful();
|
database.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handleSortOrderMenuItem(absLibraryRecyclerViewCustomGridSizeFragment, item)) {
|
if (handleSortMethodMenuItem(absLibraryRecyclerViewCustomGridSizeFragment, item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -288,6 +288,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
||||||
gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true);
|
gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxGridSize = fragment.getMaxGridSize();
|
int maxGridSize = fragment.getMaxGridSize();
|
||||||
if (maxGridSize < 8) {
|
if (maxGridSize < 8) {
|
||||||
gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false);
|
gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false);
|
||||||
|
|
@ -348,38 +349,38 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSortMethodMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
|
private void setUpSortMethodMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortMethodMenu) {
|
||||||
String currentSortOrder = fragment.getSortMethod();
|
String currentSortMethod = fragment.getSortMethod();
|
||||||
sortOrderMenu.clear();
|
sortMethodMenu.clear();
|
||||||
|
|
||||||
if (fragment instanceof AlbumsFragment) {
|
if (fragment instanceof AlbumsFragment) {
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.NAME));
|
.setChecked(currentSortMethod.equals(SortMethod.NAME));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_artist, 1, R.string.sort_order_artist)
|
sortMethodMenu.add(0, R.id.action_sort_method_artist, 1, R.string.sort_order_artist)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.ARTIST));
|
.setChecked(currentSortMethod.equals(SortMethod.ARTIST));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_year, 2, R.string.sort_order_year)
|
sortMethodMenu.add(0, R.id.action_sort_method_year, 2, R.string.sort_order_year)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.YEAR));
|
.setChecked(currentSortMethod.equals(SortMethod.YEAR));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_random, 3, R.string.sort_order_random)
|
sortMethodMenu.add(0, R.id.action_sort_method_random, 3, R.string.sort_order_random)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.RANDOM));
|
.setChecked(currentSortMethod.equals(SortMethod.RANDOM));
|
||||||
} else if (fragment instanceof ArtistsFragment) {
|
} else if (fragment instanceof ArtistsFragment) {
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.NAME));
|
.setChecked(currentSortMethod.equals(SortMethod.NAME));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_random, 1, R.string.sort_order_random)
|
sortMethodMenu.add(0, R.id.action_sort_method_random, 1, R.string.sort_order_random)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.RANDOM));
|
.setChecked(currentSortMethod.equals(SortMethod.RANDOM));
|
||||||
} else if (fragment instanceof SongsFragment) {
|
} else if (fragment instanceof SongsFragment) {
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
sortMethodMenu.add(0, R.id.action_sort_method_name, 0, R.string.sort_order_name)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.NAME));
|
.setChecked(currentSortMethod.equals(SortMethod.NAME));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_album, 1, R.string.sort_order_album)
|
sortMethodMenu.add(0, R.id.action_sort_method_album, 1, R.string.sort_order_album)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.ALBUM));
|
.setChecked(currentSortMethod.equals(SortMethod.ALBUM));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_artist, 2, R.string.sort_order_artist)
|
sortMethodMenu.add(0, R.id.action_sort_method_artist, 2, R.string.sort_order_artist)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.ARTIST));
|
.setChecked(currentSortMethod.equals(SortMethod.ARTIST));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_year, 3, R.string.sort_order_year)
|
sortMethodMenu.add(0, R.id.action_sort_method_year, 3, R.string.sort_order_year)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.YEAR));
|
.setChecked(currentSortMethod.equals(SortMethod.YEAR));
|
||||||
sortOrderMenu.add(0, R.id.action_sort_method_random, 4, R.string.sort_order_random)
|
sortMethodMenu.add(0, R.id.action_sort_method_random, 4, R.string.sort_order_random)
|
||||||
.setChecked(currentSortOrder.equals(SortMethod.RANDOM));
|
.setChecked(currentSortMethod.equals(SortMethod.RANDOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
sortOrderMenu.setGroupCheckable(0, true, true);
|
sortMethodMenu.setGroupCheckable(0, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSortOrderMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
|
private void setUpSortOrderMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu sortOrderMenu) {
|
||||||
|
|
@ -394,29 +395,29 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
||||||
sortOrderMenu.setGroupCheckable(0, true, true);
|
sortOrderMenu.setGroupCheckable(0, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleSortOrderMenuItem(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull MenuItem item) {
|
private boolean handleSortMethodMenuItem(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull MenuItem item) {
|
||||||
String sortOrder = null;
|
String sortMethod = null;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_sort_method_name:
|
case R.id.action_sort_method_name:
|
||||||
sortOrder = SortMethod.NAME;
|
sortMethod = SortMethod.NAME;
|
||||||
break;
|
break;
|
||||||
case R.id.action_sort_method_album:
|
case R.id.action_sort_method_album:
|
||||||
sortOrder = SortMethod.ALBUM;
|
sortMethod = SortMethod.ALBUM;
|
||||||
break;
|
break;
|
||||||
case R.id.action_sort_method_artist:
|
case R.id.action_sort_method_artist:
|
||||||
sortOrder = SortMethod.ARTIST;
|
sortMethod = SortMethod.ARTIST;
|
||||||
break;
|
break;
|
||||||
case R.id.action_sort_method_year:
|
case R.id.action_sort_method_year:
|
||||||
sortOrder = SortMethod.YEAR;
|
sortMethod = SortMethod.YEAR;
|
||||||
break;
|
break;
|
||||||
case R.id.action_sort_method_random:
|
case R.id.action_sort_method_random:
|
||||||
sortOrder = SortMethod.RANDOM;
|
sortMethod = SortMethod.RANDOM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sortOrder != null) {
|
if (sortMethod != null) {
|
||||||
item.setChecked(true);
|
item.setChecked(true);
|
||||||
fragment.setAndSaveSortOrder(sortOrder);
|
fragment.setAndSaveSortMethod(sortMethod);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extend
|
||||||
setUsePalette(usePalette);
|
setUsePalette(usePalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAndSaveSortOrder(final String sortMethod) {
|
public void setAndSaveSortMethod(final String sortMethod) {
|
||||||
this.sortMethod = sortMethod;
|
this.sortMethod = sortMethod;
|
||||||
saveSortMethod(sortMethod);
|
saveSortMethod(sortMethod);
|
||||||
setSortMethod(sortMethod);
|
setSortMethod(sortMethod);
|
||||||
|
|
@ -99,6 +99,7 @@ public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extend
|
||||||
|
|
||||||
protected final void notifyLayoutResChanged(@LayoutRes int res) {
|
protected final void notifyLayoutResChanged(@LayoutRes int res) {
|
||||||
this.currentLayoutRes = res;
|
this.currentLayoutRes = res;
|
||||||
|
|
||||||
RecyclerView recyclerView = getRecyclerView();
|
RecyclerView recyclerView = getRecyclerView();
|
||||||
if (recyclerView != null) {
|
if (recyclerView != null) {
|
||||||
applyRecyclerViewPaddingForLayoutRes(recyclerView, currentLayoutRes);
|
applyRecyclerViewPaddingForLayoutRes(recyclerView, currentLayoutRes);
|
||||||
|
|
@ -118,6 +119,7 @@ public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extend
|
||||||
} else {
|
} else {
|
||||||
padding = 0;
|
padding = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView.setPadding(padding, padding, padding, padding);
|
recyclerView.setPadding(padding, padding, padding, padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,9 +141,9 @@ public abstract class AbsLibraryPagerRecyclerViewCustomGridSizeFragment<A extend
|
||||||
|
|
||||||
protected abstract String loadSortMethod();
|
protected abstract String loadSortMethod();
|
||||||
|
|
||||||
protected abstract void saveSortMethod(String sortOrder);
|
protected abstract void saveSortMethod(String sortMethod);
|
||||||
|
|
||||||
protected abstract void setSortMethod(String sortOrder);
|
protected abstract void setSortMethod(String sortMethod);
|
||||||
|
|
||||||
protected int getMaxGridSizeForList() {
|
protected int getMaxGridSizeForList() {
|
||||||
if (isLandscape()) {
|
if (isLandscape()) {
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,12 @@ public class AlbumsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFra
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveSortMethod(String sortOrder) {
|
protected void saveSortMethod(String sortMethod) {
|
||||||
PreferenceUtil.getInstance(getActivity()).setAlbumSortMethod(sortOrder);
|
PreferenceUtil.getInstance(getActivity()).setAlbumSortMethod(sortMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setSortMethod(String sortOrder) {
|
protected void setSortMethod(String sortMethod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public class ArtistsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setSortMethod(String sortOrder) {
|
protected void setSortMethod(String sortMethod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,12 @@ public class SongsFragment extends AbsLibraryPagerRecyclerViewCustomGridSizeFrag
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveSortMethod(String sortOrder) {
|
protected void saveSortMethod(String sortMethod) {
|
||||||
PreferenceUtil.getInstance(getActivity()).setSongSortMethod(sortOrder);
|
PreferenceUtil.getInstance(getActivity()).setSongSortMethod(sortMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setSortMethod(String sortOrder) {
|
protected void setSortMethod(String sortMethod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue