mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Further simplified customGlideRequests, adding placeholder, error and fallback colors
This commit is contained in:
parent
f5a3ba49cc
commit
40cfbef4d7
7 changed files with 65 additions and 59 deletions
|
|
@ -1,11 +1,10 @@
|
|||
package com.cappielloantonio.play.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
|
|
@ -15,6 +14,7 @@ import com.bumptech.glide.signature.ObjectKey;
|
|||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.util.Preferences;
|
||||
import com.google.android.material.elevation.SurfaceColors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -25,9 +25,11 @@ public class CustomGlideRequest {
|
|||
|
||||
public static final DiskCacheStrategy DEFAULT_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL;
|
||||
|
||||
public static RequestOptions createRequestOptions(String item, Drawable placeholder) {
|
||||
public static RequestOptions createRequestOptions(Context context, String item) {
|
||||
return new RequestOptions()
|
||||
.error(placeholder)
|
||||
.placeholder(new ColorDrawable(SurfaceColors.SURFACE_5.getColor(context)))
|
||||
.fallback(new ColorDrawable(SurfaceColors.SURFACE_5.getColor(context)))
|
||||
.error(new ColorDrawable(SurfaceColors.SURFACE_5.getColor(context)))
|
||||
.diskCacheStrategy(DEFAULT_DISK_CACHE_STRATEGY)
|
||||
.signature(new ObjectKey(item != null ? item : 0))
|
||||
.centerCrop();
|
||||
|
|
@ -78,8 +80,7 @@ public class CustomGlideRequest {
|
|||
this.item = R.drawable.default_album_art;
|
||||
}
|
||||
|
||||
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), R.drawable.default_album_art, null);
|
||||
requestManager.applyDefaultRequestOptions(createRequestOptions(item, drawable));
|
||||
requestManager.applyDefaultRequestOptions(createRequestOptions(context, item));
|
||||
}
|
||||
|
||||
public static Builder from(Context context, String item) {
|
||||
|
|
|
|||
|
|
@ -258,6 +258,10 @@ public class PlayerBottomSheetFragment extends Fragment {
|
|||
playerBottomSheetViewModel.getPlayQueue().observeForever(new Observer<PlayQueue>() {
|
||||
@Override
|
||||
public void onChanged(PlayQueue playQueue) {
|
||||
playerBottomSheetViewModel.getPlayQueue().removeObserver(this);
|
||||
|
||||
if (bind == null) return;
|
||||
|
||||
if (playQueue != null && !playQueue.getEntries().isEmpty()) {
|
||||
int index = IntStream.range(0, playQueue.getEntries().size()).filter(ix -> playQueue.getEntries().get(ix).getId().equals(playQueue.getCurrent())).findFirst().orElse(-1);
|
||||
|
||||
|
|
@ -272,8 +276,6 @@ public class PlayerBottomSheetFragment extends Fragment {
|
|||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setOnClickListener(null);
|
||||
}
|
||||
|
||||
playerBottomSheetViewModel.getPlayQueue().removeObserver(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -282,6 +284,9 @@ public class PlayerBottomSheetFragment extends Fragment {
|
|||
return false;
|
||||
});
|
||||
|
||||
new Handler().postDelayed(() -> bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE), 5000);
|
||||
new Handler().postDelayed(() -> {
|
||||
if (bind != null)
|
||||
bind.playerHeaderLayout.playerHeaderBookmarkMediaButton.setVisibility(View.GONE);
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue