2019-02-21 01:27:11 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.settings
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.widget.Switch
|
|
|
|
import androidx.preference.Preference
|
|
|
|
import androidx.preference.PreferenceViewHolder
|
|
|
|
import org.mozilla.fenix.R
|
2020-01-04 10:35:46 +01:00
|
|
|
import org.mozilla.fenix.utils.BrowsersCache
|
2019-02-21 01:27:11 +01:00
|
|
|
|
2019-06-23 19:26:32 +02:00
|
|
|
class DefaultBrowserPreference @JvmOverloads constructor(
|
|
|
|
context: Context,
|
2019-07-01 18:02:40 +02:00
|
|
|
attrs: AttributeSet? = null
|
|
|
|
) : Preference(context, attrs) {
|
2019-02-21 01:27:11 +01:00
|
|
|
|
|
|
|
private var switchView: Switch? = null
|
|
|
|
|
|
|
|
init {
|
|
|
|
widgetLayoutResource = R.layout.preference_default_browser
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
|
|
|
super.onBindViewHolder(holder)
|
|
|
|
switchView = holder.findViewById(R.id.switch_widget) as Switch
|
|
|
|
|
|
|
|
updateSwitch()
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:27:47 +01:00
|
|
|
fun updateSwitch() {
|
2020-01-04 10:35:46 +01:00
|
|
|
val browsers = BrowsersCache.all(context)
|
2019-02-21 01:27:11 +01:00
|
|
|
switchView?.isChecked = browsers.isDefaultBrowser
|
|
|
|
}
|
|
|
|
}
|