Set activated states for manga info favorite/tracker buttons
This commit is contained in:
parent
65bacd288b
commit
0904692f15
5 changed files with 27 additions and 51 deletions
|
@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.manga.info
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
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.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
import eu.kanade.tachiyomi.util.view.setChips
|
import eu.kanade.tachiyomi.util.view.setChips
|
||||||
import eu.kanade.tachiyomi.util.view.setTooltip
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
@ -103,27 +101,17 @@ class MangaInfoHeaderAdapter(
|
||||||
isVisible = true
|
isVisible = true
|
||||||
|
|
||||||
if (trackCount > 0) {
|
if (trackCount > 0) {
|
||||||
setCompoundDrawablesWithIntrinsicBounds(
|
setIconResource(R.drawable.ic_done_24dp)
|
||||||
null,
|
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_done_24dp),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
text = view.context.resources.getQuantityString(
|
text = view.context.resources.getQuantityString(
|
||||||
R.plurals.num_trackers,
|
R.plurals.num_trackers,
|
||||||
trackCount,
|
trackCount,
|
||||||
trackCount
|
trackCount
|
||||||
)
|
)
|
||||||
isSelected = true
|
isActivated = true
|
||||||
} else {
|
} else {
|
||||||
setCompoundDrawablesWithIntrinsicBounds(
|
setIconResource(R.drawable.ic_sync_24dp)
|
||||||
null,
|
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_sync_24dp),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
text = view.context.getString(R.string.manga_tracking_tab)
|
text = view.context.getString(R.string.manga_tracking_tab)
|
||||||
isSelected = false
|
isActivated = false
|
||||||
}
|
}
|
||||||
|
|
||||||
clicks()
|
clicks()
|
||||||
|
@ -139,7 +127,6 @@ class MangaInfoHeaderAdapter(
|
||||||
binding.btnWebview.clicks()
|
binding.btnWebview.clicks()
|
||||||
.onEach { controller.openMangaInWebView() }
|
.onEach { controller.openMangaInWebView() }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
binding.btnWebview.setTooltip(R.string.action_open_in_web_view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.mangaFullTitle.longClicks()
|
binding.mangaFullTitle.longClicks()
|
||||||
|
@ -352,18 +339,10 @@ class MangaInfoHeaderAdapter(
|
||||||
// Set the Favorite drawable to the correct one.
|
// Set the Favorite drawable to the correct one.
|
||||||
// Border drawable if false, filled drawable if true.
|
// Border drawable if false, filled drawable if true.
|
||||||
binding.btnFavorite.apply {
|
binding.btnFavorite.apply {
|
||||||
setCompoundDrawablesWithIntrinsicBounds(
|
setIconResource(if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp)
|
||||||
null,
|
|
||||||
ContextCompat.getDrawable(
|
|
||||||
context,
|
|
||||||
if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_border_24dp
|
|
||||||
),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
text =
|
text =
|
||||||
context.getString(if (isFavorite) R.string.in_library else R.string.add_to_library)
|
context.getString(if (isFavorite) R.string.in_library else R.string.add_to_library)
|
||||||
isSelected = isFavorite
|
isActivated = isFavorite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
app/src/main/res/color/button_action_selector.xml
Normal file
5
app/src/main/res/color/button_action_selector.xml
Normal file
|
@ -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>
|
|
@ -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>
|
|
|
@ -133,44 +133,42 @@
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
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"
|
android:id="@+id/btn_favorite"
|
||||||
style="@style/Theme.Widget.Button.Action"
|
style="@style/Theme.Widget.Button.Action"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checkable="true"
|
|
||||||
android:text="@string/add_to_library"
|
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_constraintEnd_toStartOf="@+id/btn_tracking"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btn_tracking"
|
android:id="@+id/btn_tracking"
|
||||||
style="@style/Theme.Widget.Button.Action"
|
style="@style/Theme.Widget.Button.Action"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:checkable="true"
|
|
||||||
android:text="@string/manga_tracking_tab"
|
android:text="@string/manga_tracking_tab"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:drawableTopCompat="@drawable/ic_sync_24dp"
|
app:icon="@drawable/ic_sync_24dp"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/btn_webview"
|
app:layout_constraintEnd_toStartOf="@+id/btn_webview"
|
||||||
app:layout_constraintStart_toEndOf="@+id/btn_favorite"
|
app:layout_constraintStart_toEndOf="@+id/btn_favorite"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btn_webview"
|
android:id="@+id/btn_webview"
|
||||||
style="@style/Theme.Widget.Button.Action"
|
style="@style/Theme.Widget.Button.Action"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:text="@string/action_web_view"
|
android:text="@string/action_web_view"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:drawableTopCompat="@drawable/ic_public_24dp"
|
app:icon="@drawable/ic_public_24dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/btn_tracking"
|
app:layout_constraintStart_toEndOf="@+id/btn_tracking"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
|
|
@ -250,17 +250,16 @@
|
||||||
<item name="android:textAllCaps">false</item>
|
<item name="android:textAllCaps">false</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.Widget.Button.Action" parent="Widget.MaterialComponents.Button.Icon">
|
<style name="Theme.Widget.Button.Action" parent="Widget.MaterialComponents.Button.UnelevatedButton.Icon">
|
||||||
<item name="elevation">0dp</item>
|
|
||||||
|
|
||||||
<item name="android:textSize">12sp</item>
|
<item name="android:textSize">12sp</item>
|
||||||
|
<item name="android:textAllCaps">false</item>
|
||||||
|
|
||||||
<item name="drawableTint">?attr/colorOnBackground</item>
|
<item name="backgroundTint">@android:color/transparent</item>
|
||||||
<item name="android:drawablePadding">4dp</item>
|
|
||||||
<item name="rippleColor">?attr/colorAccent</item>
|
|
||||||
<item name="android:textColor">?attr/colorOnBackground</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>
|
||||||
|
|
||||||
<style name="Theme.Widget.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
|
<style name="Theme.Widget.Button.TextButton" parent="Widget.MaterialComponents.Button.TextButton">
|
||||||
|
|
Reference in a new issue