Close #420 - Default Browser Preference reacts to default browser status
parent
53f391de60
commit
2750b65cc3
|
@ -0,0 +1,42 @@
|
||||||
|
/* 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 mozilla.components.support.utils.Browsers
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
|
class DefaultBrowserPreference : Preference {
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||||
|
super.onBindViewHolder(holder)
|
||||||
|
switchView = holder.findViewById(R.id.switch_widget) as Switch
|
||||||
|
|
||||||
|
updateSwitch()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateSwitch() {
|
||||||
|
val browsers = Browsers.all(context)
|
||||||
|
switchView?.isChecked = browsers.isDefaultBrowser
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- 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/. -->
|
||||||
|
|
||||||
|
<Switch xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/switch_widget"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="vertical" />
|
|
@ -40,7 +40,7 @@
|
||||||
android:key="@string/pref_key_credit_cards_addresses"
|
android:key="@string/pref_key_credit_cards_addresses"
|
||||||
android:title="@string/preferences_credit_cards_addresses" />
|
android:title="@string/preferences_credit_cards_addresses" />
|
||||||
|
|
||||||
<androidx.preference.SwitchPreference
|
<org.mozilla.fenix.settings.DefaultBrowserPreference
|
||||||
android:key="@string/pref_key_make_default_browser"
|
android:key="@string/pref_key_make_default_browser"
|
||||||
android:title="@string/preferences_set_as_default_browser" />
|
android:title="@string/preferences_set_as_default_browser" />
|
||||||
</androidx.preference.PreferenceCategory>
|
</androidx.preference.PreferenceCategory>
|
||||||
|
|
Loading…
Reference in New Issue