From ae0909ef0a0dfb07e58e6d6bb6ac8f236f4d9c41 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 3 Nov 2022 23:16:48 +0100 Subject: [PATCH] Only show the checkerboard beneath the image --- .../android/fragments/ImageFragment.kt | 22 ++++++++++++++----- .../src/main/res/layout/fragment_image.xml | 7 +++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 129f883..4398b21 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -1,21 +1,23 @@ package bou.amine.apps.readerforselfossv2.android.fragments +import android.graphics.drawable.Drawable +import android.graphics.drawable.LayerDrawable import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.FragmentImageBinding import com.bumptech.glide.Glide -import com.bumptech.glide.load.engine.DiskCacheStrategy -import com.bumptech.glide.request.RequestOptions +import com.bumptech.glide.request.target.ImageViewTarget class ImageFragment : Fragment() { private lateinit var imageUrl : String - private val glideOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL) private var _binding: FragmentImageBinding? = null private val binding get() = _binding + private lateinit var layers: LayerDrawable override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -29,10 +31,18 @@ class ImageFragment : Fragment() { binding!!.photoView.visibility = View.VISIBLE Glide.with(activity) - .asBitmap() - .apply(glideOptions) .load(imageUrl) - .into(binding!!.photoView) + .into(object : ImageViewTarget(binding!!.photoView) { + override fun setResource(resource: Drawable?) { + val background = resources.getDrawable(R.drawable.checkerboard, context?.theme) + layers = LayerDrawable(arrayOf(background, resource)) + binding!!.photoView.setImageDrawable(layers) + } + + override fun onLoadCleared(placeholder: Drawable?) { + layers = LayerDrawable(emptyArray()) + } + }) return view } diff --git a/androidApp/src/main/res/layout/fragment_image.xml b/androidApp/src/main/res/layout/fragment_image.xml index 22efa95..0c65061 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -1,5 +1,5 @@ - @@ -9,8 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" - android:layout_centerHorizontal="true" - android:background="@drawable/checkerboard" + android:adjustViewBounds="true" app:srcCompat="@android:drawable/screen_background_dark" /> - \ No newline at end of file + \ No newline at end of file