From b02a588dffc62e978f36561e01d451cb9f5d45e7 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 2 Nov 2022 11:50:00 +0100 Subject: [PATCH 1/4] Add a checkerboard background drawable --- androidApp/src/main/res/drawable/checkerboard.xml | 5 +++++ androidApp/src/main/res/drawable/checktile.png | Bin 0 -> 98 bytes androidApp/src/main/res/layout/fragment_image.xml | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 androidApp/src/main/res/drawable/checkerboard.xml create mode 100644 androidApp/src/main/res/drawable/checktile.png diff --git a/androidApp/src/main/res/drawable/checkerboard.xml b/androidApp/src/main/res/drawable/checkerboard.xml new file mode 100644 index 0000000..edc5ee7 --- /dev/null +++ b/androidApp/src/main/res/drawable/checkerboard.xml @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/androidApp/src/main/res/drawable/checktile.png b/androidApp/src/main/res/drawable/checktile.png new file mode 100644 index 0000000000000000000000000000000000000000..e71359d16c0be3c3feab27c3f826987f9b87f73f GIT binary patch literal 98 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`nw~C>Ar*1S7RArb)Yr@qNN~8` v(8t*r$jsKt_=4#L!(E3Go2&yH3>X+riL77u;=!DiKurvuu6{1-oD!M \ No newline at end of file From c09a32e9ad33d9918eec2541c45b93df4ba5a982 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Thu, 3 Nov 2022 23:16:48 +0100 Subject: [PATCH 2/4] Add checkerboard background to the images in the image view A checkerboard is drawn beneath the image in the imageview to allow a simpler viewing of images with transparency --- .../android/fragments/ImageFragment.kt | 22 ++++++++++++++----- .../src/main/res/layout/fragment_image.xml | 7 +++--- 2 files changed, 20 insertions(+), 9 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 cf5200e..d3afc2a 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -1,5 +1,5 @@ - @@ -9,7 +9,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerVertical="true" - android:layout_centerHorizontal="true" + android:adjustViewBounds="true" + android:background="?attr/colorOnBackground" app:srcCompat="@android:drawable/screen_background_dark" /> - \ No newline at end of file + \ No newline at end of file From 3a3bf0311499136133d7f482b572d85f4314af9a Mon Sep 17 00:00:00 2001 From: aminecmi Date: Thu, 10 Nov 2022 21:41:55 +0100 Subject: [PATCH 3/4] Bigger checktile. --- .../android/fragments/ImageFragment.kt | 17 +---------------- androidApp/src/main/res/drawable/checktile.png | Bin 98 -> 235 bytes .../src/main/res/layout/fragment_image.xml | 2 +- 3 files changed, 2 insertions(+), 17 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 4398b21..c83d60e 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,23 +1,18 @@ 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.request.target.ImageViewTarget class ImageFragment : Fragment() { private lateinit var imageUrl : String private var _binding: FragmentImageBinding? = null private val binding get() = _binding - private lateinit var layers: LayerDrawable override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -32,17 +27,7 @@ class ImageFragment : Fragment() { binding!!.photoView.visibility = View.VISIBLE Glide.with(activity) .load(imageUrl) - .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()) - } - }) + .into(binding!!.photoView) return view } diff --git a/androidApp/src/main/res/drawable/checktile.png b/androidApp/src/main/res/drawable/checktile.png index e71359d16c0be3c3feab27c3f826987f9b87f73f..eeef9de50682fd36cdb1c09354e84d019c946362 100644 GIT binary patch literal 235 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eBeuJlrV@L(#+slrE2Mh!n9HP8GzE`+7<=Ro( z1XY8>o4@bliOM#7>AH^Lgeb#KCWUZ@CtM9Nj1#mOidY@62%i6I_+rlCC1Tj*Fg09e b|G{u?HrGA=M@gH2Zej3r^>bP0l+XkK73oK% literal 98 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`nw~C>Ar*1S7RArb)Yr@qNN~8` v(8t*r$jsKt_=4#L!(E3Go2&yH3>X+riL77u;=!DiKurvuu6{1-oD!M \ No newline at end of file From dbe97f564ea5e0e907baf778e6901c1d55ed100e Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 11 Nov 2022 09:40:36 +0100 Subject: [PATCH 4/4] Revert imageview changes --- .../readerforselfossv2/android/fragments/ImageFragment.kt | 5 +++++ 1 file changed, 5 insertions(+) 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 c83d60e..129f883 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 @@ -7,10 +7,13 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment 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 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 @@ -26,6 +29,8 @@ class ImageFragment : Fragment() { binding!!.photoView.visibility = View.VISIBLE Glide.with(activity) + .asBitmap() + .apply(glideOptions) .load(imageUrl) .into(binding!!.photoView)