51 lines
2.2 KiB
Kotlin
51 lines
2.2 KiB
Kotlin
/* 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.os.Bundle
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.preference.Preference
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
import org.mozilla.fenix.BrowserDirection
|
|
import org.mozilla.fenix.HomeActivity
|
|
import org.mozilla.fenix.R
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
|
|
class TurnOnSyncFragment : PreferenceFragmentCompat() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
(activity as AppCompatActivity).title = getString(R.string.preferences_sync)
|
|
(activity as AppCompatActivity).supportActionBar?.show()
|
|
}
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
setPreferencesFromResource(R.xml.turn_on_sync_preferences, rootKey)
|
|
|
|
val preferenceSignIn =
|
|
findPreference<Preference>(context!!.getPreferenceKey(R.string.pref_key_sync_sign_in))
|
|
val preferenceNewAccount =
|
|
findPreference<Preference>(context!!.getPreferenceKey(R.string.pref_key_sync_create_account))
|
|
preferenceSignIn?.onPreferenceClickListener = getClickListenerForSignIn()
|
|
preferenceNewAccount?.onPreferenceClickListener = getClickListenerForSignIn()
|
|
}
|
|
|
|
private fun getClickListenerForSignIn(): Preference.OnPreferenceClickListener {
|
|
return Preference.OnPreferenceClickListener {
|
|
requireComponents.services.accountsAuthFeature.beginAuthentication()
|
|
// TODO The sign-in web content populates session history,
|
|
// so pressing "back" after signing in won't take us back into the settings screen, but rather up the
|
|
// session history stack.
|
|
// We could auto-close this tab once we get to the end of the authentication process?
|
|
// Via an interceptor, perhaps.
|
|
view?.let {
|
|
(activity as HomeActivity).openToBrowser(BrowserDirection.FromSettings)
|
|
}
|
|
true
|
|
}
|
|
}
|
|
}
|