Changed to non-scrolling horizontal image view

This commit is contained in:
tom5079
2019-06-13 21:45:31 +09:00
parent 34f7b111ee
commit 868af1e6a2
2 changed files with 14 additions and 18 deletions

View File

@@ -9,9 +9,9 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.google.android.material.snackbar.Snackbar
@@ -330,12 +330,7 @@ class ReaderActivity : AppCompatActivity() {
scrollMode(false)
fullscreen(true)
} else {
val smoothScroller = object : LinearSmoothScroller(context) {
override fun getVerticalSnapPreference() = SNAP_TO_START
}.apply {
targetPosition = currentPage
}
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.startSmoothScroll(smoothScroller)
(reader_recyclerview.layoutManager as LinearLayoutManager?)?.scrollToPosition(currentPage)
}
}
}
@@ -377,7 +372,10 @@ class ReaderActivity : AppCompatActivity() {
reader_recyclerview.layoutManager = LinearLayoutManager(this)
} else {
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)

View File

@@ -25,21 +25,19 @@ class ReaderAdapter(private val images: List<String>) : RecyclerView.Adapter<Rea
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
with(holder.view as ImageView) {
CoroutineScope(Dispatchers.Default).launch {
val options = BitmapFactory.Options()
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(images[position], options)
options.inJustDecodeBounds = true
BitmapFactory.decodeFile(images[position], options)
options.inSampleSize = options.outWidth /
context.resources.displayMetrics.widthPixels
options.inSampleSize = options.outWidth /
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)
}
}