mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 00:37:58 +03:00
Make extension settings button inline
This commit is contained in:
parent
390bdfa93d
commit
ca7373c28b
4 changed files with 67 additions and 9 deletions
|
@ -15,6 +15,7 @@ import androidx.preference.Preference
|
|||
import androidx.preference.PreferenceGroupAdapter
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.DividerItemDecoration.VERTICAL
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
|
@ -29,12 +30,11 @@ import eu.kanade.tachiyomi.source.Source
|
|||
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.util.preference.DSL
|
||||
import eu.kanade.tachiyomi.util.preference.onChange
|
||||
import eu.kanade.tachiyomi.util.preference.onClick
|
||||
import eu.kanade.tachiyomi.util.preference.preference
|
||||
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.preference.switchSettingsPreference
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import eu.kanade.tachiyomi.util.view.visible
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
@ -129,8 +129,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||
.forEach { source ->
|
||||
val sourcePrefs = mutableListOf<Preference>()
|
||||
|
||||
// Source enable/disable
|
||||
switchPreference {
|
||||
val block: (@DSL SwitchPreferenceCompat).() -> Unit = {
|
||||
key = getSourceKey(source.id)
|
||||
title = if (isMultiSource) {
|
||||
source.toString()
|
||||
|
@ -156,14 +155,16 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||
.launchIn(scope)
|
||||
}
|
||||
|
||||
// Source preferences
|
||||
// Source enable/disable
|
||||
if (source is ConfigurableSource) {
|
||||
preference {
|
||||
titleRes = R.string.label_settings
|
||||
onClick {
|
||||
switchSettingsPreference {
|
||||
block()
|
||||
onSettingsClick = View.OnClickListener {
|
||||
router.pushController(SourcePreferencesController(source.id).withFadeTransaction())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switchPreference(block)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||
import eu.kanade.tachiyomi.widget.preference.IntListPreference
|
||||
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
||||
import eu.kanade.tachiyomi.widget.preference.SwitchSettingsPreference
|
||||
|
||||
@DslMarker
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
|
@ -51,6 +52,10 @@ inline fun PreferenceGroup.switchPreferenceCategory(block: (@DSL SwitchPreferenc
|
|||
return initThenAdd(SwitchPreferenceCategory(context), block)
|
||||
}
|
||||
|
||||
inline fun PreferenceGroup.switchSettingsPreference(block: (@DSL SwitchSettingsPreference).() -> Unit): SwitchSettingsPreference {
|
||||
return initThenAdd(SwitchSettingsPreference(context), block)
|
||||
}
|
||||
|
||||
inline fun PreferenceGroup.checkBoxPreference(block: (@DSL CheckBoxPreference).() -> Unit): CheckBoxPreference {
|
||||
return initThenAdd(CheckBoxPreference(context), block)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import eu.kanade.tachiyomi.R
|
||||
import kotlinx.android.synthetic.main.pref_settings.view.button
|
||||
|
||||
class SwitchSettingsPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
SwitchPreferenceCompat(context, attrs) {
|
||||
|
||||
var onSettingsClick: View.OnClickListener? = null
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.pref_settings
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
holder.itemView.button.setOnClickListener {
|
||||
onSettingsClick?.onClick(it)
|
||||
}
|
||||
}
|
||||
}
|
25
app/src/main/res/layout/pref_settings.xml
Normal file
25
app/src/main/res/layout/pref_settings.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?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"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/label_settings"
|
||||
android:padding="8dp"
|
||||
app:srcCompat="@drawable/ic_settings_24dp"
|
||||
app:tint="?attr/colorOnBackground" />
|
||||
|
||||
<!-- Matches ID used in SwitchPreferenceCompat -->
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/switchWidget"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue