From 6720725d2752a1ef4810e77baf7d5fbeaecee3b4 Mon Sep 17 00:00:00 2001
From: Viktor De Pasquale <info@depasquale.wiki>
Date: Fri, 1 Nov 2019 18:12:52 +0100
Subject: [PATCH] Added clarifying tooltips and captions

---
 .../magisk/utils/DataBindingAdapters.kt       | 10 +++++---
 app/src/main/res/layout/item_policy_md2.xml   | 25 +++++++++++++++----
 app/src/main/res/values/strings_md2.xml       |  4 +++
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
index 9d8c0d3d5..7e8a4dee2 100644
--- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
@@ -14,10 +14,7 @@ import androidx.annotation.DrawableRes
 import androidx.appcompat.widget.AppCompatImageView
 import androidx.appcompat.widget.Toolbar
 import androidx.core.animation.doOnEnd
-import androidx.core.view.isInvisible
-import androidx.core.view.isVisible
-import androidx.core.view.postDelayed
-import androidx.core.view.updateLayoutParams
+import androidx.core.view.*
 import androidx.databinding.BindingAdapter
 import androidx.databinding.InverseBindingAdapter
 import androidx.databinding.InverseBindingListener
@@ -408,4 +405,9 @@ fun MaterialCardView.setCardStrokeWidthBound(stroke: Float) {
 @BindingAdapter("onMenuClick")
 fun Toolbar.setOnMenuClickListener(listener: Toolbar.OnMenuItemClickListener) {
     setOnMenuItemClickListener(listener)
+}
+
+@BindingAdapter("tooltipText")
+fun View.setTooltipTextCompat(text: String) {
+    ViewCompat.setTooltipText(this, text)
 }
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_policy_md2.xml b/app/src/main/res/layout/item_policy_md2.xml
index 215a2bac6..710fdfc59 100644
--- a/app/src/main/res/layout/item_policy_md2.xml
+++ b/app/src/main/res/layout/item_policy_md2.xml
@@ -23,7 +23,8 @@
         android:alpha="@{item.isEnabled() ? 1f : .5f}"
         android:onClick="@{() -> item.toggle(viewModel)}"
         tools:layout_marginBottom="@dimen/l1"
-        tools:layout_marginEnd="@dimen/l1">
+        tools:layout_marginEnd="@dimen/l1"
+        tools:layout_width="200dp">
 
         <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
@@ -87,12 +88,15 @@
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/package_name">
+            app:layout_constraintTop_toBottomOf="@+id/package_name"
+            tools:visibility="visible">
 
             <androidx.appcompat.widget.AppCompatImageView
                 android:id="@+id/bell"
                 style="?styleIconNormal"
                 isSelected="@{item.shouldNotify}"
+                tooltipText="@{@string/superuser_toggle_notification}"
+                android:contentDescription="@string/superuser_toggle_notification"
                 android:onClick="@{() -> item.toggleNotify(viewModel)}"
                 app:layout_constraintBottom_toTopOf="@+id/delete"
                 app:layout_constraintEnd_toStartOf="@+id/bug"
@@ -107,6 +111,8 @@
                 android:id="@+id/bug"
                 style="?styleIconNormal"
                 isSelected="@{item.shouldLog}"
+                tooltipText="@{@string/superuser_toggle_log}"
+                android:contentDescription="@string/superuser_toggle_log"
                 android:onClick="@{() -> item.toggleLog(viewModel)}"
                 app:layout_constraintBottom_toBottomOf="@+id/bell"
                 app:layout_constraintEnd_toEndOf="parent"
@@ -115,15 +121,24 @@
                 app:srcCompat="@drawable/ic_bug_report"
                 app:tint="@color/color_error_primary_transient" />
 
-            <androidx.appcompat.widget.AppCompatImageView
+            <com.google.android.material.button.MaterialButton
                 android:id="@+id/delete"
-                style="?styleIconError"
+                style="?styleButtonText"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
                 android:onClick="@{() -> viewModel.deletePressed(item)}"
+                android:text="@string/superuser_toggle_revoke"
+                android:textAllCaps="false"
+                android:textColor="?colorError"
+                android:textSize="12sp"
+                app:icon="@drawable/ic_delete_md2"
+                app:iconPadding="@dimen/l_50"
+                app:iconTint="?colorError"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/bell"
-                app:srcCompat="@drawable/ic_delete_md2" />
+                app:rippleColor="?colorError" />
 
         </androidx.constraintlayout.widget.ConstraintLayout>
 
diff --git a/app/src/main/res/values/strings_md2.xml b/app/src/main/res/values/strings_md2.xml
index 6f01e8357..278e3cb14 100644
--- a/app/src/main/res/values/strings_md2.xml
+++ b/app/src/main/res/values/strings_md2.xml
@@ -70,4 +70,8 @@
 
     <string name="module_safe_mode_message">You\'re in safe mode. None of user modules will work.\nThis message will disappear once safe mode is disabled.</string>
 
+    <string name="superuser_toggle_log">Toggles logging</string>
+    <string name="superuser_toggle_notification">Toggles “toast” notifications</string>
+    <string name="superuser_toggle_revoke">Revoke</string>
+
 </resources>
\ No newline at end of file