Browse Source

Merge branch '151-hide365' into 'master'

Resolve "隱藏365相關功能"

See merge request android/module/pdfreadermodule!79
黃笠維 4 years ago
parent
commit
7b3deba458

+ 4 - 3
src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -89,6 +89,7 @@ abstract class ReaderActivity :
     open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
     open fun onOpenedFile() { /* do nothing */ }
     open fun onFilePathOrUriError(filePath: String?) { println("onFilePathOrUriError: $filePath") }
+    open fun shouldShowEncryptDecrypt(): Boolean { return true }
     //  子類別可複寫此方法以客製化KMPDFPageAdapter
     abstract fun providePdfPageAdapter(context: Context, filePickerSupport: FilePicker.FilePickerSupport, kmpdfFactory: KMPDFFactory): KMPDFPageAdapter
     open fun provideAdditionalPageManager(): AdditionalPageManager = AdditionalPageManager()
@@ -310,15 +311,15 @@ abstract class ReaderActivity :
             menuItemBookmark?.isVisible = false
         }
         menu?.apply {
-            val isPdf = isPdf()
+            val isVisible = isPdf() && shouldShowEncryptDecrypt()
             when (!isPasswordProtected) {
                 true -> {
-                    findItem(R.id.item_reader_more_encrypt)?.isVisible = isPdf
+                    findItem(R.id.item_reader_more_encrypt)?.isVisible = isVisible
                     findItem(R.id.item_reader_more_decrypt)?.isVisible = false
                 }
                 false -> {
                     findItem(R.id.item_reader_more_encrypt)?.isVisible = false
-                    findItem(R.id.item_reader_more_decrypt)?.isVisible = isPdf
+                    findItem(R.id.item_reader_more_decrypt)?.isVisible = isVisible
                 }
             }
         }

+ 16 - 0
src/main/java/com/kdanmobile/reader/screen/view/ReadingModeSelectView.kt

@@ -42,6 +42,12 @@ class ReadingModeSelectView : ConstraintLayout {
             }
         }
 
+    var nightAndSoftThemeVisible: Boolean = true
+        set(value) {
+            field = value
+            setReadModeBtnVisible(field)
+        }
+
     var isLock: Boolean = false
         set(value) {
             field = value
@@ -117,4 +123,14 @@ class ReadingModeSelectView : ConstraintLayout {
             iv_readingMode_soft_lock?.visibility = View.INVISIBLE
         }
     }
+
+    private fun setReadModeBtnVisible(isVisible: Boolean) {
+        if (isVisible) {
+            btn_readingMode_night?.visibility = View.VISIBLE
+            btn_readingMode_soft?.visibility = View.VISIBLE
+        } else {
+            btn_readingMode_night?.visibility = View.INVISIBLE
+            btn_readingMode_soft?.visibility = View.INVISIBLE
+        }
+    }
 }

+ 10 - 0
src/main/java/com/kdanmobile/reader/setting/ReaderSettingDialogFragment.kt

@@ -32,6 +32,9 @@ open class ReaderSettingDialogFragment : DialogFragment() {
         get() = if (activity is ReaderSettingListener) (activity as ReaderSettingListener) else null
     private var initialized = true
 
+
+    protected open fun shouldShowSmartCrop(): Boolean { return true }
+    protected open fun shouldShowNightAndSoftTheme(): Boolean { return true }
     protected open fun hasPermissionToUseSmartCrop(): Boolean { return false }
     protected open fun hasPermissionToChangeTheme(): Boolean { return false }
     protected open fun onNoPermissionToUseSmartCrop() {}
@@ -97,6 +100,13 @@ open class ReaderSettingDialogFragment : DialogFragment() {
         setupScreenSettingView()
         setupToolbarSettingView()
 
+        if (!shouldShowSmartCrop()) {
+            rowSwitchView_smartCrop.visibility = View.GONE
+        }
+        if (!shouldShowNightAndSoftTheme()) {
+            readingModeSelectView.nightAndSoftThemeVisible = false
+        }
+
         rowSwitchView_smartCrop.onCheckedChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked ->
             if (viewModel.isCropModeEnable.value == isChecked) return@OnCheckedChangeListener
             if (isChecked && !hasPermissionToUseSmartCrop()) {

+ 10 - 2
src/main/java/com/kdanmobile/reader/thumb/PdfThumbDialogFragment.kt

@@ -44,6 +44,8 @@ abstract class PdfThumbDialogFragment:
     abstract fun getColumns(): Int
     abstract fun getCreateExtractBlankFile(pdfFilename: String, selectPage: String): File
     abstract fun getKdanPdfReaderFolder(): File
+    open fun shouldShowDelete(): Boolean { return true }
+    open fun shouldShowExtract(): Boolean { return true }
 
     private val readerViewModel: ReaderViewModel by sharedViewModel()
     private val viewModel: PdfThumbViewModel by viewModel { parametersOf(readerViewModel.readerModel) }
@@ -172,8 +174,8 @@ abstract class PdfThumbDialogFragment:
     }
 
     private fun invalidateOptionsMenu() {
+        val menu = toolbar_pdfThumb.menu
         if (!viewModel.passwordHandler.isNeedPassword()) {
-            val menu = toolbar_pdfThumb.menu
             when (viewModel.isEdit) {
                 true -> {
                     val isExtractEnable = viewModel.hasSelectItem()
@@ -201,13 +203,19 @@ abstract class PdfThumbDialogFragment:
                 }
             }
         } else {
-            val menu = toolbar_pdfThumb.menu
             menu.findItem(R.id.item_action_edit_thumb).isVisible = false
             menu.findItem(R.id.item_action_select_all_thumb).isVisible = false
             menu.findItem(R.id.item_action_extract_thumb).isVisible = false
             menu.findItem(R.id.item_action_rorate_thumb).isVisible = false
             menu.findItem(R.id.item_action_delete_thumb).isVisible = false
         }
+
+        if (!shouldShowDelete()) {
+            menu.findItem(R.id.item_action_delete_thumb).isVisible = false
+        }
+        if (!shouldShowExtract()) {
+            menu.findItem(R.id.item_action_extract_thumb).isVisible = false
+        }
     }
 
     override fun onStop() {