WIP prefs UI
This commit is contained in:
parent
3130ffd8ea
commit
2e61639784
|
@ -26,6 +26,7 @@ import androidx.fragment.app.Fragment
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.db.AccountManager
|
import com.keylesspalace.tusky.db.AccountManager
|
||||||
import com.keylesspalace.tusky.di.Injectable
|
import com.keylesspalace.tusky.di.Injectable
|
||||||
|
import com.keylesspalace.tusky.settings.checkBoxPreference
|
||||||
import com.keylesspalace.tusky.settings.makePreferenceScreen
|
import com.keylesspalace.tusky.settings.makePreferenceScreen
|
||||||
import com.keylesspalace.tusky.settings.preferenceCategory
|
import com.keylesspalace.tusky.settings.preferenceCategory
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils
|
import com.keylesspalace.tusky.util.ThemeUtils
|
||||||
|
@ -55,7 +56,7 @@ class PreferencesFragment : Fragment(), Injectable {
|
||||||
val view = FrameLayout(inflater.context)
|
val view = FrameLayout(inflater.context)
|
||||||
makePreferenceScreen(view) {
|
makePreferenceScreen(view) {
|
||||||
preferenceCategory(R.string.pref_title_appearance_settings) {
|
preferenceCategory(R.string.pref_title_appearance_settings) {
|
||||||
|
checkBoxPreference("TEST", true) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return view
|
return view
|
||||||
|
|
|
@ -2,26 +2,17 @@ package com.keylesspalace.tusky.settings
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.view.marginLeft
|
|
||||||
import androidx.core.view.marginTop
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.preference.CheckBoxPreference
|
|
||||||
import androidx.preference.EditTextPreference
|
|
||||||
import androidx.preference.ListPreference
|
|
||||||
import androidx.preference.Preference
|
|
||||||
import androidx.preference.PreferenceCategory
|
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
|
||||||
import androidx.preference.PreferenceScreen
|
|
||||||
import androidx.preference.SwitchPreference
|
|
||||||
import at.connyduck.sparkbutton.helpers.Utils
|
import at.connyduck.sparkbutton.helpers.Utils
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.components.preference.EmojiPreference
|
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
|
|
||||||
class PreferenceParent(
|
class PreferenceParent(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
|
@ -70,22 +61,58 @@ class PreferenceParent(
|
||||||
// return pref
|
// return pref
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//inline fun PreferenceParent.checkBoxPreference(
|
|
||||||
// builder: CheckBoxPreference.() -> Unit
|
private fun itemLayout(context: Context): LinearLayout {
|
||||||
//): CheckBoxPreference {
|
return LinearLayout(context).apply {
|
||||||
// val pref = CheckBoxPreference(context)
|
layoutParams = ViewGroup.MarginLayoutParams(
|
||||||
|
ViewGroup.MarginLayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
|
||||||
|
)
|
||||||
|
setPadding(dpToPx(16), 0, dpToPx(16), 0)
|
||||||
|
gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||||
|
|
||||||
|
val spacer = ImageView(context).apply {
|
||||||
|
minimumWidth = dpToPx(56)
|
||||||
|
setPadding(0, dpToPx(4), dpToPx(8), dpToPx(4))
|
||||||
|
}
|
||||||
|
addView(spacer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PreferenceParent.checkBoxPreference(
|
||||||
|
text: String,
|
||||||
|
selected: Boolean,
|
||||||
|
onSelection: (Boolean) -> Unit
|
||||||
|
) {
|
||||||
|
val layout = itemLayout(context)
|
||||||
|
|
||||||
|
val textView = TextView(context)
|
||||||
|
layout.addView(textView)
|
||||||
|
textView.text = text
|
||||||
|
|
||||||
|
val checkbox = CheckBox(context)
|
||||||
|
layout.addView(checkbox)
|
||||||
|
checkbox.isSelected = selected
|
||||||
|
|
||||||
|
// TODO listener
|
||||||
// builder(pref)
|
// builder(pref)
|
||||||
// addPref(pref)
|
// addPref(pref)
|
||||||
// return pref
|
addPref(layout)
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
|
|
||||||
inline fun PreferenceParent.preferenceCategory(
|
|
||||||
|
fun PreferenceParent.preferenceCategory(
|
||||||
@StringRes title: Int,
|
@StringRes title: Int,
|
||||||
builder: PreferenceParent.() -> Unit
|
builder: PreferenceParent.() -> Unit
|
||||||
) {
|
) {
|
||||||
val category = LinearLayout(context)
|
val categoryLayout = LinearLayout(context)
|
||||||
addPref(category)
|
categoryLayout.orientation = LinearLayout.VERTICAL
|
||||||
|
|
||||||
|
addPref(categoryLayout)
|
||||||
|
|
||||||
|
val titleLayout = itemLayout(context)
|
||||||
|
categoryLayout.addView(titleLayout)
|
||||||
|
|
||||||
val titleView = TextView(context).apply {
|
val titleView = TextView(context).apply {
|
||||||
layoutParams = ViewGroup.MarginLayoutParams(
|
layoutParams = ViewGroup.MarginLayoutParams(
|
||||||
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
|
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
|
||||||
|
@ -104,8 +131,8 @@ inline fun PreferenceParent.preferenceCategory(
|
||||||
setText(title)
|
setText(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
category.addView(titleView)
|
titleLayout.addView(titleView)
|
||||||
val newParent = PreferenceParent(context) { category.addView(it) }
|
val newParent = PreferenceParent(context) { categoryLayout.addView(it) }
|
||||||
builder(newParent)
|
builder(newParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue