1
0
Fork 0

For #3317: Prepopulate FxA device name field with existing name (#3733)

master
Yeon Taek Jeong 2019-07-03 08:38:09 -07:00 committed by Sawyer Blatz
parent ba34b7b69f
commit 29402a297e
3 changed files with 15 additions and 3 deletions

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.components package org.mozilla.fenix.components
import android.content.Context import android.content.Context
import android.os.Build
import androidx.lifecycle.ProcessLifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner
import androidx.work.WorkManager import androidx.work.WorkManager
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -24,7 +25,6 @@ import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.Experiments import org.mozilla.fenix.Experiments
import org.mozilla.fenix.R
import org.mozilla.fenix.isInExperiment import org.mozilla.fenix.isInExperiment
import org.mozilla.fenix.test.Mockable import org.mozilla.fenix.test.Mockable
@ -87,11 +87,13 @@ class BackgroundServices(
emptyList() emptyList()
} }
private val defaultDeviceName = Build.MANUFACTURER + " " + Build.MODEL
val accountManager = FxaAccountManager( val accountManager = FxaAccountManager(
context, context,
config, config,
scopes, scopes,
DeviceTuple(context.getString(R.string.app_name), DeviceType.MOBILE, deviceCapabilities), DeviceTuple(defaultDeviceName, DeviceType.MOBILE, deviceCapabilities),
syncManager syncManager
).also { ).also {
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), true) it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), true)

View File

@ -31,6 +31,7 @@ import mozilla.components.service.fxa.FxaPanicException
import mozilla.components.service.fxa.manager.FxaAccountManager import mozilla.components.service.fxa.manager.FxaAccountManager
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
@ -117,6 +118,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = getChangeListenerForDeviceName() onPreferenceChangeListener = getChangeListenerForDeviceName()
deviceConstellation?.state()?.currentDevice?.let { device -> deviceConstellation?.state()?.currentDevice?.let { device ->
summary = device.displayName summary = device.displayName
text = device.displayName
} }
setOnBindEditTextListener { editText -> setOnBindEditTextListener { editText ->
editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH)) editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH))
@ -158,6 +160,13 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
private fun getChangeListenerForDeviceName(): Preference.OnPreferenceChangeListener { private fun getChangeListenerForDeviceName(): Preference.OnPreferenceChangeListener {
return Preference.OnPreferenceChangeListener { _, newValue -> return Preference.OnPreferenceChangeListener { _, newValue ->
// The network request requires a nonempty string, so don't persist any changes if the user inputs one.
if (newValue.toString().trim().isEmpty()) {
FenixSnackbar.make(view!!, FenixSnackbar.LENGTH_LONG)
.setText(getString(R.string.empty_device_name_error))
.show()
return@OnPreferenceChangeListener false
}
// Optimistically set the device name to what user requested. // Optimistically set the device name to what user requested.
val deviceNameKey = context!!.getPreferenceKey(R.string.pref_key_sync_device_name) val deviceNameKey = context!!.getPreferenceKey(R.string.pref_key_sync_device_name)
val preferenceDeviceName = findPreference<Preference>(deviceNameKey) val preferenceDeviceName = findPreference<Preference>(deviceNameKey)
@ -175,7 +184,6 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
Logger.error("Setting device name failed.", e) Logger.error("Setting device name failed.", e)
} }
} }
true true
} }
} }

View File

@ -155,6 +155,8 @@
<string name="preferences_sign_out">Sign out</string> <string name="preferences_sign_out">Sign out</string>
<!-- Preference displays and allows changing current FxA device name --> <!-- Preference displays and allows changing current FxA device name -->
<string name="preferences_sync_device_name">Device name</string> <string name="preferences_sync_device_name">Device name</string>
<!-- Text shown when user enters empty device name -->
<string name="empty_device_name_error">Device name cannot be empty.</string>
<!-- Label indicating that sync is in progress --> <!-- Label indicating that sync is in progress -->
<string name="sync_syncing_in_progress">Syncing…</string> <string name="sync_syncing_in_progress">Syncing…</string>
<!-- Label summary indicating that sync failed. The first parameter is the date stamp showing last time it succeeded --> <!-- Label summary indicating that sync failed. The first parameter is the date stamp showing last time it succeeded -->