浏览代码

Merge remote-tracking branch 'origin/master'

cooperku_kdanmobile 5 年之前
父节点
当前提交
cfc42a205a

+ 20 - 3
app/src/main/java/com/kdanmobile/pdfreaderviewapp/MyReaderActivity.kt

@@ -1,12 +1,29 @@
 package com.kdanmobile.pdfreaderviewapp
 
-import android.content.Context
-import android.support.v7.app.AppCompatActivity
 import android.os.Bundle
 import com.kdanmobile.reader.ReaderActivity
-import java.io.File
 
 class MyReaderActivity : ReaderActivity() {
+    override fun onClickUserGuide() {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun onClickPrint() {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun onClickFileInfo() {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun onClickTextReflow() {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun onClickShare() {
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    }
+
     companion object {
         val KEY_FILE_ABSOLUTE = ReaderActivity.KEY_FILE_ABSOLUTE
     }

二进制
app/src/main/jniLibs/armeabi-v7a/libkmpdf.so


二进制
app/src/main/jniLibs/armeabi/libkmpdf.so


二进制
app/src/main/jniLibs/mips/libkmpdf.so


二进制
app/src/main/jniLibs/x86/libkmpdf.so


+ 1 - 1
reader/build.gradle

@@ -41,5 +41,5 @@ dependencies {
 
     testImplementation 'junit:junit:4.12'
 
-    api(name: 'kmpdfkit-1.0.7', ext: 'aar')
+    api(name: 'kmpdfkit-1.0.8', ext: 'aar')
 }

二进制
reader/libs/kmpdfkit-1.0.7.aar


+ 94 - 2
reader/src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -8,14 +8,25 @@ import android.os.Build
 import android.support.v7.app.AppCompatActivity
 import android.os.Bundle
 import android.support.constraint.ConstraintSet
+import android.support.v4.content.ContextCompat
+import android.support.v7.app.AlertDialog
 import android.view.Menu
+import android.view.MenuItem
 import android.view.View
+import android.widget.EditText
+import android.widget.LinearLayout
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
 import com.kdanmobile.reader.Utils.applyConstraintSet
 import kotlinx.android.synthetic.main.activity_reader.*
 import kotlin.Exception
 
-open class ReaderActivity : AppCompatActivity() {
+abstract class ReaderActivity : AppCompatActivity() {
+
+    abstract fun onClickShare()
+    abstract fun onClickTextReflow()
+    abstract fun onClickFileInfo()
+    abstract fun onClickPrint()
+    abstract fun onClickUserGuide()
 
     companion object {
         const val KEY_FILE_ABSOLUTE = "file_absolutepath"
@@ -27,12 +38,15 @@ open class ReaderActivity : AppCompatActivity() {
     private var isHideToolbar = false
     private lateinit var originConstraintSet: ConstraintSet
 
+    private var menuItemBookmark: MenuItem? = null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_reader)
         setSupportActionBar(toolbar_readerActivity)
 
         cloneOriginConstraintSet()
+        setupToolbar()
         setupBottomToolbar()
 
         val factory = ReaderViewModelFactory()
@@ -45,10 +59,13 @@ open class ReaderActivity : AppCompatActivity() {
             val uri = Uri.parse(filePath)
             viewModel.openPdfFile(this, uri, intent.type)
         }
+        viewModel.pageIndexLiveData.observe(this, Observer(this::onPageIndexChanged))
+        viewModel.isPageInBookmarksLiveData.observe(this, Observer(this::onIsPageInBookmarksChanged))
     }
 
     override fun onCreateOptionsMenu(menu: Menu?): Boolean {
         menuInflater.inflate(R.menu.reader_more, menu)
+        menuItemBookmark = menu?.findItem(R.id.item_reader_bookmark)
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
             menu?.findItem(R.id.item_reader_more_print)?.isVisible = false
         }
@@ -75,7 +92,6 @@ open class ReaderActivity : AppCompatActivity() {
                 method.invoke(it, true)
             } catch (e: Exception) {
                 // Do nothing
-                println(e.message)
             }
         }
         return super.onPrepareOptionsPanel(view, menu)
@@ -102,11 +118,33 @@ open class ReaderActivity : AppCompatActivity() {
                 }
                 isHideToolbar = !isHideToolbar
             }
+
+            override fun onMoveToChild(p0: Int) {
+                super.onMoveToChild(p0)
+
+                viewModel.setPageIndex(p0)
+            }
         }
         viewModel.setReaderView(readerView)
         container.addView(readerView)
     }
 
+    private fun onPageIndexChanged(pageIndex: Int?) {
+        pageIndex?.let {
+            viewModel.setBookmarkDisplay(pageIndex)
+        }
+    }
+
+    private fun onIsPageInBookmarksChanged(isPageInBookmarks: Boolean?) {
+        isPageInBookmarks?.let {
+            if (it) {
+                menuItemBookmark?.icon = ContextCompat.getDrawable(this, R.drawable.ic_bookmark)
+            } else {
+                menuItemBookmark?.icon = ContextCompat.getDrawable(this, R.drawable.ic_bookmark_border)
+            }
+        }
+    }
+
     private fun showAllToolbars() {
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
             // TODO : Implement show toolbars on Android api level < 19 devices
@@ -131,6 +169,60 @@ open class ReaderActivity : AppCompatActivity() {
         }
     }
 
+    private fun setupToolbar() {
+        toolbar_readerActivity.setOnMenuItemClickListener {
+            when (it.itemId) {
+                R.id.item_reader_bookmark -> onClickBookmark()
+                R.id.item_reader_more_share -> onClickShare()
+                R.id.item_reader_more_text_reflow -> onClickTextReflow()
+                R.id.item_reader_more_file_info -> onClickFileInfo()
+                R.id.item_reader_more_print -> onClickPrint()
+                R.id.item_reader_more_user_guide -> onClickUserGuide()
+            }
+            return@setOnMenuItemClickListener true
+        }
+    }
+
+    private fun onClickBookmark() {
+        viewModel.isPageInBookmarksLiveData.value?.let {
+            if (!it) {
+                showAddBookmarkDialog()
+            } else {
+                showDeleteBookmarkDialog()
+            }
+        }
+    }
+
+    private fun showAddBookmarkDialog() {
+        val alertDialogBuilder = AlertDialog.Builder(this)
+        val editText = EditText(this)
+        val layoutParams =
+                LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)
+
+        editText.layoutParams = layoutParams
+
+        alertDialogBuilder.setTitle(getString(R.string.reader_alert_dialog_title_add_bookmark))
+        alertDialogBuilder.setView(editText)
+        alertDialogBuilder.setPositiveButton(getString(R.string.reader_alert_dialog_button_confirm)) { dialog, which ->
+            viewModel.addBookmark(editText.text.toString())
+        }
+        alertDialogBuilder.setNegativeButton(getString(R.string.reader_alert_dialog_button_cancel)) { dialog, which ->
+        }
+        alertDialogBuilder.create().show()
+    }
+
+    private fun showDeleteBookmarkDialog() {
+        val alertDialogBuilder = AlertDialog.Builder(this)
+        alertDialogBuilder.setTitle(getString(R.string.reader_alert_dialog_title_delete_bookmark))
+        alertDialogBuilder.setMessage(getString(R.string.reader_alert_dialog_message_delete_bookmark))
+        alertDialogBuilder.setPositiveButton(getString(R.string.reader_alert_dialog_button_confirm)) { dialog, which ->
+            viewModel.deleteBookmark()
+        }
+        alertDialogBuilder.setNegativeButton(getString(R.string.reader_alert_dialog_button_cancel)) { dialog, which ->
+        }
+        alertDialogBuilder.create().show()
+    }
+
     private fun setupBottomToolbar() {
         val context = this
         /** Set buttons color **/

+ 42 - 0
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -1,5 +1,6 @@
 package com.kdanmobile.reader
 
+import android.arch.lifecycle.LiveData
 import android.arch.lifecycle.MutableLiveData
 import android.arch.lifecycle.ViewModel
 import android.content.Context
@@ -37,6 +38,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     val isOpenedFileLiveData = MutableLiveData<Boolean>().apply { value = false }
     val fileNameLiveData = MutableLiveData<String>()
 
+    val pageIndexLiveData: LiveData<Int>
+        get() = mPageIndexLiveData
+    val isPageInBookmarksLiveData: LiveData<Boolean>
+        get() = mIsPageInBookmarksLiveData
+
+    private val mPageIndexLiveData = MutableLiveData<Int>().apply { value = 0 }
+    private val mIsPageInBookmarksLiveData = MutableLiveData<Boolean>().apply { value = false }
+
     @JvmOverloads
     fun openPdfFile(context: Context, uri: Uri, type: String? = null): Boolean {
         if (!isVerified) {
@@ -144,6 +153,39 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         updateViewDirection()
     }
 
+    fun setPageIndex(pageIndex: Int){
+        mPageIndexLiveData.value = pageIndex
+    }
+
+    fun addBookmark(title: String) {
+        pageIndexLiveData.value?.let {
+            kmpdfDocumentController?.addBookmark(title, it)
+            setBookmarkDisplay(it)
+        }
+    }
+
+    fun deleteBookmark() {
+        pageIndexLiveData.value?.let {
+            kmpdfDocumentController?.deleteBookmarks(it)
+            setBookmarkDisplay(it)
+        }
+    }
+
+    fun setBookmarkDisplay(pageIndex: Int) {
+        kmpdfDocumentController?.let {
+            var isPageInBookmarks = false
+            it.bookmarks?.let {
+                for (bookmark in it) {
+                    if (bookmark.pageNum == pageIndex) {
+                        isPageInBookmarks = true
+                        break
+                    }
+                }
+            }
+            mIsPageInBookmarksLiveData.value = isPageInBookmarks
+        }
+    }
+
     private fun verifyLicense(context: Context): Boolean {
         val errorCode = KMPDFFactory.verifyLicense(context, pdfSdkLicense, pdfSdkRsaMsg)
         return errorCode == 0

+ 6 - 0
reader/src/main/res/menu/reader_more.xml

@@ -1,6 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item
+        android:id="@+id/item_reader_bookmark"
+        android:icon="@drawable/ic_bookmark_border"
+        android:title="@string/reader_more_menu_bookmark"
+        app:showAsAction="ifRoom"
+        />
     <item
         android:id="@+id/item_reader_more_share"
         android:icon="@drawable/ic_share_black_op60_24dp"

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">"Teilen  "</string>
     <string name="reader_more_menu_text_reflow">Text Rückfluss</string>
     <string name="reader_more_menu_print">Drucken</string>
+    <string name="reader_more_menu_bookmark">Lesezeichen</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Lesezeichen hinzufügen</string>
+    <string name="reader_alert_dialog_button_confirm">Bestätigen</string>
+    <string name="reader_alert_dialog_button_cancel">Abbrechen</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Lesezeichen löschen</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Sind Sie sicher, dass Sie %s löschen wollen?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">Compartir</string>
     <string name="reader_more_menu_text_reflow">Herramienta de marcado</string>
     <string name="reader_more_menu_print">Borrar firma</string>
+    <string name="reader_more_menu_bookmark">Marcador</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Añadir marcador</string>
+    <string name="reader_alert_dialog_button_confirm">Confirmar</string>
+    <string name="reader_alert_dialog_button_cancel">Cancelar</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Eliminar marcador</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">¿Seguro que deseas eliminar %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">Partager</string>
     <string name="reader_more_menu_text_reflow">Text Reflow</string>
     <string name="reader_more_menu_print">Imprimer</string>
+    <string name="reader_more_menu_bookmark">Marquer la page</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Ajouter un marque page</string>
+    <string name="reader_alert_dialog_button_confirm">Confirmer</string>
+    <string name="reader_alert_dialog_button_cancel">Annuler</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Supprimer un marque page</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Etes-vous sûre de vouloir supprimer %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">Condividere</string>
     <string name="reader_more_menu_text_reflow">Testo riflusso</string>
     <string name="reader_more_menu_print">Stampa</string>
+    <string name="reader_more_menu_bookmark">Segnalibro</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Aggiungi segnalibro</string>
+    <string name="reader_alert_dialog_button_confirm">Conferma</string>
+    <string name="reader_alert_dialog_button_cancel">Cancella</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Elimina segnalibro</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Sei sicuro di voler cancellare %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_print">印刷</string>
     <string name="reader_more_menu_file_info">ファイル内容</string>
     <string name="reader_more_menu_user_guide">ユーザーガイド</string>
+    <string name="reader_more_menu_bookmark">ブックマーク</string>
+    <string name="reader_alert_dialog_title_add_bookmark">ブックマークを作成する</string>
+    <string name="reader_alert_dialog_button_confirm">確定</string>
+    <string name="reader_alert_dialog_button_cancel">キャンセル</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">ブックマークを削除する</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">「%s」のブックマークを削除しますか?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">공유</string>
     <string name="reader_more_menu_text_reflow">텍스트 리플로우</string>
     <string name="reader_more_menu_print">인쇄</string>
+    <string name="reader_more_menu_bookmark">북마크</string>
+    <string name="reader_alert_dialog_title_add_bookmark">북마크 추가</string>
+    <string name="reader_alert_dialog_button_confirm">확인</string>
+    <string name="reader_alert_dialog_button_cancel">취소</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">북마크 삭제</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">%s 를 삭제하시겠습니까?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">Compartilhar</string>
     <string name="reader_more_menu_text_reflow">Refluxo de texto</string>
     <string name="reader_more_menu_print">Imprimir</string>
+    <string name="reader_more_menu_bookmark">Marcador</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Adicionar marcador</string>
+    <string name="reader_alert_dialog_button_confirm">Confirmar</string>
+    <string name="reader_alert_dialog_button_cancel">Cancelar</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Apagar marcador</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Você tem certeza que quer apagar %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_share">Поделиться</string>
     <string name="reader_more_menu_text_reflow">Перенаправить Текст</string>
     <string name="reader_more_menu_print">Печать</string>
+    <string name="reader_more_menu_bookmark">Закладка</string>
+    <string name="reader_alert_dialog_title_add_bookmark">Добавить закладку</string>
+    <string name="reader_alert_dialog_button_confirm">Подтвердить</string>
+    <string name="reader_alert_dialog_button_cancel">Отменить</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Удалить закладку</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Вы уверены что хотите удалить %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_print">列印</string>
     <string name="reader_more_menu_file_info">文件資訊</string>
     <string name="reader_more_menu_user_guide">使用指南</string>
+    <string name="reader_more_menu_bookmark">書籤</string>
+    <string name="reader_alert_dialog_title_add_bookmark">新增書籤</string>
+    <string name="reader_alert_dialog_button_confirm">確定</string>
+    <string name="reader_alert_dialog_button_cancel">取消</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">刪除書籤</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">確定刪除書籤 %s ?</string>
 </resources>

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

@@ -5,4 +5,10 @@
     <string name="reader_more_menu_print">打印</string>
     <string name="reader_more_menu_file_info">文件信息</string>
     <string name="reader_more_menu_user_guide">使用导航</string>
+    <string name="reader_more_menu_bookmark">书签</string>
+    <string name="reader_alert_dialog_title_add_bookmark">添加书签</string>
+    <string name="reader_alert_dialog_button_confirm">确定</string>
+    <string name="reader_alert_dialog_button_cancel">取消</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">删除书签</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">确定删除书签 %s ?</string>
 </resources>

+ 7 - 0
reader/src/main/res/values/strings.xml

@@ -1,9 +1,16 @@
 <resources>
     <string name="app_name" translatable="false">Reader</string>
 
+    <string name="reader_more_menu_bookmark">Bookmark</string>
     <string name="reader_more_menu_share">Share</string>
     <string name="reader_more_menu_text_reflow">Text Reflow</string>
     <string name="reader_more_menu_print">Print</string>
     <string name="reader_more_menu_file_info">File Info</string>
     <string name="reader_more_menu_user_guide">User Guide</string>
+
+    <string name="reader_alert_dialog_title_add_bookmark">Add bookmark</string>
+    <string name="reader_alert_dialog_title_delete_bookmark">Delete bookmark</string>
+    <string name="reader_alert_dialog_message_delete_bookmark">Are you sure you want to delete %s ?</string>
+    <string name="reader_alert_dialog_button_confirm">Confirm</string>
+    <string name="reader_alert_dialog_button_cancel">Cancel</string>
 </resources>