Checkerboard background for transparency in zoomed images #92

Merged
AmineB merged 4 commits from davidoskky/ReaderForSelfoss-multiplatform:checkerboard into master 2022-11-11 19:29:43 +00:00
2 changed files with 20 additions and 9 deletions
Showing only changes of commit c09a32e9ad - Show all commits

View File

@ -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<Drawable>(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
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -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" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>