parent
ba34b7b69f
commit
29402a297e
|
@ -5,6 +5,7 @@
|
|||
package org.mozilla.fenix.components
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.work.WorkManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
@ -24,7 +25,6 @@ import mozilla.components.service.fxa.manager.FxaAccountManager
|
|||
import mozilla.components.support.base.log.logger.Logger
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.Experiments
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.isInExperiment
|
||||
import org.mozilla.fenix.test.Mockable
|
||||
|
||||
|
@ -87,11 +87,13 @@ class BackgroundServices(
|
|||
emptyList()
|
||||
}
|
||||
|
||||
private val defaultDeviceName = Build.MANUFACTURER + " " + Build.MODEL
|
||||
|
||||
val accountManager = FxaAccountManager(
|
||||
context,
|
||||
config,
|
||||
scopes,
|
||||
DeviceTuple(context.getString(R.string.app_name), DeviceType.MOBILE, deviceCapabilities),
|
||||
DeviceTuple(defaultDeviceName, DeviceType.MOBILE, deviceCapabilities),
|
||||
syncManager
|
||||
).also {
|
||||
it.registerForDeviceEvents(deviceEventObserver, ProcessLifecycleOwner.get(), true)
|
||||
|
|
|
@ -31,6 +31,7 @@ import mozilla.components.service.fxa.FxaPanicException
|
|||
import mozilla.components.service.fxa.manager.FxaAccountManager
|
||||
import mozilla.components.support.base.log.logger.Logger
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
|
@ -117,6 +118,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
|
|||
onPreferenceChangeListener = getChangeListenerForDeviceName()
|
||||
deviceConstellation?.state()?.currentDevice?.let { device ->
|
||||
summary = device.displayName
|
||||
text = device.displayName
|
||||
}
|
||||
setOnBindEditTextListener { editText ->
|
||||
editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH))
|
||||
|
@ -158,6 +160,13 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
|
|||
|
||||
private fun getChangeListenerForDeviceName(): Preference.OnPreferenceChangeListener {
|
||||
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.
|
||||
val deviceNameKey = context!!.getPreferenceKey(R.string.pref_key_sync_device_name)
|
||||
val preferenceDeviceName = findPreference<Preference>(deviceNameKey)
|
||||
|
@ -175,7 +184,6 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
|
|||
Logger.error("Setting device name failed.", e)
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,8 @@
|
|||
<string name="preferences_sign_out">Sign out</string>
|
||||
<!-- Preference displays and allows changing current FxA device name -->
|
||||
<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 -->
|
||||
<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 -->
|
||||
|
|
Loading…
Reference in New Issue