Ver código fonte

New: toolbar menu each item click listener to abstract method

liweihao 5 anos atrás
pai
commit
7a7bf41e8b

+ 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
     }

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

@@ -15,7 +15,13 @@ 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"
@@ -33,6 +39,7 @@ open class ReaderActivity : AppCompatActivity() {
         setSupportActionBar(toolbar_readerActivity)
 
         cloneOriginConstraintSet()
+        setupToolbar()
         setupBottomToolbar()
 
         val factory = ReaderViewModelFactory()
@@ -130,6 +137,19 @@ open class ReaderActivity : AppCompatActivity() {
         }
     }
 
+    private fun setupToolbar() {
+        toolbar_readerActivity.setOnMenuItemClickListener {
+            when (it.itemId) {
+                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 setupBottomToolbar() {
         val context = this
         /** Set buttons color **/