WIP prefs: editText preference without summary
This commit is contained in:
parent
20e9cc7d5f
commit
4eb5a484e3
|
@ -35,6 +35,7 @@ import com.keylesspalace.tusky.settings.PreferenceOption
|
|||
import com.keylesspalace.tusky.settings.PreferenceParent
|
||||
import com.keylesspalace.tusky.settings.clickPreference
|
||||
import com.keylesspalace.tusky.settings.customListPreference
|
||||
import com.keylesspalace.tusky.settings.editTextPreference
|
||||
import com.keylesspalace.tusky.settings.getBlocking
|
||||
import com.keylesspalace.tusky.settings.listPreference
|
||||
import com.keylesspalace.tusky.settings.makePreferenceScreen
|
||||
|
@ -102,6 +103,33 @@ class PreferencesFragment : Fragment(), Injectable {
|
|||
browserCategory()
|
||||
filtersCategory()
|
||||
wellbeingCategory()
|
||||
preferenceCategory(R.string.pref_title_proxy_settings) {
|
||||
switchPreference(
|
||||
getString(R.string.pref_title_http_proxy_enable),
|
||||
{ prefs.httpProxyEnabled }
|
||||
) {
|
||||
updatePrefs { data -> data.copy(httpProxyEnabled = it) }
|
||||
}
|
||||
editTextPreference(
|
||||
getString(R.string.pref_title_http_proxy_server),
|
||||
{ prefs.httpProxyServer },
|
||||
) {
|
||||
updatePrefs { data -> data.copy(httpProxyServer = it) }
|
||||
}
|
||||
editTextPreference(
|
||||
getString(R.string.pref_title_http_proxy_port),
|
||||
{ prefs.httpProxyPort },
|
||||
) {
|
||||
updatePrefs { data -> data.copy(httpProxyPort = it) }
|
||||
}
|
||||
//
|
||||
// editTextPreference {
|
||||
// setTitle(R.string.pref_title_http_proxy_port)
|
||||
// key = PrefKeys.HTTP_PROXY_PORT
|
||||
// isIconSpaceReserved = false
|
||||
// setSummaryProvider { text }
|
||||
// }
|
||||
}
|
||||
}
|
||||
return viewRoot
|
||||
}
|
||||
|
|
|
@ -7,11 +7,16 @@ import android.view.Gravity
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import at.connyduck.sparkbutton.helpers.Utils
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||
|
@ -177,11 +182,46 @@ fun PreferenceParent.switchPreference(
|
|||
addPref(layout)
|
||||
}
|
||||
|
||||
fun PreferenceParent.editTextPreference(
|
||||
title: String,
|
||||
value: () -> String,
|
||||
onNewValue: (String) -> Unit
|
||||
) {
|
||||
val layout = baseOneLineItemLayout(title)
|
||||
// TODO: current value
|
||||
layout.setOnClickListener {
|
||||
val editLayout = FrameLayout(context)
|
||||
val editText = EditText(context).apply {
|
||||
setText(value())
|
||||
}
|
||||
editLayout.addView(editText)
|
||||
editText.updateLayoutParams<FrameLayout.LayoutParams> {
|
||||
setMargins(dpToPx(8), 0, dpToPx(8), 0)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(context)
|
||||
.setView(editLayout)
|
||||
.setTitle(title)
|
||||
.setPositiveButton(android.R.string.ok) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
onNewValue(editText.text.toString())
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setCancelable(true)
|
||||
.show()
|
||||
}
|
||||
addPref(layout)
|
||||
}
|
||||
|
||||
data class PreferenceOption<T>(val name: String, val value: T)
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun <T> PreferenceParent.PreferenceOption(pair: Pair<T, Int>): PreferenceOption<T> {
|
||||
return PreferenceOption(context.getString(pair.second), pair.first)
|
||||
}
|
||||
|
||||
infix fun <T> T.named(name: String) = PreferenceOption(name, this)
|
||||
|
||||
fun <T> PreferenceParent.listPreference(
|
||||
|
|
Loading…
Reference in New Issue