13 Commits eb660a9a7b ... 64d44519a9

Autor SHA1 Mensaje Fecha
  Wayne Huang 64d44519a9 Merge branch '137-encryptPdf' into 'master' hace 4 años
  cooperku_kdanmobile 9d17dab765 Merge branch 'encryptCopyFile' into 137-encryptPdf hace 4 años
  cooperku_kdanmobile 71c8393eda Merge branch 'encryptStrings' into encryptCopyFile hace 4 años
  cooperku_kdanmobile e056903107 Remove ReaderViewModel::encrypt(String) hace 4 años
  cooperku_kdanmobile 0153d902dd Add translations hace 4 años
  GameJob 810e5d0bd7 Hide encrypt & decrypt when the current file is not pdf hace 4 años
  GameJob b4a00e8fca Remove log hace 4 años
  cooperku_kdanmobile db3a3092ed Fix ReaderModel::password hace 4 años
  cooperku_kdanmobile e660083378 Add encryptPdf / decryptPdf functions hace 4 años
  cooperku_kdanmobile d3393d9ae2 Add encrypt / decrypt in menu hace 4 años
  cooperku_kdanmobile 73ba7bcb64 Add @SuppressLint("NewApi") hace 4 años
  cooperku_kdanmobile ca9b73c961 Refactor: rename 'isPdf' to 'isNoPasswordProtectedPdf' hace 4 años
  cooperku_kdanmobile fc90f574b8 Add xml resources hace 4 años

+ 29 - 7
src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -69,6 +69,8 @@ abstract class ReaderActivity :
     abstract fun onClickFileInfo()
     abstract fun onClickIBonPrint()
     abstract fun onClickPrint()
+    abstract fun onClickEncrypt()
+    abstract fun onClickDecrypt()
     abstract fun onClickUserGuide()
     abstract fun provideReaderSettingDialogFragment(): ReaderSettingDialogFragment
     abstract fun providePdfThumbDialogFragment(): PdfThumbDialogFragment
@@ -273,11 +275,13 @@ abstract class ReaderActivity :
     }
 
     fun isPdf(): Boolean {
-        var isPdf = filePath?.toLowerCase(Locale.US)?.endsWith(".pdf") ?: false
+        return filePath?.toLowerCase(Locale.US)?.endsWith(".pdf") ?: false
+    }
+
+    fun isNoPasswordProtectedPdf(): Boolean {
         //  TODO this workaround should be removed in the future
         //  workaround: password-protected pdf is not editable
-        isPdf = isPdf && !isPasswordProtected
-        return isPdf
+        return isPdf() && !isPasswordProtected
     }
 
     final override fun onBackPressed() {
@@ -295,7 +299,7 @@ abstract class ReaderActivity :
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
             menu?.findItem(R.id.item_reader_more_print)?.isVisible = false
         }
-        if (!isPdf()) {
+        if (!isNoPasswordProtectedPdf()) {
             menu?.apply {
                 findItem(R.id.item_reader_more_text_reflow)?.isVisible = false
                 findItem(R.id.item_reader_more_clear_signature)?.isVisible = false
@@ -305,6 +309,19 @@ abstract class ReaderActivity :
             }
             menuItemBookmark?.isVisible = false
         }
+        menu?.apply {
+            val isPdf = isPdf()
+            when (password.isEmpty()) {
+                true -> {
+                    findItem(R.id.item_reader_more_encrypt)?.isVisible = isPdf
+                    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
+                }
+            }
+        }
         if (!isIBonPrintEnabled()) {
             menu?.findItem(R.id.item_ibon_print)?.isVisible = false
         }
@@ -628,6 +645,7 @@ abstract class ReaderActivity :
 //        return Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT
     }
 
