Code refactor and Flat, Fit, Full, Circle theme toolbar shadow fixes
This commit is contained in:
parent
954dfb6327
commit
724f743627
304 changed files with 3874 additions and 3524 deletions
|
@ -4,7 +4,6 @@ import android.content.Context;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -17,8 +16,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.signature.MediaStoreSignature;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCover;
|
||||
import code.name.monkey.retromusic.glide.palette.BitmapPaletteTranscoder;
|
||||
|
@ -32,21 +29,37 @@ public class AlbumGlideRequest {
|
|||
private static final int DEFAULT_ERROR_IMAGE = R.drawable.default_album_art;
|
||||
private static final int DEFAULT_ANIMATION = android.R.anim.fade_in;
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Song song,
|
||||
boolean ignoreMediaStore) {
|
||||
if (ignoreMediaStore) {
|
||||
return requestManager.load(new AudioFileCover(song.getData()));
|
||||
} else {
|
||||
return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Key createSignature(@NonNull Song song) {
|
||||
return new MediaStoreSignature("", song.getDateModified(), 0);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
final RequestManager requestManager;
|
||||
final Song song;
|
||||
boolean ignoreMediaStore;
|
||||
|
||||
@NonNull
|
||||
public static Builder from(@NonNull RequestManager requestManager, Song song) {
|
||||
return new Builder(requestManager, song);
|
||||
}
|
||||
|
||||
private Builder(@NonNull RequestManager requestManager, Song song) {
|
||||
this.requestManager = requestManager;
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Builder from(@NonNull RequestManager requestManager, Song song) {
|
||||
return new Builder(requestManager, song);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public PaletteBuilder generatePalette(@NonNull Context context) {
|
||||
return new PaletteBuilder(this, context);
|
||||
|
@ -98,6 +111,7 @@ public class AlbumGlideRequest {
|
|||
}
|
||||
|
||||
public static class PaletteBuilder {
|
||||
private static final String TAG = "PaletteBuilder";
|
||||
final Context context;
|
||||
private final Builder builder;
|
||||
|
||||
|
@ -107,32 +121,15 @@ public class AlbumGlideRequest {
|
|||
}
|
||||
|
||||
public BitmapRequestBuilder<?, BitmapPaletteWrapper> build() {
|
||||
Drawable drawable = TintHelper.createTintedDrawable(context, DEFAULT_ERROR_IMAGE, ThemeStore.Companion.accentColor(context));
|
||||
|
||||
//noinspection unchecked
|
||||
return createBaseRequest(builder.requestManager, builder.song, builder.ignoreMediaStore)
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.placeholder(drawable)
|
||||
.error(drawable)
|
||||
.error(DEFAULT_ERROR_IMAGE)
|
||||
.animate(DEFAULT_ANIMATION)
|
||||
.signature(createSignature(builder.song));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Song song,
|
||||
boolean ignoreMediaStore) {
|
||||
if (ignoreMediaStore) {
|
||||
return requestManager.load(new AudioFileCover(song.getData()));
|
||||
} else {
|
||||
return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Key createSignature(@NonNull Song song) {
|
||||
return new MediaStoreSignature("", song.getDateModified(), 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.glide;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -30,8 +29,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
||||
import code.name.monkey.retromusic.App;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.glide.artistimage.ArtistImage;
|
||||
|
@ -49,25 +46,40 @@ public class ArtistGlideRequest {
|
|||
|
||||
private static final int DEFAULT_ERROR_IMAGE = R.drawable.default_artist_art;
|
||||
|
||||
@NonNull
|
||||
public static Key createSignature(@NonNull Artist artist) {
|
||||
return ArtistSignatureUtil.getInstance(App.Companion.getContext()).getArtistSignature(artist.getName());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Artist artist,
|
||||
boolean noCustomImage, boolean forceDownload) {
|
||||
boolean hasCustomImage = CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext())
|
||||
.hasCustomArtistImage(artist);
|
||||
if (noCustomImage || !hasCustomImage) {
|
||||
return requestManager.load(new ArtistImage(artist.getName()));
|
||||
} else {
|
||||
return requestManager.load(CustomArtistImageUtil.getFile(artist));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
final Artist artist;
|
||||
|
||||
boolean forceDownload;
|
||||
|
||||
boolean noCustomImage;
|
||||
|
||||
final RequestManager requestManager;
|
||||
|
||||
public static Builder from(@NonNull RequestManager requestManager, Artist artist) {
|
||||
return new Builder(requestManager, artist);
|
||||
}
|
||||
boolean forceDownload;
|
||||
boolean noCustomImage;
|
||||
|
||||
private Builder(@NonNull RequestManager requestManager, Artist artist) {
|
||||
this.requestManager = requestManager;
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
public static Builder from(@NonNull RequestManager requestManager, Artist artist) {
|
||||
return new Builder(requestManager, artist);
|
||||
}
|
||||
|
||||
public BitmapBuilder asBitmap() {
|
||||
return new BitmapBuilder(this);
|
||||
}
|
||||
|
@ -132,38 +144,18 @@ public class ArtistGlideRequest {
|
|||
}
|
||||
|
||||
public BitmapRequestBuilder<?, BitmapPaletteWrapper> build() {
|
||||
Drawable drawable = TintHelper.createTintedDrawable(context, DEFAULT_ERROR_IMAGE, ThemeStore.Companion.accentColor(context));
|
||||
//noinspection unchecked
|
||||
return createBaseRequest(builder.requestManager, builder.artist, builder.noCustomImage,
|
||||
builder.forceDownload)
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.placeholder(drawable)
|
||||
.error(drawable)
|
||||
.placeholder(DEFAULT_ERROR_IMAGE)
|
||||
.error(DEFAULT_ERROR_IMAGE)
|
||||
.animate(DEFAULT_ANIMATION)
|
||||
.priority(Priority.LOW)
|
||||
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
|
||||
.signature(createSignature(builder.artist));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public static Key createSignature(@NonNull Artist artist) {
|
||||
return ArtistSignatureUtil.getInstance(App.Companion.getContext()).getArtistSignature(artist.getName());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Artist artist,
|
||||
boolean noCustomImage, boolean forceDownload) {
|
||||
boolean hasCustomImage = CustomArtistImageUtil.Companion.getInstance(App.Companion.getContext())
|
||||
.hasCustomArtistImage(artist);
|
||||
if (noCustomImage || !hasCustomImage) {
|
||||
return requestManager.load(new ArtistImage(artist.getName()));
|
||||
} else {
|
||||
return requestManager.load(CustomArtistImageUtil.getFile(artist));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -87,7 +87,12 @@ class BlurTransformation : BitmapTransformation {
|
|||
}
|
||||
}
|
||||
|
||||
override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap? {
|
||||
override fun transform(
|
||||
pool: BitmapPool,
|
||||
toTransform: Bitmap,
|
||||
outWidth: Int,
|
||||
outHeight: Int
|
||||
): Bitmap? {
|
||||
val sampling: Int
|
||||
if (this.sampling == 0) {
|
||||
sampling = ImageUtil.calculateInSampleSize(toTransform.width, toTransform.height, 100)
|
||||
|
@ -114,7 +119,12 @@ class BlurTransformation : BitmapTransformation {
|
|||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
try {
|
||||
val rs = RenderScript.create(context!!.applicationContext)
|
||||
val input = Allocation.createFromBitmap(rs, out, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT)
|
||||
val input = Allocation.createFromBitmap(
|
||||
rs,
|
||||
out,
|
||||
Allocation.MipmapControl.MIPMAP_NONE,
|
||||
Allocation.USAGE_SCRIPT
|
||||
)
|
||||
val output = Allocation.createTyped(rs, input.type)
|
||||
val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
|
||||
|
||||
|
|
|
@ -40,15 +40,20 @@ abstract class RetroMusicColoredTarget(view: ImageView) : BitmapPaletteTarget(vi
|
|||
onColorReady(defaultFooterColor)
|
||||
}
|
||||
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper?, glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
override fun onResourceReady(
|
||||
resource: BitmapPaletteWrapper?,
|
||||
glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?
|
||||
) {
|
||||
super.onResourceReady(resource, glideAnimation)
|
||||
val defaultColor = defaultFooterColor
|
||||
|
||||
resource?.let {
|
||||
onColorReady(if (PreferenceUtil.getInstance(getView().context).isDominantColor)
|
||||
RetroColorUtil.getDominantColor(it.bitmap, defaultColor)
|
||||
else
|
||||
RetroColorUtil.getColor(it.palette, defaultColor))
|
||||
onColorReady(
|
||||
if (PreferenceUtil.getInstance(getView().context).isDominantColor)
|
||||
RetroColorUtil.getDominantColor(it.bitmap, defaultColor)
|
||||
else
|
||||
RetroColorUtil.getColor(it.palette, defaultColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.glide
|
|||
|
||||
import android.content.Context
|
||||
import code.name.monkey.retromusic.glide.artistimage.ArtistImage
|
||||
import code.name.monkey.retromusic.glide.artistimage.ArtistImageLoader
|
||||
import code.name.monkey.retromusic.glide.artistimage.Factory
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCover
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCoverLoader
|
||||
|
@ -30,7 +29,11 @@ class RetroMusicGlideModule : GlideModule {
|
|||
}
|
||||
|
||||
override fun registerComponents(context: Context, glide: Glide) {
|
||||
glide.register(AudioFileCover::class.java, InputStream::class.java, AudioFileCoverLoader.Factory())
|
||||
glide.register(
|
||||
AudioFileCover::class.java,
|
||||
InputStream::class.java,
|
||||
AudioFileCoverLoader.Factory()
|
||||
)
|
||||
glide.register(ArtistImage::class.java, InputStream::class.java, Factory(context))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.glide;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -29,8 +28,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|||
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
||||
import com.bumptech.glide.signature.MediaStoreSignature;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.glide.audiocover.AudioFileCover;
|
||||
import code.name.monkey.retromusic.glide.palette.BitmapPaletteTranscoder;
|
||||
|
@ -48,21 +45,37 @@ public class SongGlideRequest {
|
|||
private static final int DEFAULT_ERROR_IMAGE = R.drawable.default_audio_art;
|
||||
private static final int DEFAULT_ANIMATION = android.R.anim.fade_in;
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Song song,
|
||||
boolean ignoreMediaStore) {
|
||||
if (ignoreMediaStore) {
|
||||
return requestManager.load(new AudioFileCover(song.getData()));
|
||||
} else {
|
||||
return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Key createSignature(@NonNull Song song) {
|
||||
return new MediaStoreSignature("", song.getDateModified(), 0);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
final RequestManager requestManager;
|
||||
final Song song;
|
||||
boolean ignoreMediaStore;
|
||||
|
||||
@NonNull
|
||||
public static Builder from(@NonNull RequestManager requestManager, Song song) {
|
||||
return new Builder(requestManager, song);
|
||||
}
|
||||
|
||||
private Builder(@NonNull RequestManager requestManager, Song song) {
|
||||
this.requestManager = requestManager;
|
||||
this.song = song;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Builder from(@NonNull RequestManager requestManager, Song song) {
|
||||
return new Builder(requestManager, song);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public PaletteBuilder generatePalette(@NonNull Context context) {
|
||||
return new PaletteBuilder(this, context);
|
||||
|
@ -90,7 +103,6 @@ public class SongGlideRequest {
|
|||
return createBaseRequest(requestManager, song, ignoreMediaStore)
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.error(DEFAULT_ERROR_IMAGE)
|
||||
.placeholder(DEFAULT_ERROR_IMAGE)
|
||||
.animate(DEFAULT_ANIMATION)
|
||||
.signature(createSignature(song));
|
||||
}
|
||||
|
@ -109,7 +121,6 @@ public class SongGlideRequest {
|
|||
.asBitmap()
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.error(DEFAULT_ERROR_IMAGE)
|
||||
.placeholder(DEFAULT_ERROR_IMAGE)
|
||||
.animate(DEFAULT_ANIMATION)
|
||||
.signature(createSignature(builder.song));
|
||||
}
|
||||
|
@ -125,32 +136,14 @@ public class SongGlideRequest {
|
|||
}
|
||||
|
||||
public BitmapRequestBuilder<?, BitmapPaletteWrapper> build() {
|
||||
Drawable drawable = TintHelper.createTintedDrawable(context, DEFAULT_ERROR_IMAGE, ThemeStore.Companion.accentColor(context));
|
||||
//noinspection unchecked
|
||||
return createBaseRequest(builder.requestManager, builder.song, builder.ignoreMediaStore)
|
||||
.asBitmap()
|
||||
.transcode(new BitmapPaletteTranscoder(context), BitmapPaletteWrapper.class)
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.placeholder(drawable)
|
||||
.error(drawable)
|
||||
.error(DEFAULT_ERROR_IMAGE)
|
||||
.animate(DEFAULT_ANIMATION)
|
||||
.signature(createSignature(builder.song));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static DrawableTypeRequest createBaseRequest(@NonNull RequestManager requestManager,
|
||||
@NonNull Song song,
|
||||
boolean ignoreMediaStore) {
|
||||
if (ignoreMediaStore) {
|
||||
return requestManager.load(new AudioFileCover(song.getData()));
|
||||
} else {
|
||||
return requestManager.loadFromMediaStore(MusicUtil.getMediaStoreAlbumCoverUri(song.getAlbumId()));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static Key createSignature(@NonNull Song song) {
|
||||
return new MediaStoreSignature("", song.getDateModified(), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,10 @@ class ArtistImageFetcher(
|
|||
}
|
||||
|
||||
override fun loadData(priority: Priority?): InputStream? {
|
||||
if (!MusicUtil.isArtistNameUnknown(model.artistName) && PreferenceUtil.isAllowedToDownloadMetadata(context)) {
|
||||
if (!MusicUtil.isArtistNameUnknown(model.artistName) && PreferenceUtil.isAllowedToDownloadMetadata(
|
||||
context
|
||||
)
|
||||
) {
|
||||
val artists = model.artistName.split(",")
|
||||
val response = deezerApiService.getArtistImage(artists[0]).execute()
|
||||
|
||||
|
@ -100,7 +103,11 @@ class ArtistImageLoader(
|
|||
private val urlLoader: ModelLoader<GlideUrl, InputStream>
|
||||
) : StreamModelLoader<ArtistImage> {
|
||||
|
||||
override fun getResourceFetcher(model: ArtistImage, width: Int, height: Int): DataFetcher<InputStream> {
|
||||
override fun getResourceFetcher(
|
||||
model: ArtistImage,
|
||||
width: Int,
|
||||
height: Int
|
||||
): DataFetcher<InputStream> {
|
||||
return ArtistImageFetcher(context, deezerApiService, model, urlLoader, width, height)
|
||||
}
|
||||
}
|
||||
|
@ -129,8 +136,15 @@ class Factory(
|
|||
)
|
||||
}
|
||||
|
||||
override fun build(context: Context?, factories: GenericLoaderFactory?): ModelLoader<ArtistImage, InputStream> {
|
||||
return ArtistImageLoader(context!!, deezerApiService, okHttpFactory.build(context, factories))
|
||||
override fun build(
|
||||
context: Context?,
|
||||
factories: GenericLoaderFactory?
|
||||
): ModelLoader<ArtistImage, InputStream> {
|
||||
return ArtistImageLoader(
|
||||
context!!,
|
||||
deezerApiService,
|
||||
okHttpFactory.build(context, factories)
|
||||
)
|
||||
}
|
||||
|
||||
override fun teardown() {
|
||||
|
|
|
@ -25,7 +25,6 @@ import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
|||
import java.io.InputStream;
|
||||
|
||||
|
||||
|
||||
public class AudioFileCoverLoader implements StreamModelLoader<AudioFileCover> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package code.name.monkey.retromusic.glide.palette;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.palette.graphics.Palette;
|
||||
|
||||
public class BitmapPaletteWrapper {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue