Quellcode durchsuchen

Add SeekBarFormatter to TextSeekBar

cooperku_kdanmobile vor 5 Jahren
Ursprung
Commit
dd6f007e3d

+ 17 - 1
reader/src/main/java/com/kdanmobile/reader/screen/view/edit/TextSeekBar.kt

@@ -16,10 +16,26 @@ class TextSeekBar : ConstraintLayout {
     private var minValue = 0
     private var initValue = 0
 
+    private val defaultFormatter = object : SeekBarFormatter {
+        override fun format(value: Int): String {
+            return value.toString()
+        }
+    }
+
+    var formatter = defaultFormatter
+        set(value) {
+            field = value
+            tv_seekBarValue?.text = "${formatter.format(currentValue)}$unit"
+        }
+
+    interface SeekBarFormatter {
+        fun format(value: Int): String
+    }
+
     var currentValue = 0
         set(value) {
             field = Math.max(Math.min(value, maxValue), minValue)
-            tv_seekBarValue?.text = "$field$unit"
+            tv_seekBarValue?.text = "${formatter.format(currentValue)}$unit"
             seekBar?.progress = field - minValue
         }
     var onSeekBarChangeListener: SeekBar.OnSeekBarChangeListener? = null

+ 3 - 3
reader/src/main/res/layout/view_viewer_edit_item_shape_border.xml

@@ -23,9 +23,9 @@
         android:layout_marginTop="8dp"
         app:title="Opacity"
         app:unit="%"
-        app:maxValue="100"
+        app:maxValue="255"
         app:minValue="0"
-        app:initValue="100"
+        app:initValue="255"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/colorChooser_shapeBorder"
@@ -37,7 +37,7 @@
         android:id="@+id/seekBar_shapeBorder_thickness"
         app:title="Thickness"
         app:unit="px"
-        app:maxValue="10"
+        app:maxValue="24"
         app:minValue="0"
         app:initValue="3"
         app:layout_constraintLeft_toLeftOf="parent"

+ 2 - 2
reader/src/main/res/layout/view_viewer_edit_item_shape_fill.xml

@@ -23,9 +23,9 @@
         android:layout_marginTop="8dp"
         app:title="Opacity"
         app:unit="%"
-        app:maxValue="100"
+        app:maxValue="255"
         app:minValue="0"
-        app:initValue="100"
+        app:initValue="0"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/colorChooser_shapeFill" />