Merge pull request #122 from DelightLane/duration_crash

fix: null checking for song without duration info
This commit is contained in:
CappielloAntonio 2024-01-28 19:35:56 +01:00 committed by GitHub
commit 34d6692dae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -49,7 +49,7 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
Child song = songs.get(position);
holder.item.searchResultSongTitleTextView.setText(MusicUtil.getReadableString(song.getTitle()));
holder.item.searchResultSongSubtitleTextView.setText(holder.itemView.getContext().getString(R.string.song_subtitle_formatter, MusicUtil.getReadableString(this.showAlbum ? song.getAlbum() : song.getArtist()), MusicUtil.getReadableDurationString(song.getDuration() != null ? song.getDuration() : 0, false)));
holder.item.searchResultSongSubtitleTextView.setText(holder.itemView.getContext().getString(R.string.song_subtitle_formatter, MusicUtil.getReadableString(this.showAlbum ? song.getAlbum() : song.getArtist()), MusicUtil.getReadableDurationString(song.getDuration(), false)));
holder.item.trackNumberTextView.setText(MusicUtil.getReadableTrackNumber(holder.itemView.getContext(), song.getTrack()));
if (DownloadUtil.getDownloadTracker(holder.itemView.getContext()).isDownloaded(song.getId())) {

View file

@ -149,6 +149,14 @@ public class MusicUtil {
}
}
public static String getReadableDurationString(Integer duration, boolean millis) {
long converted = 0;
if(duration != null)
converted = duration.intValue();
return getReadableDurationString(converted, millis);
}
public static String getReadablePodcastDurationString(long duration) {
long minutes = duration / 60;