Changed to non-scrolling horizontal image view
This commit is contained in:
@@ -9,9 +9,9 @@ import androidx.appcompat.app.AlertDialog
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearSmoothScroller
|
|
||||||
import androidx.recyclerview.widget.PagerSnapHelper
|
import androidx.recyclerview.widget.PagerSnapHelper
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||||
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
|
||||||
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
@@ -330,12 +330,7 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
scrollMode(false)
|
scrollMode(false)
|
||||||
fullscreen(true)
|
fullscreen(true)
|
||||||
} else {
|
} else {
|
||||||
val smoothScroller = object : LinearSmoothScroller(context) {
|
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPosition(currentPage)
|
||||||
override fun getVerticalSnapPreference() = SNAP_TO_START
|
|
||||||
}.apply {
|
|
||||||
targetPosition = currentPage
|
|
||||||
}
|
|
||||||
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.startSmoothScroll(smoothScroller)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +372,10 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
reader_recyclerview.layoutManager = LinearLayoutManager(this)
|
reader_recyclerview.layoutManager = LinearLayoutManager(this)
|
||||||
} else {
|
} else {
|
||||||
snapHelper.attachToRecyclerView(reader_recyclerview)
|
snapHelper.attachToRecyclerView(reader_recyclerview)
|
||||||
reader_recyclerview.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
|
reader_recyclerview.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false).apply {
|
||||||
|
isItemPrefetchEnabled = true
|
||||||
|
initialPrefetchItemCount = 4
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(reader_recyclerview.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(currentPage-1, 0)
|
(reader_recyclerview.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(currentPage-1, 0)
|
||||||
|
|||||||
@@ -25,21 +25,19 @@ class ReaderAdapter(private val images: List<String>) : RecyclerView.Adapter<Rea
|
|||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
with(holder.view as ImageView) {
|
with(holder.view as ImageView) {
|
||||||
CoroutineScope(Dispatchers.Default).launch {
|
val options = BitmapFactory.Options()
|
||||||
val options = BitmapFactory.Options()
|
|
||||||
|
|
||||||
options.inJustDecodeBounds = true
|
options.inJustDecodeBounds = true
|
||||||
BitmapFactory.decodeFile(images[position], options)
|
BitmapFactory.decodeFile(images[position], options)
|
||||||
|
|
||||||
options.inSampleSize = options.outWidth /
|
options.inSampleSize = options.outWidth /
|
||||||
context.resources.displayMetrics.widthPixels
|
context.resources.displayMetrics.widthPixels
|
||||||
|
|
||||||
options.inJustDecodeBounds = false
|
options.inJustDecodeBounds = false
|
||||||
|
|
||||||
val image = BitmapFactory.decodeFile(images[position], options)
|
val image = BitmapFactory.decodeFile(images[position], options)
|
||||||
|
|
||||||
post { setImageBitmap(image) }
|
setImageBitmap(image)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user