sort songs by disc number on album details page
This commit is contained in:
parent
5c7be50dfa
commit
35f71fc6f3
6 changed files with 13 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ import com.dkanada.gramophone.model.Song;
|
|||
import com.dkanada.gramophone.util.MusicUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class AlbumSongAdapter extends SongAdapter {
|
||||
public AlbumSongAdapter(AppCompatActivity activity, List<Song> dataSet, @LayoutRes int itemLayoutRes, boolean usePalette, @Nullable CabHolder cabHolder) {
|
||||
|
|
@ -29,9 +30,9 @@ public class AlbumSongAdapter extends SongAdapter {
|
|||
final Song song = dataSet.get(position);
|
||||
|
||||
if (holder.imageText != null) {
|
||||
final int trackNumber = MusicUtil.getFixedTrackNumber(song.trackNumber);
|
||||
final String trackNumberString = trackNumber > 0 ? String.valueOf(trackNumber) : "-";
|
||||
holder.imageText.setText(trackNumberString);
|
||||
final String trackNumber = song.trackNumber > 0 ? String.format(Locale.ENGLISH, "%02d", song.trackNumber) : null;
|
||||
final String discNumber = song.discNumber > 0 ? String.valueOf(song.discNumber) : null;
|
||||
holder.imageText.setText(trackNumber != null ? String.format(Locale.ENGLISH, "%s.%s", discNumber, trackNumber) : "-");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class SongLoader {
|
|||
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);
|
||||
return new Song(id, title, trackNumber, 1, year, duration, albumId, albumName, artistId, artistName, primary, favorite);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ import android.os.Parcelable;
|
|||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
||||
public class Song implements Parcelable {
|
||||
public static final Song EMPTY_SONG = new Song(null, "", -1, -1, -1, null, "", null, "", null, false);
|
||||
public static final Song EMPTY_SONG = new Song(null, "", -1, -1, -1, -1, null, "", null, "", null, false);
|
||||
|
||||
public final String id;
|
||||
public final String title;
|
||||
public final int trackNumber;
|
||||
public final int discNumber;
|
||||
public final int year;
|
||||
public final long duration;
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ public class Song implements Parcelable {
|
|||
this.id = itemDto.getId();
|
||||
this.title = itemDto.getName();
|
||||
this.trackNumber = itemDto.getIndexNumber() != null ? itemDto.getIndexNumber() : 0;
|
||||
this.discNumber = itemDto.getParentIndexNumber() != null ? itemDto.getParentIndexNumber() : 0;
|
||||
this.year = itemDto.getProductionYear() != null ? itemDto.getProductionYear() : 0;
|
||||
this.duration = itemDto.getRunTimeTicks() != null ? itemDto.getRunTimeTicks() / 10000 : 0;
|
||||
|
||||
|
|
@ -45,10 +47,11 @@ public class Song implements Parcelable {
|
|||
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, String primary, boolean favorite) {
|
||||
public Song(String id, String title, int trackNumber, int discNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName, String primary, boolean favorite) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.trackNumber = trackNumber;
|
||||
this.discNumber = discNumber;
|
||||
this.year = year;
|
||||
this.duration = duration;
|
||||
|
||||
|
|
@ -91,6 +94,7 @@ public class Song implements Parcelable {
|
|||
dest.writeString(this.id);
|
||||
dest.writeString(this.title);
|
||||
dest.writeInt(this.trackNumber);
|
||||
dest.writeInt(this.discNumber);
|
||||
dest.writeInt(this.year);
|
||||
dest.writeLong(this.duration);
|
||||
|
||||
|
|
@ -108,6 +112,7 @@ public class Song implements Parcelable {
|
|||
this.id = in.readString();
|
||||
this.title = in.readString();
|
||||
this.trackNumber = in.readInt();
|
||||
this.discNumber = in.readInt();
|
||||
this.year = in.readInt();
|
||||
this.duration = in.readLong();
|
||||
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
|
|||
|
||||
ItemQuery query = new ItemQuery();
|
||||
query.setParentId(album.id);
|
||||
query.setSortBy(new String[]{"IndexNumber"});
|
||||
query.setSortBy(new String[]{"ParentIndexNumber", "IndexNumber"});
|
||||
|
||||
QueryUtil.getSongs(query, new MediaCallback() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -146,12 +146,6 @@ public class MusicUtil {
|
|||
return one + " • " + two;
|
||||
}
|
||||
|
||||
// iTunes uses for example 1002 for track 2 CD1 or 3011 for track 11 CD3.
|
||||
// this method converts those values to normal track numbers
|
||||
public static int getFixedTrackNumber(int trackNumberToFix) {
|
||||
return trackNumberToFix % 1000;
|
||||
}
|
||||
|
||||
public static void toggleFavorite(@NonNull final Context context, @NonNull final Song song) {
|
||||
song.favorite = !song.favorite;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue