|
@@ -1,4 +1,4 @@
|
|
|
-package com.kdanmobile.reader.screen.view
|
|
|
+package com.kdanmobile.reader.screen.adapter
|
|
|
|
|
|
import android.graphics.Bitmap
|
|
|
import android.support.v4.util.LruCache
|
|
@@ -10,15 +10,15 @@ import android.widget.FrameLayout
|
|
|
import android.widget.ImageView
|
|
|
import android.widget.TextView
|
|
|
import com.kdanmobile.reader.R
|
|
|
-import com.kdanmobile.reader.ReaderViewModel
|
|
|
-import com.kdanmobile.reader.screen.view.ThumbnailAdapter.ThumbnailViewHolder
|
|
|
-import com.kdanmobile.reader.utils.DensityUtil
|
|
|
+import com.kdanmobile.reader.screen.handler.ThumbnailHandler
|
|
|
+import com.kdanmobile.reader.screen.adapter.ThumbnailAdapter.ThumbnailViewHolder
|
|
|
+import com.kdanmobile.reader.screen.handler.PdfInfoHandler
|
|
|
import io.reactivex.Observable
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
import io.reactivex.schedulers.Schedulers
|
|
|
|
|
|
-class ThumbnailAdapter(private val handler: ThumbnailHandler, private val filename: String): RecyclerView.Adapter<ThumbnailViewHolder>() {
|
|
|
+class ThumbnailAdapter(private val pdfInfoHandler: PdfInfoHandler, private val thumbnailHandler: ThumbnailHandler, private val filename: String = pdfInfoHandler.getOpenPdfFilename()!!): RecyclerView.Adapter<ThumbnailViewHolder>() {
|
|
|
|
|
|
companion object {
|
|
|
lateinit var mMemoryCache: LruCache<String, Bitmap>
|
|
@@ -27,7 +27,7 @@ class ThumbnailAdapter(private val handler: ThumbnailHandler, private val filena
|
|
|
private var currentPage = 0
|
|
|
|
|
|
init {
|
|
|
- this.currentPage = handler.getCurrentPage() ?: 0
|
|
|
+ this.currentPage = pdfInfoHandler.getCurrentPage() ?: 0
|
|
|
|
|
|
mMemoryCache = object: LruCache<String, Bitmap>(maxMemory.toInt()) {
|
|
|
override fun sizeOf(key: String, value: Bitmap): Int {
|
|
@@ -49,13 +49,13 @@ class ThumbnailAdapter(private val handler: ThumbnailHandler, private val filena
|
|
|
}
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
|
- return handler.getPdfPageCount() ?: 0
|
|
|
+ return pdfInfoHandler.getPdfPageCount() ?: 0
|
|
|
}
|
|
|
|
|
|
override fun onBindViewHolder(holder: ThumbnailViewHolder, position: Int) {
|
|
|
holder.page.text = (holder.adapterPosition + 1).toString()
|
|
|
holder.onShowBorder(currentPage == holder.adapterPosition)
|
|
|
- holder.loadThumbSync(filename, handler)
|
|
|
+ holder.loadThumbSync()
|
|
|
}
|
|
|
|
|
|
override fun onBindViewHolder(holder: ThumbnailViewHolder, position: Int, payloads: List<Any>) {
|
|
@@ -101,7 +101,7 @@ class ThumbnailAdapter(private val handler: ThumbnailHandler, private val filena
|
|
|
border.visibility = if (isShow) View.VISIBLE else View.GONE
|
|
|
}
|
|
|
|
|
|
- internal fun loadThumbSync(filename: String, handler: ThumbnailHandler) {
|
|
|
+ internal fun loadThumbSync() {
|
|
|
stopLoadThumbSync()
|
|
|
|
|
|
disposable = Observable.create<Bitmap> { emitter ->
|
|
@@ -110,13 +110,13 @@ class ThumbnailAdapter(private val handler: ThumbnailHandler, private val filena
|
|
|
if (null != mMemoryCache[pageNameTag]) {
|
|
|
bitmap = mMemoryCache[pageNameTag]!!
|
|
|
} else {
|
|
|
- bitmap = handler.getPdfBitmap(adapterPosition, 180, ThumbnailHandler.MODE_DAY, true) !!
|
|
|
+ bitmap = thumbnailHandler.getPdfBitmap(adapterPosition, 180, ThumbnailHandler.MODE_DAY, true) !!
|
|
|
mMemoryCache.put(pageNameTag, bitmap)
|
|
|
}
|
|
|
emitter.onNext(bitmap)
|
|
|
emitter.onComplete()
|
|
|
}
|
|
|
- .subscribeOn(Schedulers.computation())
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
.subscribe({
|
|
|
thumb.setImageBitmap(it)
|