mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Update tracker services logo layout (closes #5625)
This commit is contained in:
parent
0f41e56a24
commit
7094fef37f
8 changed files with 100 additions and 48 deletions
|
@ -35,7 +35,7 @@ class TrackSearchAdapter(
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrackSearchHolder {
|
||||
val binding = TrackSearchItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
binding.container.applyElevationOverlay()
|
||||
binding.root.applyElevationOverlay()
|
||||
return TrackSearchHolder(binding, this)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ class TrackSearchHolder(
|
|||
private val adapter: TrackSearchAdapter
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(track: TrackSearch, position: Int) {
|
||||
binding.container.isChecked = position == adapter.selectedItemPosition
|
||||
binding.container.setOnClickListener {
|
||||
binding.root.isChecked = position == adapter.selectedItemPosition
|
||||
binding.root.setOnClickListener {
|
||||
adapter.selectedItemPosition = position
|
||||
binding.container.isChecked = true
|
||||
binding.root.isChecked = true
|
||||
}
|
||||
|
||||
binding.trackSearchTitle.text = track.title
|
||||
|
@ -62,6 +62,6 @@ class TrackSearchHolder(
|
|||
}
|
||||
|
||||
fun setUnchecked() {
|
||||
binding.container.isChecked = false
|
||||
binding.root.isChecked = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import eu.kanade.tachiyomi.util.preference.switchPreference
|
|||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.widget.preference.LoginPreference
|
||||
import eu.kanade.tachiyomi.widget.preference.TrackerPreference
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
|
||||
|
@ -96,12 +96,13 @@ class SettingsTrackingController :
|
|||
private inline fun PreferenceGroup.trackPreference(
|
||||
service: TrackService,
|
||||
crossinline login: () -> Unit
|
||||
): LoginPreference {
|
||||
): TrackerPreference {
|
||||
return add(
|
||||
LoginPreference(context).apply {
|
||||
TrackerPreference(context).apply {
|
||||
key = Keys.trackUsername(service.id)
|
||||
titleRes = service.nameRes()
|
||||
iconRes = service.getLogo()
|
||||
iconColor = service.getLogoColor()
|
||||
onClick {
|
||||
if (service.isLogged) {
|
||||
if (service is NoLoginTrackService) {
|
||||
|
@ -142,7 +143,7 @@ class SettingsTrackingController :
|
|||
}
|
||||
|
||||
private fun updatePreference(id: Int) {
|
||||
val pref = findPreference(Keys.trackUsername(id)) as? LoginPreference
|
||||
val pref = findPreference(Keys.trackUsername(id)) as? TrackerPreference
|
||||
pref?.notifyChanged()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
class LoginPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
Preference(context, attrs) {
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.pref_widget_imageview
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
(holder.findViewById(R.id.image_view) as ImageView).setImageResource(
|
||||
if (getPersistedString("").isNullOrEmpty()) {
|
||||
android.R.color.transparent
|
||||
} else {
|
||||
R.drawable.ic_done_green_24dp
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public override fun notifyChanged() {
|
||||
super.notifyChanged()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
||||
class TrackerPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
Preference(context, attrs) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.pref_tracker_item
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
val logoContainer = holder.findViewById(R.id.logo_container) as MaterialCardView
|
||||
val checkedIcon = holder.findViewById(R.id.checked_icon) as ImageView
|
||||
|
||||
logoContainer.setCardBackgroundColor(iconColor)
|
||||
checkedIcon.isVisible = !getPersistedString("").isNullOrEmpty()
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
var iconColor: Int = Color.TRANSPARENT
|
||||
set(value) {
|
||||
field = value
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
public override fun notifyChanged() {
|
||||
super.notifyChanged()
|
||||
}
|
||||
}
|
49
app/src/main/res/layout/pref_tracker_item.xml
Normal file
49
app/src/main/res/layout/pref_tracker_item.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?listPreferredItemHeight"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/logo_container"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:cardBackgroundColor="#2E51A2"
|
||||
app:cardElevation="0dp"
|
||||
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MaterialCardView.Tracker">
|
||||
|
||||
<ImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:importantForAccessibility="no"
|
||||
android:padding="4dp"
|
||||
tools:src="@drawable/ic_tracker_mal" />
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:textAppearance="?attr/textAppearanceSubtitle1"
|
||||
tools:text="MyAnimeList" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/checked_icon"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="4dp"
|
||||
android:src="@drawable/ic_done_green_24dp" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/image_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
|
@ -2,7 +2,6 @@
|
|||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
|
@ -12,7 +11,6 @@
|
|||
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.MaterialCardView.Tracker">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
|
|
Loading…
Reference in a new issue