pull/1463/head^2
gedoor 3 years ago
parent b936006ee0
commit 1bc1abb797
  1. 11
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  2. 2
      app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt
  4. 2
      app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt
  5. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt
  6. 56
      app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt
  7. 10
      app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt

@ -14,6 +14,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.databinding.FragmentMyConfigBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.ThemeConfig
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.primaryColor
import io.legado.app.service.WebService
import io.legado.app.ui.about.AboutActivity
@ -65,6 +66,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.webService, WebService.isRun)
addPreferencesFromResource(R.xml.pref_main)
findPreference<SwitchPreference>("webService")?.onLongClick {
context?.selector(arrayListOf("复制地址", "浏览器打开")) { _, i ->
when (i) {
0 -> context?.sendToClip(it.summary.toString())
1 -> context?.openUrl(it.summary.toString())
}
}
true
}
observeEventSticky<String>(EventBus.WEB_SERVICE) {
findPreference<SwitchPreference>(PreferKey.webService)?.let {
it.isChecked = WebService.isRun
@ -138,5 +148,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
return super.onPreferenceTreeClick(preference)
}
}
}

@ -14,7 +14,7 @@ class EditTextPreference(context: Context, attrs: AttributeSet) :
layoutResource = R.layout.view_preference
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
Preference.bindView<TextView>(context, holder, icon, title, summary, null, null)
super.onBindViewHolder(holder)
}

@ -51,7 +51,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference
}
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val v = Preference.bindView<ImageView>(
context,

@ -23,7 +23,7 @@ class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference
typedArray.recycle()
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
val v = Preference.bindView<TextView>(
context,
holder,

@ -106,7 +106,7 @@ class Preference(context: Context, attrs: AttributeSet) :
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
bindView<View>(
context,
holder,
@ -116,7 +116,7 @@ class Preference(context: Context, attrs: AttributeSet) :
isBottomBackground = isBottomBackground
)
super.onBindViewHolder(holder)
holder?.itemView?.onLongClick {
holder.itemView.onLongClick {
onLongClick?.invoke()
}
}

@ -22,37 +22,35 @@ class PreferenceCategory(context: Context, attrs: AttributeSet) :
layoutResource = R.layout.view_preference_category
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
holder?.let {
val view = it.findViewById(R.id.preference_title)
if (view is TextView) { // && !view.isInEditMode
view.text = title
if (view.isInEditMode) return
view.setTextColor(context.accentColor)
view.isVisible = title != null && title.isNotEmpty()
val view = holder.findViewById(R.id.preference_title)
if (view is TextView) { // && !view.isInEditMode
view.text = title
if (view.isInEditMode) return
view.setTextColor(context.accentColor)
view.isVisible = title != null && title.isNotEmpty()
val da = it.findViewById(R.id.preference_divider_above)
val dividerColor = if (AppConfig.isNightTheme) {
ColorUtils.withAlpha(
ColorUtils.shiftColor(context.backgroundColor, 1.05f),
0.5f
)
} else {
ColorUtils.withAlpha(
ColorUtils.shiftColor(context.backgroundColor, 0.95f),
0.5f
)
}
if (da is View) {
da.setBackgroundColor(dividerColor)
da.isVisible = it.isDividerAllowedAbove
}
val db = it.findViewById(R.id.preference_divider_below)
if (db is View) {
db.setBackgroundColor(dividerColor)
db.isVisible = it.isDividerAllowedBelow
}
val da = holder.findViewById(R.id.preference_divider_above)
val dividerColor = if (AppConfig.isNightTheme) {
ColorUtils.withAlpha(
ColorUtils.shiftColor(context.backgroundColor, 1.05f),
0.5f
)
} else {
ColorUtils.withAlpha(
ColorUtils.shiftColor(context.backgroundColor, 0.95f),
0.5f
)
}
if (da is View) {
da.setBackgroundColor(dividerColor)
da.isVisible = holder.isDividerAllowedAbove
}
val db = holder.findViewById(R.id.preference_divider_below)
if (db is View) {
db.setBackgroundColor(dividerColor)
db.isVisible = holder.isDividerAllowedBelow
}
}
}

@ -13,6 +13,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
SwitchPreferenceCompat(context, attrs) {
private val isBottomBackground: Boolean
private var onLongClick: ((preference: SwitchPreference) -> Boolean)? = null
init {
layoutResource = R.layout.view_preference
@ -21,7 +22,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
typedArray.recycle()
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
val v = Preference.bindView<SwitchCompat>(
context,
holder,
@ -35,7 +36,14 @@ class SwitchPreference(context: Context, attrs: AttributeSet) :
if (v is SwitchCompat && !v.isInEditMode) {
v.applyTint(context.accentColor)
}
holder.itemView.setOnLongClickListener {
onLongClick?.invoke(this) ?: false
}
super.onBindViewHolder(holder)
}
fun onLongClick(listener: (preference: SwitchPreference) -> Boolean) {
onLongClick = listener
}
}

Loading…
Cancel
Save