Sfoglia il codice sorgente

Set activated states for manga info favorite/tracker buttons

arkon 4 anni fa
parent
commit
0904692f15

+ 6 - 27
app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt

@@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.manga.info
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import androidx.core.content.ContextCompat
 import androidx.core.view.isVisible
 import androidx.recyclerview.widget.RecyclerView
 import com.bumptech.glide.load.engine.DiskCacheStrategy
@@ -21,7 +20,6 @@ import eu.kanade.tachiyomi.source.online.HttpSource
 import eu.kanade.tachiyomi.ui.manga.MangaController
 import eu.kanade.tachiyomi.util.system.copyToClipboard
 import eu.kanade.tachiyomi.util.view.setChips
-import eu.kanade.tachiyomi.util.view.setTooltip
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -103,27 +101,17 @@ class MangaInfoHeaderAdapter(
                     isVisible = true
 
                     if (trackCount > 0) {
-                        setCompoundDrawablesWithIntrinsicBounds(
-                            null,
-                            ContextCompat.getDrawable(context, R.drawable.ic_done_24dp),
-                            null,
-                            null
-                        )
+                        setIconResource(R.drawable.ic_done_24dp)
                         text = view.context.resources.getQuantityString(
                             R.plurals.num_trackers,
                             trackCount,
                             trackCount
                         )
-                        isSelected = true
+                        isActivated = true
                     } else {
-                        setCompoundDrawablesWithIntrinsicBounds(
-                            null,
-                            ContextCompat.getDrawable(context, R.drawable.ic_sync_24dp),
-                            null,
-                            null
-                        )
+                        setIconResource(R.drawable.ic_sync_24dp)
                         text = view.context.getString(R.string.manga_tracking_tab)
-                        isSelected = false
+                        isActivated = false
                     }
 
                     clicks()
@@ -139,7 +127,6 @@ class MangaInfoHeaderAdapter(
                 binding.btnWebview.clicks()
                     .onEach { controller.openMangaInWebView() }
                     .launchIn(scope)
-                binding.btnWebview.setTooltip(R.string.action_open_in_web_view)
             }
 
             binding.mangaFullTitle.longClicks()
@@ -352,18 +339,10 @@ class MangaInfoHeaderAdapter(
             // Set the Favorite drawable to the correct one.
             // Border drawable if false, filled drawable if true.
             binding.btnFavorite.apply {
-                setCompoundDrawablesWithIntrinsicBounds(
-                    null,
-                    ContextCompat.getDrawable(
-                        context,
-                        if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp
-                    ),
-                    null,
-                    null
-                )
+                setIconResource(if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp)
                 text =
                     context.getString(if (isFavorite) R.string.in_library else R.string.add_to_library)
-                isSelected = isFavorite
+                isActivated = isFavorite
             }
         }
     }

+ 5 - 0
app/src/main/res/color/button_action_selector.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:color="?attr/colorAccent" android:state_activated="true" />
+    <item android:color="?attr/colorOnBackground" android:state_activated="false" />
+</selector>

+ 0 - 5
app/src/main/res/color/outlined_button_bg.xml

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:alpha="0.25" android:color="?attr/colorAccent" android:state_checked="true" />
-    <item android:color="@android:color/transparent" android:state_checked="false" />
-</selector>

+ 9 - 11
app/src/main/res/layout/manga_info_header.xml

@@ -133,44 +133,42 @@
 
     <androidx.constraintlayout.widget.ConstraintLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+        android:layout_height="wrap_content"
+        android:paddingStart="16dp"
+        android:paddingEnd="16dp">
 
-        <androidx.appcompat.widget.AppCompatButton
+        <com.google.android.material.button.MaterialButton
             android:id="@+id/btn_favorite"
             style="@style/Theme.Widget.Button.Action"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:checkable="true"
             android:text="@string/add_to_library"
-            app:drawableTopCompat="@drawable/ic_favorite_border_24dp"
+            app:icon="@drawable/ic_favorite_border_24dp"
             app:layout_constraintEnd_toStartOf="@+id/btn_tracking"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 
-        <androidx.appcompat.widget.AppCompatButton
+        <com.google.android.material.button.MaterialButton
             android:id="@+id/btn_tracking"
             style="@style/Theme.Widget.Button.Action"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:layout_marginStart="8dp"
-            android:checkable="true"
             android:text="@string/manga_tracking_tab"
             android:visibility="gone"
-            app:drawableTopCompat="@drawable/ic_sync_24dp"
+            app:icon="@drawable/ic_sync_24dp"
             app:layout_constraintEnd_toStartOf="@+id/btn_webview"
             app:layout_constraintStart_toEndOf="@+id/btn_favorite"
             app:layout_constraintTop_toTopOf="parent"
             tools:visibility="visible" />
 
-        <androidx.appcompat.widget.AppCompatButton
+        <com.google.android.material.button.MaterialButton
             android:id="@+id/btn_webview"
             style="@style/Theme.Widget.Button.Action"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:layout_marginStart="8dp"
             android:text="@string/action_web_view"
             android:visibility="gone"
-            app:drawableTopCompat="@drawable/ic_public_24dp"
+            app:icon="@drawable/ic_public_24dp"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toEndOf="@+id/btn_tracking"
             app:layout_constraintTop_toTopOf="parent"

+ 7 - 8
app/src/main/res/values/styles.xml

@@ -250,17 +250,16 @@
         <item name="android:textAllCaps">false</item>
     </style>
 
-    <style name="Theme.Widget.Button.Action" parent="Widget.MaterialComponents.Button.Icon">
-        <item name="elevation">0dp</item>
-
+    <style name="Theme.Widget.Button.Action" parent="Widget.MaterialComponents.Button.UnelevatedButton.Icon">
         <item name="android:textSize">12sp</item>
+        <item name="android:textAllCaps">false</item>
 
-        <item name="drawableTint">?attr/colorOnBackground</item>
-        <item name="android:drawablePadding">4dp</item>
-        <item name="rippleColor">?attr/colorAccent</item>
-        <item name="android:textColor">?attr/colorOnBackground</item>
+        <item name="backgroundTint">@android:color/transparent</item>
 
-        <item name="backgroundTint">@color/outlined_button_bg</item>
+        <item name="iconGravity">top</item>
+        <item name="iconTint">@color/button_action_selector</item>
+        <item name="iconPadding">4dp</item>
+        <item name="android:textColor">@color/button_action_selector</item>
     </style>
 
     <style name="Theme.Widget.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">