For #3388: Set max length for device name (#3397)

nightly-build-test
Jonathan Almeida 5 years ago committed by Colin Lee
parent f1088222b4
commit f71bdcfd10

@ -6,10 +6,12 @@ package org.mozilla.fenix.settings
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.text.InputFilter
import android.text.format.DateUtils import android.text.format.DateUtils
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.Navigation import androidx.navigation.Navigation
import androidx.preference.CheckBoxPreference import androidx.preference.CheckBoxPreference
import androidx.preference.EditTextPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceCategory import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
@ -111,11 +113,14 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
// Device Name // Device Name
val deviceConstellation = accountManager.authenticatedAccount()?.deviceConstellation() val deviceConstellation = accountManager.authenticatedAccount()?.deviceConstellation()
val deviceNameKey = context!!.getPreferenceKey(R.string.pref_key_sync_device_name) val deviceNameKey = context!!.getPreferenceKey(R.string.pref_key_sync_device_name)
findPreference<Preference>(deviceNameKey)?.apply { findPreference<EditTextPreference>(deviceNameKey)?.apply {
onPreferenceChangeListener = getChangeListenerForDeviceName() onPreferenceChangeListener = getChangeListenerForDeviceName()
deviceConstellation?.state()?.currentDevice?.let { device -> deviceConstellation?.state()?.currentDevice?.let { device ->
summary = device.displayName summary = device.displayName
} }
setOnBindEditTextListener { editText ->
editText.filters = arrayOf(InputFilter.LengthFilter(DEVICE_NAME_MAX_LENGTH))
}
} }
deviceConstellation?.registerDeviceObserver(deviceConstellationObserver, owner = this, autoPause = true) deviceConstellation?.registerDeviceObserver(deviceConstellationObserver, owner = this, autoPause = true)
@ -257,4 +262,8 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope {
) )
} }
} }
companion object {
private const val DEVICE_NAME_MAX_LENGTH = 128
}
} }

Loading…
Cancel
Save