mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Merge pull request #5305 from Isira-Seneviratne/TypedArray_use
refactor: Use TypedArray.use() extension
This commit is contained in:
commit
3c13ec0c46
@ -5,6 +5,7 @@ import android.util.AttributeSet
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import androidx.core.content.res.use
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.DropdownMenuBinding
|
import com.github.libretube.databinding.DropdownMenuBinding
|
||||||
|
|
||||||
@ -30,15 +31,10 @@ class DropdownMenu(
|
|||||||
get() = adapter.getPosition(binding.autoCompleteTextView.text.toString())
|
get() = adapter.getPosition(binding.autoCompleteTextView.text.toString())
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val ta = context.obtainStyledAttributes(attributeSet, R.styleable.DropdownMenu, 0, 0)
|
context.obtainStyledAttributes(attributeSet, R.styleable.DropdownMenu, 0, 0).use {
|
||||||
|
binding.textInputLayout.hint = it.getString(R.styleable.DropdownMenu_hint)
|
||||||
try {
|
binding.textInputLayout.startIconDrawable =
|
||||||
binding.textInputLayout.hint = ta.getString(R.styleable.DropdownMenu_hint)
|
it.getDrawable(R.styleable.DropdownMenu_icon)
|
||||||
binding.textInputLayout.startIconDrawable = ta.getDrawable(
|
|
||||||
R.styleable.DropdownMenu_icon
|
|
||||||
)
|
|
||||||
} finally {
|
|
||||||
ta.recycle()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,41 +17,25 @@ import kotlin.math.roundToInt
|
|||||||
class SliderPreference(
|
class SliderPreference(
|
||||||
context: Context,
|
context: Context,
|
||||||
attributeSet: AttributeSet
|
attributeSet: AttributeSet
|
||||||
) : Preference(
|
) : Preference(context, attributeSet) {
|
||||||
context,
|
|
||||||
attributeSet
|
|
||||||
) {
|
|
||||||
private lateinit var sliderBinding: DialogSliderBinding
|
private lateinit var sliderBinding: DialogSliderBinding
|
||||||
private var defValue = 0f
|
private val defValue: Float
|
||||||
private var valueFrom = 1f
|
private val valueFrom: Float
|
||||||
private var valueTo = 10f
|
private val valueTo: Float
|
||||||
private var stepSize = 1f
|
private val stepSize: Float
|
||||||
|
|
||||||
|
init {
|
||||||
|
val ta = context.obtainStyledAttributes(attributeSet, R.styleable.SliderPreference)
|
||||||
|
defValue = ta.getFloat(R.styleable.SliderPreference_defValue, 0f)
|
||||||
|
valueFrom = ta.getFloat(R.styleable.SliderPreference_valueFrom, 1f)
|
||||||
|
valueTo = ta.getFloat(R.styleable.SliderPreference_valueTo, 10f)
|
||||||
|
stepSize = ta.getFloat(R.styleable.SliderPreference_stepSize, 1f)
|
||||||
|
ta.recycle()
|
||||||
|
}
|
||||||
|
|
||||||
private var prefValue: Float
|
private var prefValue: Float
|
||||||
get() = PreferenceHelper.getString(
|
get() = PreferenceHelper.getString(key, defValue.toString()).toFloat()
|
||||||
key,
|
set(value) = PreferenceHelper.putString(key, value.toString())
|
||||||
defValue.toString()
|
|
||||||
).toFloat()
|
|
||||||
set(value) {
|
|
||||||
PreferenceHelper.putString(
|
|
||||||
key,
|
|
||||||
value.toString()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val typedArray = context.obtainStyledAttributes(
|
|
||||||
attributeSet,
|
|
||||||
R.styleable.SliderPreference
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun onAttached() {
|
|
||||||
super.onAttached()
|
|
||||||
|
|
||||||
defValue = typedArray.getFloat(R.styleable.SliderPreference_defValue, defValue)
|
|
||||||
valueFrom = typedArray.getFloat(R.styleable.SliderPreference_valueFrom, valueFrom)
|
|
||||||
valueTo = typedArray.getFloat(R.styleable.SliderPreference_valueTo, valueTo)
|
|
||||||
stepSize = typedArray.getFloat(R.styleable.SliderPreference_stepSize, stepSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getSummary(): CharSequence = getDisplayedCurrentValue(prefValue)
|
override fun getSummary(): CharSequence = getDisplayedCurrentValue(prefValue)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user