+    @SuppressLint("NewApi")
     private fun showAllToolbars() {
         if (isBelowKitkat()) {
             val duration = ((1 - toolbar_readerActivity.alpha) * UI_ANIMATION_DURATION).toLong()
@@ -641,6 +659,7 @@ abstract class ReaderActivity :
         isHidePdfPage = true
     }
 
+    @SuppressLint("NewApi")
     private fun hideAllToolbars() {
         if (isBelowKitkat()) {
             val duration = (toolbar_readerActivity.alpha * UI_ANIMATION_DURATION).toLong()
@@ -654,6 +673,7 @@ abstract class ReaderActivity :
         }
     }
 
+    @SuppressLint("NewApi")
     private fun hideTopLeftBottomToolbars() {
         if (isBelowKitkat()) {
             val duration = (toolbar_readerActivity.alpha * UI_ANIMATION_DURATION).toLong()
@@ -718,6 +738,8 @@ abstract class ReaderActivity :
                 R.id.item_reader_more_file_info -> onClickFileInfo()
                 R.id.item_ibon_print -> onClickIBonPrint()
                 R.id.item_reader_more_print -> onClickPrint()
+                R.id.item_reader_more_encrypt -> onClickEncrypt()
+                R.id.item_reader_more_decrypt -> onClickDecrypt()
                 R.id.item_reader_more_user_guide -> onClickUserGuide()
                 R.id.item_reader_more_clear_signature -> onClickClearSignature()
             }
@@ -816,7 +838,7 @@ abstract class ReaderActivity :
         iv_readerActivity_outline.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.OUTLINE) }
         iv_readerActivity_search.setOnClickListener { onClickLeftToolbarItem(ReaderViewModel.LeftToolbarType.SEARCH) }
 
-        if (!isPdf()) {
+        if (!isNoPasswordProtectedPdf()) {
             iv_readerActivity_bookmark.visibility = View.GONE
             if (!isPasswordProtected) iv_readerActivity_outline.visibility = View.GONE
         }
@@ -955,7 +977,7 @@ abstract class ReaderActivity :
             onClickShare()
         }
 
-        if (!isPdf()) {
+        if (!isNoPasswordProtectedPdf()) {
             ib_readerActivity_bottomToolbarMediaBox.visibility = View.GONE
         }
     }
@@ -1161,7 +1183,7 @@ abstract class ReaderActivity :
             }
         }
 
