Use @JvmOverloads instead of multiple constructors
parent
94e99cf877
commit
6bf8d6be34
|
@ -8,6 +8,7 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import kotlinx.android.synthetic.main.library_list_item.view.*
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
|
@ -19,28 +20,18 @@ class LibraryListItem @JvmOverloads constructor(
|
|||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.library_list_item, this, true)
|
||||
|
||||
attrs.let {
|
||||
context.theme.obtainStyledAttributes(
|
||||
it,
|
||||
R.styleable.LibraryListItem,
|
||||
0, 0
|
||||
).apply {
|
||||
try {
|
||||
val id = getResourceId(
|
||||
R.styleable.LibraryListItem_listItemIcon,
|
||||
R.drawable.library_icon_reading_list_circle_background
|
||||
)
|
||||
libraryIcon?.background = resources.getDrawable(id, context.theme)
|
||||
libraryItemTitle?.text = resources.getString(
|
||||
getResourceId(
|
||||
R.styleable.LibraryListItem_listItemTitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
context.withStyledAttributes(attrs, R.styleable.LibraryListItem, defStyleAttr, 0) {
|
||||
val id = getResourceId(
|
||||
R.styleable.LibraryListItem_listItemIcon,
|
||||
R.drawable.library_icon_reading_list_circle_background
|
||||
)
|
||||
libraryIcon?.background = resources.getDrawable(id, context.theme)
|
||||
libraryItemTitle?.text = resources.getString(
|
||||
getResourceId(
|
||||
R.styleable.LibraryListItem_listItemTitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ import androidx.preference.Preference
|
|||
import androidx.preference.PreferenceViewHolder
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class AccountAuthErrorPreference : Preference {
|
||||
class AccountAuthErrorPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attributeSetId: Int = 0
|
||||
) : Preference(context, attrs, attributeSetId) {
|
||||
var email: String? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, attributeSetId: Int) : super(context, attrs, attributeSetId)
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.account_auth_error_preference
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ import androidx.preference.Preference
|
|||
import androidx.preference.PreferenceViewHolder
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class AccountPreference : Preference {
|
||||
class AccountPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attributeSetId: Int = 0
|
||||
) : Preference(context, attrs, attributeSetId) {
|
||||
var displayName: String? = null
|
||||
var email: String? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, attributeSetId: Int) : super(context, attrs, attributeSetId)
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.account_preference
|
||||
}
|
||||
|
|
|
@ -12,18 +12,14 @@ import androidx.preference.PreferenceViewHolder
|
|||
import mozilla.components.support.utils.Browsers
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class DefaultBrowserPreference : Preference {
|
||||
class DefaultBrowserPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attributeSetId: Int = 0
|
||||
) : Preference(context, attrs, attributeSetId) {
|
||||
|
||||
private var switchView: Switch? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, attributeSetId: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
attributeSetId
|
||||
)
|
||||
|
||||
init {
|
||||
widgetLayoutResource = R.layout.preference_default_browser
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.util.AttributeSet
|
|||
import android.view.LayoutInflater
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import kotlinx.android.synthetic.main.delete_browsing_data_item.view.*
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
|
@ -41,33 +42,23 @@ class DeleteBrowsingDataItem @JvmOverloads constructor(
|
|||
onCheckListener?.invoke(isChecked)
|
||||
}
|
||||
|
||||
attrs.let {
|
||||
context.theme.obtainStyledAttributes(
|
||||
it,
|
||||
R.styleable.DeleteBrowsingDataItem,
|
||||
0, 0
|
||||
).apply {
|
||||
try {
|
||||
val iconId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemIcon,
|
||||
R.drawable.library_icon_reading_list_circle_background
|
||||
)
|
||||
val titleId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemTitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
val subtitleId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemSubtitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
context.withStyledAttributes(attrs, R.styleable.DeleteBrowsingDataItem, defStyleAttr, 0) {
|
||||
val iconId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemIcon,
|
||||
R.drawable.library_icon_reading_list_circle_background
|
||||
)
|
||||
val titleId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemTitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
val subtitleId = getResourceId(
|
||||
R.styleable.DeleteBrowsingDataItem_deleteBrowsingDataItemSubtitle,
|
||||
R.string.browser_menu_your_library
|
||||
)
|
||||
|
||||
icon.background = resources.getDrawable(iconId, context.theme)
|
||||
title.text = resources.getString(titleId)
|
||||
subtitle.text = resources.getString(subtitleId)
|
||||
} finally {
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
icon.background = resources.getDrawable(iconId, context.theme)
|
||||
title.text = resources.getString(titleId)
|
||||
subtitle.text = resources.getString(subtitleId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package org.mozilla.fenix.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
@ -13,6 +12,7 @@ import android.widget.RadioButton
|
|||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.TypedArrayUtils
|
||||
import androidx.core.content.withStyledAttributes
|
||||
import androidx.core.text.HtmlCompat
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
|
@ -20,7 +20,11 @@ import org.mozilla.fenix.R
|
|||
import org.mozilla.fenix.ThemeManager
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class RadioButtonPreference : Preference {
|
||||
class RadioButtonPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
attributeSetId: Int = 0
|
||||
) : Preference(context, attrs, attributeSetId) {
|
||||
private val radioGroups = mutableListOf<RadioButtonPreference>()
|
||||
private lateinit var summaryView: TextView
|
||||
private lateinit var radioButton: RadioButton
|
||||
|
@ -30,6 +34,27 @@ class RadioButtonPreference : Preference {
|
|||
|
||||
init {
|
||||
layoutResource = R.layout.preference_widget_radiobutton
|
||||
|
||||
context.withStyledAttributes(
|
||||
attrs,
|
||||
androidx.preference.R.styleable.Preference,
|
||||
TypedArrayUtils.getAttr(
|
||||
context, androidx.preference.R.attr.preferenceStyle, android.R.attr.preferenceStyle
|
||||
),
|
||||
0
|
||||
) {
|
||||
if (hasValue(androidx.preference.R.styleable.Preference_defaultValue)) {
|
||||
defaultValue = getBoolean(
|
||||
androidx.preference.R.styleable.Preference_defaultValue,
|
||||
false
|
||||
)
|
||||
} else if (hasValue(androidx.preference.R.styleable.Preference_android_defaultValue)) {
|
||||
defaultValue = getBoolean(
|
||||
androidx.preference.R.styleable.Preference_android_defaultValue,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* In devices with Android 6, when we use android:button="@null" android:drawableStart doesn't work via xml
|
||||
|
@ -45,16 +70,6 @@ class RadioButtonPreference : Preference {
|
|||
this.setCompoundDrawables(buttonDrawable, null, null, null)
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
val typedArray = context.obtainStyledAttributes(
|
||||
attrs, androidx.preference.R.styleable.Preference, TypedArrayUtils.getAttr(
|
||||
context, androidx.preference.R.attr.preferenceStyle,
|
||||
android.R.attr.preferenceStyle
|
||||
), 0
|
||||
)
|
||||
initDefaultValue(typedArray)
|
||||
}
|
||||
|
||||
fun addToRadioGroup(radioPreference: RadioButtonPreference) {
|
||||
radioGroups.add(radioPreference)
|
||||
}
|
||||
|
@ -94,20 +109,6 @@ class RadioButtonPreference : Preference {
|
|||
radioButton.setStartCheckedIndicator()
|
||||
}
|
||||
|
||||
private fun initDefaultValue(typedArray: TypedArray) {
|
||||
if (typedArray.hasValue(androidx.preference.R.styleable.Preference_defaultValue)) {
|
||||
defaultValue = typedArray.getBoolean(
|
||||
androidx.preference.R.styleable.Preference_defaultValue,
|
||||
false
|
||||
)
|
||||
} else if (typedArray.hasValue(androidx.preference.R.styleable.Preference_android_defaultValue)) {
|
||||
defaultValue = typedArray.getBoolean(
|
||||
androidx.preference.R.styleable.Preference_android_defaultValue,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleRadioGroups() {
|
||||
if (radioButton.isChecked) {
|
||||
radioGroups.forEach { it.updateRadioValue(false) }
|
||||
|
|
|
@ -12,18 +12,14 @@ import org.mozilla.fenix.R
|
|||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.utils.Settings
|
||||
|
||||
class RadioSearchEngineListPreference : SearchEngineListPreference {
|
||||
class RadioSearchEngineListPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : SearchEngineListPreference(context, attrs, defStyleAttr) {
|
||||
override val itemResId: Int
|
||||
get() = R.layout.search_engine_radio_button
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
override fun updateDefaultItem(defaultButton: CompoundButton) {
|
||||
defaultButton.isChecked = true
|
||||
}
|
||||
|
|
|
@ -28,7 +28,11 @@ import org.mozilla.fenix.ext.components
|
|||
import org.mozilla.fenix.utils.Settings
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
abstract class SearchEngineListPreference : Preference, CompoundButton.OnCheckedChangeListener, CoroutineScope {
|
||||
abstract class SearchEngineListPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : Preference(context, attrs, defStyleAttr), CompoundButton.OnCheckedChangeListener, CoroutineScope {
|
||||
private val job = Job()
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = job + Dispatchers.Main
|
||||
|
@ -37,15 +41,7 @@ abstract class SearchEngineListPreference : Preference, CompoundButton.OnChecked
|
|||
|
||||
protected abstract val itemResId: Int
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
layoutResource = R.layout.preference_search_engine_chooser
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
) {
|
||||
init {
|
||||
layoutResource = R.layout.preference_search_engine_chooser
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue