mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Custom glide builder now also accepts a custom url
This commit is contained in:
parent
231eab549c
commit
8243173e29
24 changed files with 54 additions and 26 deletions
|
|
@ -50,7 +50,7 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(album.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class AlbumArtistPageOrSimilarAdapter extends RecyclerView.Adapter<AlbumA
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(album.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(album.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
|
|||
holder.albumArtist.setText(MusicUtil.getReadableString(album.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(context, album.getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(artist.getName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC)
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class ArtistCatalogueAdapter extends RecyclerView.Adapter<ArtistCatalogue
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(artist.getName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC)
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizont
|
|||
holder.artistInfo.setText("Album count: " + String.valueOf(artist.getAlbumCount()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC)
|
||||
.from(context, artist.getId(), CustomGlideRequest.ARTIST_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class ArtistSimilarAdapter extends RecyclerView.Adapter<ArtistSimilarAdap
|
|||
holder.textArtistName.setText(MusicUtil.getReadableString(artist.getName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, artist.getId(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(context, artist.getId(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class DiscoverSongAdapter extends RecyclerView.Adapter<DiscoverSongAdapte
|
|||
holder.textAlbum.setText(MusicUtil.getReadableString(song.getAlbumName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.into(holder.cover);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class PlayerNowPlayingSongAdapter extends RecyclerView.Adapter<PlayerNowP
|
|||
Song song = songs.get(position);
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getId(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getId(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
|||
holder.songArtist.setText(MusicUtil.getReadableString(song.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
|
|||
holder.textPlaylistSongCount.setText("Song count: " + String.valueOf(playlist.getSongCount()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, playlist.getPrimary(), CustomGlideRequest.PLAYLIST_PIC)
|
||||
.from(context, playlist.getPrimary(), CustomGlideRequest.PLAYLIST_PIC, null)
|
||||
.build()
|
||||
.into(holder.cover);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class PlaylistCatalogueAdapter extends RecyclerView.Adapter<PlaylistCatal
|
|||
holder.textPlaylistName.setText(MusicUtil.getReadableString(playlist.getName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, playlist.getPrimary(), CustomGlideRequest.PLAYLIST_PIC)
|
||||
.from(context, playlist.getPrimary(), CustomGlideRequest.PLAYLIST_PIC, null)
|
||||
.build()
|
||||
.into(holder.cover);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class RecentMusicAdapter extends RecyclerView.Adapter<RecentMusicAdapter.
|
|||
holder.textAlbum.setText(MusicUtil.getReadableString(song.getAlbumName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class SongHorizontalAdapter extends RecyclerView.Adapter<SongHorizontalAd
|
|||
}
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(context, song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
|
|
|||
|
|
@ -55,16 +55,25 @@ public class CustomGlideRequest {
|
|||
private final RequestManager requestManager;
|
||||
private final Object item;
|
||||
|
||||
private Builder(Context context, String item, String category) {
|
||||
private Builder(Context context, String item, String category, String custom) {
|
||||
this.requestManager = Glide.with(context);
|
||||
this.item = item != null ? createUrl(item) : MusicUtil.getDefaultPicPerCategory(category);
|
||||
|
||||
if(item != null) {
|
||||
this.item = createUrl(item);
|
||||
}
|
||||
else if(custom != null) {
|
||||
this.item = custom;
|
||||
}
|
||||
else {
|
||||
this.item = MusicUtil.getDefaultPicPerCategory(category);
|
||||
}
|
||||
|
||||
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), MusicUtil.getDefaultPicPerCategory(category), null);
|
||||
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
|
||||
}
|
||||
|
||||
public static Builder from(Context context, String item, String category) {
|
||||
return new Builder(context, item, category);
|
||||
public static Builder from(Context context, String item, String category, String custom) {
|
||||
return new Builder(context, item, category, custom);
|
||||
}
|
||||
|
||||
public BitmapBuilder bitmap() {
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ public class AlbumPageFragment extends Fragment {
|
|||
|
||||
private void initBackCover() {
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), albumPageViewModel.getAlbum().getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(requireContext(), albumPageViewModel.getAlbum().getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(bind.albumCoverImageView);
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ public class PlayerBottomSheetFragment extends Fragment implements MusicServiceE
|
|||
bind.playerHeaderLayout.playerHeaderSongArtistLabel.setText(MusicUtil.getReadableString(song.getArtistName()));
|
||||
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(requireContext(), song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(bind.playerHeaderLayout.playerHeaderSongCoverImage);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ public class PlaylistPageFragment extends Fragment {
|
|||
|
||||
private void initBackCover() {
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), playlistPageViewModel.getPlaylist().getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(requireContext(), playlistPageViewModel.getPlaylist().getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.into(bind.albumBackCoverImageView);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class AlbumBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
|
||||
coverAlbum = view.findViewById(R.id.album_cover_image_view);
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getPrimary(), CustomGlideRequest.ALBUM_PIC)
|
||||
.from(requireContext(), albumBottomSheetViewModel.getAlbum().getPrimary(), CustomGlideRequest.ALBUM_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(coverAlbum);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class ArtistBottomSheetDialog extends BottomSheetDialogFragment implement
|
|||
|
||||
coverArtist = view.findViewById(R.id.artist_cover_image_view);
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), artistBottomSheetViewModel.getArtist().getPrimary(), CustomGlideRequest.ARTIST_PIC)
|
||||
.from(requireContext(), artistBottomSheetViewModel.getArtist().getPrimary(), CustomGlideRequest.ARTIST_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(coverArtist);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class SongBottomSheetDialog extends BottomSheetDialogFragment implements
|
|||
private void init(View view) {
|
||||
coverSong = view.findViewById(R.id.song_cover_image_view);
|
||||
CustomGlideRequest.Builder
|
||||
.from(requireContext(), songBottomSheetViewModel.getSong().getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(requireContext(), songBottomSheetViewModel.getSong().getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.build()
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(coverSong);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class PlayingNotification {
|
|||
|
||||
final int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
|
||||
service.runOnUiThread(() -> CustomGlideRequest.Builder
|
||||
.from(service, song.getPrimary(), CustomGlideRequest.SONG_PIC)
|
||||
.from(service, song.getPrimary(), CustomGlideRequest.SONG_PIC, null)
|
||||
.bitmap()
|
||||
.build()
|
||||
.into(new CustomTarget<Bitmap>(bigNotificationImageSize, bigNotificationImageSize) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MusicUtil {
|
||||
private static final String TAG = "MusicUtil";
|
||||
|
|
@ -91,4 +93,21 @@ public class MusicUtil {
|
|||
String uri = MusicUtil.getSongFileUri(song);
|
||||
return MediaItem.fromUri(uri);
|
||||
}
|
||||
|
||||
public static CharSequence HTMLParser(String toParse) {
|
||||
if (toParse != null && containsHTML(toParse)) {
|
||||
return Html.fromHtml(toParse, Html.FROM_HTML_MODE_LEGACY);
|
||||
}
|
||||
else {
|
||||
return toParse;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean containsHTML(String toParse) {
|
||||
String HTML_PATTERN = "<(\"[^\"]*\"|'[^']*'|[^'\">])*>";
|
||||
Pattern pattern = Pattern.compile(HTML_PATTERN);
|
||||
|
||||
Matcher matcher = pattern.matcher(toParse);
|
||||
return matcher.find();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue