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