diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/preferences')
3 files changed, 0 insertions, 162 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt deleted file mode 100644 index f49eac8f..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceBuilder.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.content.Context -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.annotation.StringRes -import com.mikepenz.iconics.typeface.IIcon -import com.pitchedapps.frost.utils.toColor -import com.pitchedapps.frost.utils.toString - -/** - * Created by Allan Wang on 2017-06-06. - */ -//fun Context.preference(setup: PreferenceBuild) - -@DslMarker -annotation class PreferenceMarker - -@PreferenceMarker -enum class PreferenceType() { - HEADER, TEXT, CHECKBOX; - - fun <T> createView(builder: PrefItem<T>) { - - } -} - -@PreferenceMarker -class PrefFrame(val context: Context, val theme: ThemeBuilder? = null, builder: PrefFrameBuilder.() -> Unit) - -@PreferenceMarker -class PrefFrameBuilder() { - val items: MutableList<PrefItem<*>> = mutableListOf() - - fun <T> item(item: PrefItem<T>) { - items.add(item) - } -} - -@PreferenceMarker -class ThemeBuilder(context: Context, @ColorInt text: Int? = null, @ColorRes textRes: Int? = null, - @ColorInt accent: Int? = null, @ColorRes accentRes: Int? = null, - @ColorInt background: Int? = null, @ColorRes backgroundRes: Int? = null) { - val textColor = text ?: textRes?.toColor(context) - val accentColor = accent ?: accentRes?.toColor(context) - val backgroundColor = background ?: backgroundRes?.toColor(context) -} - -@PreferenceMarker -class PrefItem<T>( - context: Context, - val key: String, - title: String? = null, - @StringRes titleRes: Int? = null, - description: String? = null, - @StringRes descriptionRes: Int? = null, - val onClick: (key: String, current: T, callback: (T) -> Unit) -> Unit, - val iicon: IIcon? = null, - val getter: (key: String) -> T, - val setter: (key: String, value: T) -> Unit -) { - val title: String = titleRes?.toString(context) ?: title ?: "" - val description: String = descriptionRes?.toString(context) ?: description ?: "" - val originalValue: T by lazy { getter.invoke(key) } -} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt deleted file mode 100644 index 311ce051..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceCheckboxView.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.content.Context -import android.content.res.ColorStateList -import android.support.annotation.ColorInt -import android.view.View - -/** - * Created by Allan Wang on 2017-06-06. - */ -class PreferenceCheckboxView(context: Context, builder: PrefItem<Boolean>, themeBuilder: ThemeBuilder?) : PreferenceView<Boolean>(context, builder, themeBuilder) { - - init { - checkbox.visibility = View.VISIBLE - } - - override fun viewWithClick() = checkbox - - override fun setAccentColor(@ColorInt color: Int) { - val state = ColorStateList.valueOf(color) - checkbox.buttonTintList = state - icon.imageTintList = state - } -}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt b/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt deleted file mode 100644 index 60c3bb9d..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/preferences/PreferenceView.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.pitchedapps.frost.preferences - -import android.annotation.SuppressLint -import android.content.Context -import android.support.annotation.ColorInt -import android.view.View -import android.widget.CheckBox -import android.widget.ImageView -import android.widget.LinearLayout -import android.widget.TextView -import butterknife.ButterKnife -import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.bindView -import com.pitchedapps.frost.utils.toDrawable - -@SuppressLint("ViewConstructor") -/** - * Created by Allan Wang on 2017-06-06. - */ -open class PreferenceView<T>( - context: Context, builder: PrefItem<T>, themeBuilder: ThemeBuilder? -) : LinearLayout(context) { - - val iconFrame: LinearLayout by bindView(R.id.icon_frame) - val icon: ImageView by bindView(R.id.icon) - val title: TextView by bindView(R.id.title) - val desc: TextView by bindView(R.id.summary) - val checkbox: CheckBox by bindView(R.id.checkbox) - val key = builder.key - private val getter = builder.getter - private val setter = builder.setter - var pref: T - get() = getter.invoke(key) - set(value) { - setter.invoke(key, value) - } - val original = pref - val hasChanged: Boolean - get() = original == pref - - init { - ButterKnife.bind(this) - title.text = builder.title - desc.text = builder.description - if (builder.iicon == null) iconFrame.visibility = View.GONE - else icon.setImageDrawable(builder.iicon.toDrawable(context, sizeDp = 48)) - if (themeBuilder != null) { - with(themeBuilder) { - if (textColor != null) setTextColor(textColor) - if (accentColor != null) setAccentColor(accentColor) - } - } - setClick(builder.onClick) - } - - fun setClick(listener: (key: String, current: T, callback: (T) -> Unit) -> Unit) { - viewWithClick().setOnClickListener { - listener.invoke(key, pref, { pref = it }) - } - } - - open fun viewWithClick(): View = this - - open fun setTextColor(@ColorInt color: Int) { - title.setTextColor(color) - desc.setTextColor(color) - desc.alpha = 0.7f - } - - //Accent color is not needed for basic prefs - open fun setAccentColor(@ColorInt color: Int) {} - -}
\ No newline at end of file |