Explorar o código

make filled buttons Material 3

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger %!s(int64=2) %!d(string=hai) anos
pai
achega
c10a0a7c65

+ 1 - 1
app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java

@@ -106,7 +106,7 @@ public class TakePhotoActivity extends AppCompatActivity {
         setContentView(binding.getRoot());
 
         viewThemeUtils.themeFAB(binding.takePhoto);
-        viewThemeUtils.colorMaterialButtonBackground(binding.send);
+        viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.send);
 
         cameraProviderFuture = ProcessCameraProvider.getInstance(this);
         cameraProviderFuture.addListener(() -> {

+ 1 - 1
app/src/main/java/com/nextcloud/talk/polls/ui/PollCreateDialogFragment.kt

@@ -108,7 +108,7 @@ class PollCreateDialogFragment : DialogFragment(), PollCreateOptionsItemListener
         viewThemeUtils.colorMaterialButtonText(binding.pollAddOptionsItem)
         // TODO button also needs a disabled state handling for colors
         viewThemeUtils.colorMaterialButtonText(binding.pollDismiss)
-        viewThemeUtils.colorMaterialButtonBackground(binding.pollCreateButton)
+        viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.pollCreateButton)
 
         viewThemeUtils.themeCheckbox(binding.pollPrivatePollCheckbox)
         viewThemeUtils.themeCheckbox(binding.pollMultipleAnswersCheckbox)

+ 1 - 1
app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt

@@ -98,7 +98,7 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener {
     }
 
     private fun themeDialog() {
-        viewThemeUtils.colorMaterialButtonBackground(binding.editVoteButton)
+        viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.editVoteButton)
         viewThemeUtils.colorMaterialButtonText(binding.pollResultsEndPollButton)
     }
 

+ 1 - 1
app/src/main/java/com/nextcloud/talk/polls/ui/PollVoteFragment.kt

@@ -126,7 +126,7 @@ class PollVoteFragment : Fragment() {
     }
 
     private fun themeDialog() {
-        viewThemeUtils.colorMaterialButtonBackground(binding.pollVoteSubmitButton)
+        viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.pollVoteSubmitButton)
         viewThemeUtils.colorMaterialButtonText(binding.pollVoteEndPollButton)
         viewThemeUtils.colorMaterialButtonText(binding.pollVoteEditDismiss)
     }

+ 1 - 1
app/src/main/java/com/nextcloud/talk/ui/dialog/SetStatusDialogFragment.kt

@@ -242,7 +242,7 @@ class SetStatusDialogFragment :
         }
 
         viewThemeUtils.colorMaterialButtonText(binding.clearStatus)
-        viewThemeUtils.colorMaterialButtonBackground(binding.setStatus)
+        viewThemeUtils.colorMaterialButtonPrimaryFilled(binding.setStatus)
 
         binding.customStatusInput.highlightColor = resources.getColor(R.color.colorPrimary)
 

+ 42 - 9
app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt

@@ -63,6 +63,7 @@ import com.yarolegovich.mp.MaterialPreferenceCategory
 import com.yarolegovich.mp.MaterialSwitchPreference
 import scheme.Scheme
 import javax.inject.Inject
+import kotlin.math.roundToInt
 
 @Suppress("TooManyFunctions")
 class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private val colorUtil: ColorUtil) {
@@ -229,21 +230,42 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
         }
     }
 
-    fun colorMaterialButtonBackground(button: MaterialButton) {
-        withElementColor(button) { color ->
-            button.setBackgroundColor(color)
+    fun colorMaterialButtonPrimaryFilled(button: MaterialButton) {
+        withScheme(button) { scheme ->
+            button.backgroundTintList =
+                ColorStateList(
+                    arrayOf(
+                        intArrayOf(android.R.attr.state_enabled),
+                        intArrayOf(-android.R.attr.state_enabled)
+                    ),
+                    intArrayOf(
+                        scheme.primary,
+                        calculateDisabledColor(scheme.primary, SURFACE_OPACITY_BUTTON_DISABLED)
+                    )
+                )
 
-            val disabledColor = ContextCompat.getColor(button.context, R.color.disabled_text)
-            val colorStateList = ColorStateList(
+            button.setTextColor(
+                ColorStateList(
+                    arrayOf(
+                        intArrayOf(android.R.attr.state_enabled),
+                        intArrayOf(-android.R.attr.state_enabled)
+                    ),
+                    intArrayOf(
+                        scheme.onPrimary,
+                        calculateDisabledColor(scheme.onPrimary, ON_SURFACE_OPACITY_BUTTON_DISABLED)
+                    )
+                )
+            )
+            button.iconTint = ColorStateList(
                 arrayOf(
                     intArrayOf(android.R.attr.state_enabled),
                     intArrayOf(-android.R.attr.state_enabled)
                 ),
-                intArrayOf(theme.colorText, disabledColor)
+                intArrayOf(
+                    scheme.onPrimary,
+                    calculateDisabledColor(scheme.onPrimary, ON_SURFACE_OPACITY_BUTTON_DISABLED)
+                )
             )
-
-            button.setTextColor(colorStateList)
-            button.iconTint = colorStateList
         }
     }
 
@@ -435,6 +457,15 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
         }
     }
 
+    private fun calculateDisabledColor(color: Int, opacity: Float): Int {
+        return Color.argb(
+            (Color.alpha(color) * opacity).roundToInt(),
+            Color.red(color),
+            Color.green(color),
+            Color.blue(color)
+        )
+    }
+
     companion object {
         private val THEMEABLE_PLACEHOLDER_IDS = listOf(
             R.drawable.ic_mimetype_package_x_generic,
@@ -443,5 +474,7 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
         private const val SWITCHCOMPAT_TRACK_ALPHA: Int = 77
         private const val PROGRESS_LIGHTNESS_LIGHT_THEME: Float = 0.76f
         private const val PROGRESS_LIGHTNESS_DARK_THEME: Float = 0.28f
+        private const val SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.12f
+        private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f
     }
 }