|
@@ -0,0 +1,57 @@
|
|
|
|
+package com.kdanmobile.reader.screen.view
|
|
|
|
+
|
|
|
|
+import android.content.Context
|
|
|
|
+import android.util.AttributeSet
|
|
|
|
+import android.view.LayoutInflater
|
|
|
|
+import android.widget.RelativeLayout
|
|
|
|
+import com.kdanmobile.kmpdfkit.pdfcommon.OutlineItem
|
|
|
|
+import com.kdanmobile.reader.R
|
|
|
|
+import com.kdanmobile.reader.ReaderViewModel
|
|
|
|
+import com.kdanmobile.reader.screen.adapter.OutlineAdapter
|
|
|
|
+import com.kdanmobile.reader.screen.handler.OutlineHandler
|
|
|
|
+import com.kdanmobile.reader.screen.handler.PdfInfoHandler
|
|
|
|
+import io.reactivex.Observable
|
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
|
+import io.reactivex.schedulers.Schedulers
|
|
|
|
+import kotlinx.android.synthetic.main.view_outline.view.*
|
|
|
|
+
|
|
|
|
+class OutlineView: RelativeLayout {
|
|
|
|
+ private lateinit var adapter: OutlineAdapter
|
|
|
|
+
|
|
|
|
+ constructor(context: Context, viewModel: ReaderViewModel) : super(context) {
|
|
|
|
+ initView(viewModel, viewModel)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constructor(context: Context, attributeSet: AttributeSet, viewModel: ReaderViewModel) : super(context, attributeSet) {
|
|
|
|
+ initView(viewModel, viewModel)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int, viewModel: ReaderViewModel) : super(context, attributeSet, defStyleAttr) {
|
|
|
|
+ initView(viewModel, viewModel)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun initView(pdfInfoHandler: PdfInfoHandler, outlineHandler: OutlineHandler) {
|
|
|
|
+ LayoutInflater.from(context).inflate(R.layout.view_outline, this)
|
|
|
|
+
|
|
|
|
+ lv_viewPdfReaderOutline_.setOnItemClickListener { parent, view, position, id ->
|
|
|
|
+ val item = adapter.getItem(position) as OutlineItem
|
|
|
|
+ pdfInfoHandler.setCurrentPage(item.page)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ val disposable = Observable.create<OutlineAdapter> {
|
|
|
|
+ val outlineItems = outlineHandler.getOutline()!!
|
|
|
|
+ val copyList = outlineItems.toList()
|
|
|
|
+ it.onNext(OutlineAdapter(copyList))
|
|
|
|
+ it.onComplete()
|
|
|
|
+ }
|
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
+ .subscribe({
|
|
|
|
+ adapter = it
|
|
|
|
+ lv_viewPdfReaderOutline_.adapter = adapter
|
|
|
|
+ }, {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|