فهرست منبع

Merge branch 'saveCurrentPageIndex'

cooperku_kdanmobile 6 سال پیش
والد
کامیت
dc980a4e75
1فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 13 1
      src/main/java/com/kdanmobile/reader/ReaderActivity.kt

+ 13 - 1
src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -62,6 +62,9 @@ abstract class ReaderActivity : AppCompatActivity() {
     abstract fun transferThumbIntent(): Intent
     abstract fun provideReaderSettingDialogFragment(): ReaderSettingDialogFragment
 
+    open fun saveCurrentPageIndex(filename: String, currentPage: Int) {}
+    open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
+
     companion object {
         const val KEY_FILE_ABSOLUTE = "file_absolutepath"
         const val THUMB = 221
@@ -131,6 +134,7 @@ abstract class ReaderActivity : AppCompatActivity() {
         setContentView(R.layout.activity_reader)
         setSupportActionBar(toolbar_readerActivity)
         isShowPasswordActivity = savedInstanceState?.getBoolean("isShowPasswordActivity") ?: false
+        filePath = savedInstanceState?.getString("filePath")
 
         val displayMetrics = DisplayMetrics()
         windowManager.defaultDisplay.getMetrics(displayMetrics)
@@ -190,6 +194,7 @@ abstract class ReaderActivity : AppCompatActivity() {
     override fun onSaveInstanceState(outState: Bundle?) {
         super.onSaveInstanceState(outState)
         outState?.putBoolean("isShowPasswordActivity", isShowPasswordActivity)
+        outState?.putString("filePath", filePath)
     }
 
     private fun requestPassword(isIncorrectPassword: Boolean = false) {
@@ -397,7 +402,11 @@ abstract class ReaderActivity : AppCompatActivity() {
             }
         }
         viewModel.setReaderView(readerView)
-        viewModel.pdfInfoHandler.setCurrentPage(viewModel.pageIndexLiveData.value ?: 0)
+        if (!filePath.isNullOrEmpty()) {
+            val defaultValue = viewModel.pageIndexLiveData.value ?: 0
+            val pageIndex = loadCurrentPageIndex(filePath as String, defaultValue)
+            viewModel.pdfInfoHandler.setCurrentPage(pageIndex)
+        }
         initTextBoxContextMenuActions()
         container.addView(readerView)
         if (SharePrefsModel(this).isCropModeEnable.value == true) {
@@ -439,6 +448,9 @@ abstract class ReaderActivity : AppCompatActivity() {
     override fun onStop() {
         viewModel.saveModifyingAnnotation()
         viewModel.temporarySave()
+        if (!filePath.isNullOrEmpty()) {
+            saveCurrentPageIndex(filePath as String, currentPageIndex)
+        }
         super.onStop()
     }