-        if (!isPdf()) {
+        if (!isNoPasswordProtectedPdf()) {
             iv_readerActivity_highLight.visibility = View.GONE
             iv_readerActivity_strike.visibility = View.GONE
             iv_readerActivity_underline.visibility = View.GONE

+ 4 - 1
src/main/java/com/kdanmobile/reader/ReaderModel.kt

@@ -43,7 +43,10 @@ class ReaderModel {
 
         this.kmpdfFactory = kmpdfFactory
         this.filename = filename
-        this.password = password
+        this.password = when (kmpdfFactory?.needPassWord()) {
+            false -> ""
+            else -> password
+        }
         this.isInitialized = true
     }
 

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

@@ -177,7 +177,7 @@ abstract class PdfThumbDialogFragment:
                     val isExtractEnable = viewModel.hasSelectItem()
                     val isRotateEnable = viewModel.hasSelectItem()
                     val isDeleteEnable = viewModel.hasSelectItem() && !viewModel.isAllItemSelect()
-                    val visible = viewModel.isPdf
+                    val visible = viewModel.isNoPasswordProtectedPdf
                     menu.findItem(R.id.item_action_edit_thumb).isVisible = false
                     menu.findItem(R.id.item_action_select_all_thumb)
                             .setVisible(visible)
@@ -190,7 +190,7 @@ abstract class PdfThumbDialogFragment:
                             .setVisible(visible).isEnabled = isDeleteEnable
                 }
                 false -> {
-                    val visible = viewModel.isPdf
+                    val visible = viewModel.isNoPasswordProtectedPdf
                     menu.findItem(R.id.item_action_edit_thumb).isVisible = visible
                     menu.findItem(R.id.item_action_select_all_thumb).isVisible = false
                     menu.findItem(R.id.item_action_extract_thumb).isVisible = false

+ 3 - 3
src/main/java/com/kdanmobile/reader/thumb/PdfThumbViewModel.kt

@@ -25,7 +25,7 @@ class PdfThumbViewModel(private val readerModel: ReaderModel): ViewModel() {
     val mapSelect: MutableMap<Int, Boolean> = HashMap()
     var mode: Mode = normalMode
     var isEdit = false
-    var isPdf = false
+    var isNoPasswordProtectedPdf = false
 
     val pdfInfoHandler = readerModel.pdfInfoHandler
 
@@ -38,10 +38,10 @@ class PdfThumbViewModel(private val readerModel: ReaderModel): ViewModel() {
     val passwordHandler = readerModel.passwordHandler
 
     init {
-        isPdf = kmpdfFactory?.fileName?.toLowerCase(Locale.US)?.endsWith(".pdf") ?: false
+        isNoPasswordProtectedPdf = kmpdfFactory?.fileName?.toLowerCase(Locale.US)?.endsWith(".pdf") ?: false
         //  TODO this workaround should be removed in the future
         //  workaround: password-protected pdf is not editable
-        isPdf = isPdf && !(kmpdfFactory?.needPassWord() ?: false)
+        isNoPasswordProtectedPdf = isNoPasswordProtectedPdf && !(kmpdfFactory?.needPassWord() ?: false)
         pageCount = kmpdfDocumentController?.getDocumentPageCount(false) ?: 0
         setAllUnSelect()
     }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 10 - 0
src/main/res/drawable/ic_decrypt.xml


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 11 - 0
src/main/res/drawable/ic_encrypt.xml


+ 12 - 0
src/main/res/menu/reader_more.xml

@@ -37,6 +37,18 @@
         android:title="@string/reader_more_menu_print"
         app:showAsAction="withText">
     </item>
+    <item
+        android:id="@+id/item_reader_more_encrypt"
+        android:icon="@drawable/ic_encrypt"
+        android:title="@string/reader_more_menu_encrypt"
+        app:showAsAction="withText">
+    </item>
+    <item
+        android:id="@+id/item_reader_more_decrypt"
+        android:icon="@drawable/ic_decrypt"
+        android:title="@string/reader_more_menu_decrypt"
+        app:showAsAction="withText">
+    </item>
     <item
         android:id="@+id/item_reader_more_user_guide"
         android:icon="@drawable/ic_help_black_op60_24dp"

+ 2 - 0
src/main/res/values-de/strings.xml

@@ -108,4 +108,6 @@
     <string name="reader_clear_signature_dialog_msg">Sind Sie sicher, dass Sie alle Signaturen löschen möchten?</string>
     <string name="cannot_open_buffer">Datei kann nicht geöffnet werden</string>
     <string name="reader_more_menu_ibon">Drucken aus iBon</string>
+    <string name="reader_more_menu_encrypt">Verschlüsseln</string>
+    <string name="reader_more_menu_decrypt">Passwort entfernen</string>
 </resources>

+ 2 - 0
src/main/res/values-es/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">¿ Seguro que desea eliminar todas las firmas ?</string>
     <string name="cannot_open_buffer">No se puede abrir el archivo</string>
     <string name="reader_more_menu_ibon">Impresión desde ibon</string>
+    <string name="reader_more_menu_encrypt">Cifrar</string>
+    <string name="reader_more_menu_decrypt">Elimine contraseña</string>
 </resources>

+ 2 - 0
src/main/res/values-fr/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">Etes-vous sûre de vouloir supprimer toutes les signatures?</string>
     <string name="cannot_open_buffer">Nous ne pouvons ouvrir le fichier</string>
     <string name="reader_more_menu_ibon">Impression d\'ibon</string>
+    <string name="reader_more_menu_encrypt">Crypter</string>
+    <string name="reader_more_menu_decrypt">Supprimer Le Mot De Passe</string>
 </resources>

+ 2 - 0
src/main/res/values-it/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">"Sei sicuro di voler cancellare tutte le firme ? "</string>
     <string name="cannot_open_buffer">Impossibile aprire il file</string>
     <string name="reader_more_menu_ibon">Stampa da iBon</string>
+    <string name="reader_more_menu_encrypt">Encrypt</string>
+    <string name="reader_more_menu_decrypt">Rimuovi password</string>
 </resources>

+ 2 - 0
src/main/res/values-ja/strings.xml

@@ -106,4 +106,6 @@
     <string name="reader_clear_signature_dialog_msg">PDFから署名を削除しますか?</string>
     <string name="cannot_open_buffer">ファイルを開くことができません</string>
     <string name="reader_more_menu_ibon">ibon印刷する</string>
+    <string name="reader_more_menu_encrypt">エンクリプション</string>
+    <string name="reader_more_menu_decrypt">パスワードの削除</string>
 </resources>

+ 2 - 0
src/main/res/values-ko/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">모든 서명을 삭제하시겠습니까 ?</string>
     <string name="cannot_open_buffer">파일을 열 수 없습니다</string>
     <string name="reader_more_menu_ibon">ibon에서 인쇄</string>
+    <string name="reader_more_menu_encrypt">암호화</string>
+    <string name="reader_more_menu_decrypt">비밀번호 제거</string>
 </resources>

+ 2 - 0
src/main/res/values-pt/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">Você deseja excluir todas as assinaturas?</string>
     <string name="cannot_open_buffer">Não conseguimos abrir o arquivo</string>
     <string name="reader_more_menu_ibon">Imprimir a partir do iBon</string>
+    <string name="reader_more_menu_encrypt">Criptografar</string>
+    <string name="reader_more_menu_decrypt">Remover Senha</string>
 </resources>

+ 2 - 0
src/main/res/values-ru/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">Вы уверены , что хотите удалить все подписи ?</string>
     <string name="cannot_open_buffer">Не возможно открыть файл</string>
     <string name="reader_more_menu_ibon">Печать из ibon</string>
+    <string name="reader_more_menu_encrypt">Зашифровать</string>
+    <string name="reader_more_menu_decrypt">Удалить пароль</string>
 </resources>

+ 2 - 0
src/main/res/values-zh-rTW/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">是否要移除文件內所有簽名?</string>
     <string name="cannot_open_buffer">無法打開檔案</string>
     <string name="reader_more_menu_ibon">ibon雲端列印</string>
+    <string name="reader_more_menu_encrypt">加密</string>
+    <string name="reader_more_menu_decrypt">移除密碼</string>
 </resources>

+ 2 - 0
src/main/res/values-zh/strings.xml

@@ -107,4 +107,6 @@
     <string name="reader_clear_signature_dialog_msg">是否要移除文件内所有签名?</string>
     <string name="cannot_open_buffer">无法打开文档</string>
     <string name="reader_more_menu_ibon">ibon云端列印</string>
+    <string name="reader_more_menu_encrypt">加密</string>
+    <string name="reader_more_menu_decrypt">移除密码</string>
 </resources>

+ 2 - 0
src/main/res/values/strings.xml

@@ -7,6 +7,8 @@
     <string name="reader_more_menu_print">Print</string>
     <string name="reader_more_menu_file_info">File Info</string>
     <string name="reader_more_menu_clear_signature">"Clear Signature "</string>
+    <string name="reader_more_menu_encrypt">Encrypt</string>
+    <string name="reader_more_menu_decrypt">Remove Password</string>
     <string name="reader_more_menu_user_guide">User Guide</string>
     <string name="reader_more_menu_ibon">Print from ibon</string>
     <string name="reader_copy_text_success">The selected text has been saved to the clipboard!</string>