فهرست منبع

Fixed strike, underline, ink icon color not work

Wayne 5 سال پیش
والد
کامیت
dd6111021e

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

@@ -25,6 +25,9 @@ import android.view.View
 import android.widget.EditText
 import android.widget.LinearLayout
 import android.widget.TextView
+import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
+import com.kdanmobile.reader.annotationattribute.AnnotationColor
+import com.kdanmobile.reader.annotationattribute.InkAttribute
 import com.kdanmobile.reader.screen.view.BookmarkView
 import com.kdanmobile.reader.screen.view.OutlineView
 import com.kdanmobile.reader.screen.view.SearchView
@@ -92,10 +95,10 @@ abstract class ReaderActivity : AppCompatActivity() {
         viewModel.fileNameLiveData.observe(this, Observer { tv_readerActivity_title.text = it })
         viewModel.annotationModeLiveData.observe(this, Observer(this::onAnnotationModeUpdate))
         viewModel.isCopyModeLiveData.observe(this, Observer (this::onIsCopyModeUpdate))
-        viewModel.highLightAttributeLiveData.observe(this, Observer {
-            if (it == null) return@Observer
-            view_readerActivity_highLightStroke.setBackgroundColor(it.color)
-        })
+        viewModel.highLightAttributeLiveData.observe(this, Observer(this::onHighlightAttributeUpdate))
+        viewModel.strikeAttributeLiveData.observe(this, Observer(this::onStrikeAttributeUpdate))
+        viewModel.underLineAttributeLiveData.observe(this, Observer(this::onUnderlineAttributeUpdate))
+        viewModel.inkAttributeLiveData.observe(this, Observer(this::onInkAttributeUpdate))
         viewModel.isOpenedFileLiveData.value?.also { isOpened ->
             if (isOpened) return@also
             val filePath = intent.getStringExtra(KEY_FILE_ABSOLUTE)
@@ -164,6 +167,44 @@ abstract class ReaderActivity : AppCompatActivity() {
         }
     }
 
+    private fun onHighlightAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
+        if (annotationAttribute == null) return
+        view_readerActivity_highLightStroke.setBackgroundColor(annotationAttribute.color)
+    }
+
+    private fun onStrikeAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
+        if (annotationAttribute == null) return
+        view_readerActivity_strikeStroke.setBackgroundColor(annotationAttribute.color)
+    }
+
+    private fun onUnderlineAttributeUpdate(annotationAttribute: AnnotationAttribute?) {
+        if (annotationAttribute == null) return
+        view_readerActivity_underlineStroke.setBackgroundColor(annotationAttribute.color)
+    }
+
+    private fun onInkAttributeUpdate(inkAttribute: InkAttribute?) {
+        if (inkAttribute == null) return
+        val color = inkAttribute.color
+        AnnotationColor.values().forEach {
+            if (resources.getColor(it.colorResId) == color) {
+                val drawableResId = when (it) {
+                    AnnotationColor.Color1 -> R.drawable.ic_tool_freehand_s1
+                    AnnotationColor.Color2 -> R.drawable.ic_tool_freehand_s2
+                    AnnotationColor.Color3 -> R.drawable.ic_tool_freehand_s3
+                    AnnotationColor.Color4 -> R.drawable.ic_tool_freehand_s4
+                    AnnotationColor.Color5 -> R.drawable.ic_tool_freehand_s5
+                    AnnotationColor.Color6 -> R.drawable.ic_tool_freehand_s6
+                    AnnotationColor.Color7 -> R.drawable.ic_tool_freehand_s7
+                    AnnotationColor.Color8 -> R.drawable.ic_tool_freehand_s8
+                    AnnotationColor.Color9 -> R.drawable.ic_tool_freehand_s9
+                    AnnotationColor.Color10 -> R.drawable.ic_tool_freehand_s10
+                }
+                iv_readerActivity_inkStroke.setImageResource(drawableResId)
+                return
+            }
+        }
+    }
+
     private fun onAnnotationModeUpdate(annotationMode: ReaderViewModel.AnnotationMode?) {
         if (annotationMode == null) return
         val map = HashMap<ReaderViewModel.AnnotationMode, View>().apply {

+ 16 - 0
reader/src/main/java/com/kdanmobile/reader/annotationattribute/AnnotationColor.kt

@@ -0,0 +1,16 @@
+package com.kdanmobile.reader.annotationattribute
+
+import com.kdanmobile.reader.R
+
+enum class AnnotationColor(val colorResId: Int) {
+    Color1(R.color.reader_annotation_color_1),
+    Color2(R.color.reader_annotation_color_2),
+    Color3(R.color.reader_annotation_color_3),
+    Color4(R.color.reader_annotation_color_4),
+    Color5(R.color.reader_annotation_color_5),
+    Color6(R.color.reader_annotation_color_6),
+    Color7(R.color.reader_annotation_color_7),
+    Color8(R.color.reader_annotation_color_8),
+    Color9(R.color.reader_annotation_color_9),
+    Color10(R.color.reader_annotation_color_10),
+}

+ 14 - 25
reader/src/main/java/com/kdanmobile/reader/view/AnnotationAttributeView.kt

@@ -12,6 +12,7 @@ import android.widget.SeekBar
 import com.kdanmobile.reader.R
 import com.kdanmobile.reader.Utils
 import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
+import com.kdanmobile.reader.annotationattribute.AnnotationColor
 import com.kdanmobile.reader.annotationattribute.Brush
 import com.kdanmobile.reader.annotationattribute.InkAttribute
 import kotlinx.android.synthetic.main.view_reader_annotation_property.view.*
@@ -27,18 +28,6 @@ class AnnotationAttributeView @JvmOverloads constructor(
         const val DEFAULT_THICKNESS = 5
     }
 
-    private enum class Color(val colorResId: Int) {
-        Color1(R.color.reader_annotation_color_1),
-        Color2(R.color.reader_annotation_color_2),
-        Color3(R.color.reader_annotation_color_3),
-        Color4(R.color.reader_annotation_color_4),
-        Color5(R.color.reader_annotation_color_5),
-        Color6(R.color.reader_annotation_color_6),
-        Color7(R.color.reader_annotation_color_7),
-        Color8(R.color.reader_annotation_color_8),
-        Color9(R.color.reader_annotation_color_9),
-        Color10(R.color.reader_annotation_color_10),
-    }
 
     init {
         inflate(context, R.layout.view_reader_annotation_property, this)
@@ -67,17 +56,17 @@ class AnnotationAttributeView @JvmOverloads constructor(
             update()
         }
     var onChangeListener: OnChangeListener? = null
-    private val colorBtnMap = HashMap<Color, ImageView>().apply {
-        put(Color.Color1, iv_readerAnnotationProperty_color1)
-        put(Color.Color2, iv_readerAnnotationProperty_color2)
-        put(Color.Color3, iv_readerAnnotationProperty_color3)
-        put(Color.Color4, iv_readerAnnotationProperty_color4)
-        put(Color.Color5, iv_readerAnnotationProperty_color5)
-        put(Color.Color6, iv_readerAnnotationProperty_color6)
-        put(Color.Color7, iv_readerAnnotationProperty_color7)
-        put(Color.Color8, iv_readerAnnotationProperty_color8)
-        put(Color.Color9, iv_readerAnnotationProperty_color9)
-        put(Color.Color10, iv_readerAnnotationProperty_color10)
+    private val colorBtnMap = HashMap<AnnotationColor, ImageView>().apply {
+        put(AnnotationColor.Color1, iv_readerAnnotationProperty_color1)
+        put(AnnotationColor.Color2, iv_readerAnnotationProperty_color2)
+        put(AnnotationColor.Color3, iv_readerAnnotationProperty_color3)
+        put(AnnotationColor.Color4, iv_readerAnnotationProperty_color4)
+        put(AnnotationColor.Color5, iv_readerAnnotationProperty_color5)
+        put(AnnotationColor.Color6, iv_readerAnnotationProperty_color6)
+        put(AnnotationColor.Color7, iv_readerAnnotationProperty_color7)
+        put(AnnotationColor.Color8, iv_readerAnnotationProperty_color8)
+        put(AnnotationColor.Color9, iv_readerAnnotationProperty_color9)
+        put(AnnotationColor.Color10, iv_readerAnnotationProperty_color10)
     }
     private var thickness: Int = DEFAULT_THICKNESS
         set(value) {
@@ -104,7 +93,7 @@ class AnnotationAttributeView @JvmOverloads constructor(
             return context.resources.getColor(colorEnum.colorResId)
         }
         set(value) {
-            Color.values().forEach {
+            AnnotationColor.values().forEach {
                 val c = context.resources.getColor(it.colorResId)
                 if (c == value) {
                     colorEnum = it
@@ -112,7 +101,7 @@ class AnnotationAttributeView @JvmOverloads constructor(
                 }
             }
         }
-    private var colorEnum: Color = Color.Color1
+    private var colorEnum: AnnotationColor = AnnotationColor.Color1
         set(value) {
             field = value
             updateColor()