Skip to content

Commit

Permalink
added folder song sort order, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Jul 27, 2024
1 parent ca6d000 commit 06d6230
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected void onDestroy() {
public boolean onPrepareOptionsMenu(Menu menu) {
// Theme the add to home screen icon
MenuItem shuffle = menu.findItem(R.id.menu_shuffle);
if (type == Type.FAVORITE || type == Type.LAST_ADDED || type == Type.PLAYLIST || type == Type.POPULAR) {
if (type == Type.FAVORITE || type == Type.LAST_ADDED || type == Type.PLAYLIST || type == Type.POPULAR || type == Type.FOLDER) {
shuffle.setTitle(R.string.menu_play_all);
} else {
shuffle.setTitle(R.string.menu_shuffle);
Expand Down Expand Up @@ -360,6 +360,8 @@ public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.album_song_sort_by, menu);
} else if (type == Type.POPULAR) {
getMenuInflater().inflate(R.menu.popular_songs_clear, menu);
} else if (type == Type.FOLDER) {
getMenuInflater().inflate(R.menu.folder_songs_sort_by, menu);
}
return true;
}
Expand Down Expand Up @@ -441,6 +443,8 @@ else if (item.getItemId() == R.id.menu_sort_by_az) {
if (mViewPager.getCurrentItem() == ProfileAdapter.IDX_ALBUM_SONG) {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_A_Z);
}
} else if (type == Type.FOLDER) {
mPreferences.setFolderSongSortOrder(SortOrder.FolderSongSortOrder.SONG_A_Z);
}
viewModel.notify(ProfileFragment.REFRESH);
}
Expand All @@ -456,6 +460,8 @@ else if (item.getItemId() == R.id.menu_sort_by_za) {
if (mViewPager.getCurrentItem() == ProfileAdapter.IDX_ALBUM_SONG) {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_Z_A);
}
} else if (type == Type.FOLDER) {
mPreferences.setFolderSongSortOrder(SortOrder.FolderSongSortOrder.SONG_Z_A);
}
viewModel.notify(ProfileFragment.REFRESH);
}
Expand Down Expand Up @@ -487,6 +493,8 @@ else if (item.getItemId() == R.id.menu_sort_by_duration) {
if (mViewPager.getCurrentItem() == ProfileAdapter.IDX_ALBUM_SONG) {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_DURATION);
}
} else if (type == Type.FOLDER) {
mPreferences.setFolderSongSortOrder(SortOrder.FolderSongSortOrder.SONG_DURATION);
}
viewModel.notify(ProfileFragment.REFRESH);
}
Expand All @@ -499,7 +507,11 @@ else if (item.getItemId() == R.id.menu_sort_by_date_added) {
}
// sort by default order
else if (item.getItemId() == R.id.menu_sort_by_track_list) {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
if (type == Type.FOLDER) {
mPreferences.setFolderSongSortOrder(SortOrder.FolderSongSortOrder.SONG_TRACK_LIST);
} else {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
}
viewModel.notify(ProfileFragment.REFRESH);
}
// sort by file name
Expand All @@ -512,6 +524,8 @@ else if (item.getItemId() == R.id.menu_sort_by_filename) {
if (mViewPager.getCurrentItem() == ProfileAdapter.IDX_ALBUM_SONG) {
mPreferences.setAlbumSongSortOrder(SortOrder.AlbumSongSortOrder.SONG_FILENAME);
}
} else if (type == Type.FOLDER) {
mPreferences.setFolderSongSortOrder(SortOrder.FolderSongSortOrder.SONG_FILENAME);
}
viewModel.notify(ProfileFragment.REFRESH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ protected void init(Bundle param) {
mLoader.execute(null, this);
}


/**
* {@inheritDoc}
*/
@Override
public void onDestroy() {
mLoader.cancel();
super.onDestroy();
}


/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public final class CursorFactory {
/**
* select specific artist matching name
*/
private static final String ARTIST_SELECT = Artists.ARTIST + "=?";
private static final String ARTIST_SELECT = Artists.ARTIST + " LIKE ?";

/**
* select specific artist matching name
Expand Down Expand Up @@ -411,7 +411,7 @@ public static Cursor makeFolderSongCursor(Context context, String folderName) {
ContentResolver contentResolver = context.getContentResolver();

String[] args = {folderName + "%"};
String sortOrder = PreferenceUtils.getInstance(context).getSongSortOrder();
String sortOrder = PreferenceUtils.getInstance(context).getFolderSongSortOrder();
return contentResolver.query(Media.EXTERNAL_CONTENT_URI, TRACK_COLUMNS, FOLDER_TRACK_SELECT, args, sortOrder);
}

Expand Down Expand Up @@ -454,7 +454,7 @@ public static Cursor makeArtistCursor(Context context) {
public static Cursor makeArtistCursor(Context context, @NonNull String artistName) {
ContentResolver resolver = context.getContentResolver();

String[] args = {artistName};
String[] args = {"%" + artistName + "%"};
return resolver.query(Artists.EXTERNAL_CONTENT_URI, ARTIST_COLUMNS, ARTIST_SELECT, args, null);
}

Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/org/nuclearfog/apollo/utils/PreferenceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public final class PreferenceUtils {
public static final String ALBUM_SORT_ORDER = "album_sort_order";
// Sort order for the album song list
public static final String ALBUM_SONG_SORT_ORDER = "album_song_sort_order";
// Sort order for the album song list
public static final String FOLDER_SONG_SORT_ORDER = "folder_song_sort_order";
// Sort order for the song list
public static final String SONG_SORT_ORDER = "song_sort_order";
// Sets the type of layout to use for the artist list
Expand Down Expand Up @@ -291,6 +293,23 @@ public void setAlbumSongSortOrder(String value) {
setSortOrder(ALBUM_SONG_SORT_ORDER, value);
}

/**
* @return The sort order used for the folder song in
* {@link org.nuclearfog.apollo.ui.fragments.profile.FolderSongFragment}
*/
public String getFolderSongSortOrder() {
return defaultPref.getString(FOLDER_SONG_SORT_ORDER, SortOrder.FolderSongSortOrder.SONG_TRACK_LIST);
}

/**
* Sets the sort order for the folder song list.
*
* @param value The new sort order
*/
public void setFolderSongSortOrder(String value) {
setSortOrder(FOLDER_SONG_SORT_ORDER, value);
}

/**
* get current card ID
*
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/org/nuclearfog/apollo/utils/SortOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public interface SongSortOrder {
String SONG_YEAR = MediaStore.Audio.Media.YEAR + " DESC";

/* Song sort order duration */
String SONG_DURATION = "duration"/*MediaStore.Audio.Media.DURATION*/ + " DESC";
String SONG_DURATION = MediaStore.Audio.Media.DURATION + " DESC";

/* Song sort order filename */
String SONG_FILENAME = MediaStore.Audio.Media.DATA;
Expand Down Expand Up @@ -139,6 +139,9 @@ public interface ArtistSongSortOrder {
String SONG_FILENAME = SongSortOrder.SONG_FILENAME;
}

public interface FolderSongSortOrder extends AlbumSongSortOrder {
}

/**
* Artist album sort order entries.
*/
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/menu/folder_songs_sort_by.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:title="@string/menu_sort_by"
app:showAsAction="never">
<menu>
<item
android:id="@+id/menu_sort_by_az"
android:title="@string/sort_order_entry_az" />
<item
android:id="@+id/menu_sort_by_za"
android:title="@string/sort_order_entry_za" />
<item
android:id="@+id/menu_sort_by_duration"
android:title="@string/sort_order_entry_duration" />
<item
android:id="@+id/menu_sort_by_track_list"
android:title="@string/sort_order_entry_track_list" />
<item
android:id="@+id/menu_sort_by_filename"
android:title="@string/sort_order_entry_filename" />
</menu>
</item>
</menu>

0 comments on commit 06d6230

Please sign in to comment.