Further simplified customGlideRequests, adding placeholder, error and fallback colors

This commit is contained in:
antonio 2023-03-14 10:48:13 +01:00
parent f5a3ba49cc
commit 40cfbef4d7
7 changed files with 65 additions and 59 deletions

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -20,7 +20,7 @@
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="9"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="12dp"
@ -29,7 +29,7 @@
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<ImageView
@ -39,5 +39,5 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>

View file

@ -20,7 +20,7 @@
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="8"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="12dp"
@ -29,7 +29,7 @@
android:layout_marginTop="22dp"
android:layout_marginEnd="8dp"
android:layout_weight="2"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
@ -53,19 +53,19 @@
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
@ -78,19 +78,19 @@
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
@ -102,19 +102,19 @@
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -12,7 +12,7 @@
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<LinearLayout
android:layout_width="wrap_content"
@ -27,7 +27,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -35,7 +35,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -43,7 +43,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
@ -58,7 +58,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -66,7 +66,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -74,7 +74,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
@ -89,7 +89,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -97,7 +97,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="196dp"
@ -105,6 +105,6 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
</LinearLayout>

View file

@ -21,7 +21,7 @@
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="8"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="12dp"
@ -30,7 +30,7 @@
android:layout_marginTop="22dp"
android:layout_marginEnd="8dp"
android:layout_weight="2"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
<androidx.constraintlayout.widget.ConstraintLayout
@ -46,7 +46,7 @@
android:layout_height="52dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -58,7 +58,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_1"
app:layout_constraintTop_toTopOf="parent" />
@ -68,7 +68,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_1"
app:layout_constraintTop_toBottomOf="@+id/album_title_placeholder_1" />
@ -77,7 +77,7 @@
android:layout_height="18dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -98,7 +98,7 @@
android:layout_height="52dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -110,7 +110,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_2"
app:layout_constraintTop_toTopOf="parent" />
@ -120,7 +120,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_2"
app:layout_constraintTop_toBottomOf="@+id/album_title_placeholder_2" />
@ -129,7 +129,7 @@
android:layout_height="18dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -150,7 +150,7 @@
android:layout_height="52dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -162,7 +162,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_3"
app:layout_constraintTop_toTopOf="parent" />
@ -172,7 +172,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_3"
app:layout_constraintTop_toBottomOf="@+id/album_title_placeholder_3" />
@ -181,7 +181,7 @@
android:layout_height="18dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -202,7 +202,7 @@
android:layout_height="52dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -214,7 +214,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_4"
app:layout_constraintTop_toTopOf="parent" />
@ -224,7 +224,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_4"
app:layout_constraintTop_toBottomOf="@+id/album_title_placeholder_4" />
@ -233,7 +233,7 @@
android:layout_height="18dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -254,7 +254,7 @@
android:layout_height="52dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -266,7 +266,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_5"
app:layout_constraintTop_toTopOf="parent" />
@ -276,7 +276,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="16dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
app:layout_constraintStart_toEndOf="@+id/album_cover_placeholder_5"
app:layout_constraintTop_toBottomOf="@+id/album_title_placeholder_5" />
@ -285,7 +285,7 @@
android:layout_height="18dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/colorSurfaceContainer"
android:background="?attr/colorSurface"
android:gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

View file

@ -12,7 +12,7 @@
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<LinearLayout
android:layout_width="wrap_content"
@ -27,7 +27,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="172dp"
@ -35,7 +35,7 @@
android:layout_gravity="center"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="172dp"
@ -43,6 +43,6 @@
android:layout_gravity="center"
android:layout_marginEnd="12dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurfaceContainer" />
android:background="?attr/colorSurface" />
</LinearLayout>
</LinearLayout>