Browse Source

Add some event hooks

Wayne 5 years ago
parent
commit
3a17f3b39d
1 changed files with 25 additions and 1 deletions
  1. 25 1
      src/main/java/com/kdanmobile/reader/ReaderActivity.kt

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

@@ -72,6 +72,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
     open fun loadCurrentPageIndex(filename: String, defaultValue: Int): Int = 0
     open fun onOpenedFile() { /* do nothing */ }
     open fun onFilePathOrUriError(filePath: String?) { println("onFilePathOrUriError: $filePath") }
+    protected open fun onEvent(hookEvent: HookEvent) { /* do nothing */ }
 
     companion object {
         const val KEY_FILE_ABSOLUTE = "file_absolutepath"
@@ -677,6 +678,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
     }
 
     private fun onClickBookmark() {
+        onEvent(HookEvent.OnClickTopBookmarkBtn())
         viewModel.isPageInBookmarksLiveData.value?.let {
             if (!it) {
                 showAddBookmarkDialog()
@@ -871,17 +873,23 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
     }
 
     private fun setupBottomToolbar() {
-        ib_readerActivity_bottomToolbarMediaBox.setOnClickListener { mediaBoxView.show() }
+        ib_readerActivity_bottomToolbarMediaBox.setOnClickListener {
+            onEvent(HookEvent.OnClickBottomMediaBoxBtn())
+            mediaBoxView.show()
+        }
         ib_readerActivity_bottomToolbarViewAll.setOnClickListener {
+            onEvent(HookEvent.OnClickBottomThumbnailBtn())
             onClickBottomThumb1()
         }
         ib_readerActivity_bottomToolbarPrevious.setOnClickListener {
+            onEvent(HookEvent.OnClickBottomPreviousBtn())
             val handler = viewModel.pdfInfoHandler
             val pageIndex = handler.getCurrentPage()
             val previousPageIndex = Math.max(pageIndex - 1, 0)
             handler.goToCurrentPage(previousPageIndex)
         }
         ib_readerActivity_bottomToolbarNext.setOnClickListener {
+            onEvent(HookEvent.OnClickBottomNextBtn())
             val handler = viewModel.pdfInfoHandler
             val pageIndex = handler.getCurrentPage()
             val nextPageIndex = Math.min(pageIndex + 1, handler.getPdfPageCount() - 1)
@@ -977,6 +985,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
                     }
                     window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
                         override fun onChange(annotationAttributeView: AnnotationAttributeView) {
+                            onEvent(HookEvent.OnUserChangeHighlightPropertySuccess())
                             viewModel.setHighLightAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
@@ -1004,6 +1013,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
                     }
                     window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
                         override fun onChange(annotationAttributeView: AnnotationAttributeView) {
+                            onEvent(HookEvent.OnUserChangeStrikeoutPropertySuccess())
                             viewModel.setStrikeOutAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
@@ -1031,6 +1041,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
                     }
                     window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
                         override fun onChange(annotationAttributeView: AnnotationAttributeView) {
+                            onEvent(HookEvent.OnUserChangeUnderlinePropertySuccess())
                             viewModel.setUnderLineAttributes(annotationAttributeView.annotationAttribute)
                         }
                     }
@@ -1065,6 +1076,7 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
                     }
                     window.annotationAttributeView.onChangeListener = object : AnnotationAttributeView.OnChangeListener {
                         override fun onChange(annotationAttributeView: AnnotationAttributeView) {
+                            onEvent(HookEvent.OnUserChangeInkPropertySuccess())
                             viewModel.setInkAttributes(annotationAttributeView.inkAttribute)
                         }
                     }
@@ -1232,4 +1244,16 @@ abstract class ReaderActivity : KdanBaseActivity(), ReaderSettingListener, PdfTh
             }
         }
     }
+
+    protected sealed class HookEvent {
+        class OnClickTopBookmarkBtn : HookEvent()
+        class OnClickBottomPreviousBtn : HookEvent()
+        class OnClickBottomNextBtn : HookEvent()
+        class OnClickBottomMediaBoxBtn : HookEvent()
+        class OnClickBottomThumbnailBtn : HookEvent()
+        class OnUserChangeHighlightPropertySuccess : HookEvent()
+        class OnUserChangeStrikeoutPropertySuccess : HookEvent()
+        class OnUserChangeUnderlinePropertySuccess : HookEvent()
+        class OnUserChangeInkPropertySuccess : HookEvent()
+    }
 }