mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/15675: Disable Save button when editing saved login until something has been changed
set save button state by calling invalidateOptionsMenu, causing onPrepareOptionsMenu to be called which will enable/disable the save button depending on if changes have been made or not
This commit is contained in:
parent
1d8006f733
commit
efc846d57a
@ -13,7 +13,6 @@ import android.view.Menu
|
|||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.view.menu.ActionMenuItemView
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@ -57,7 +56,6 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||||||
|
|
||||||
private var usernameChanged = false
|
private var usernameChanged = false
|
||||||
private var passwordChanged = false
|
private var passwordChanged = false
|
||||||
private var saveEnabled = false
|
|
||||||
|
|
||||||
private var validPassword = true
|
private var validPassword = true
|
||||||
private var validUsername = true
|
private var validUsername = true
|
||||||
@ -90,8 +88,9 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||||||
usernameText.text = args.savedLoginItem.username.toEditable()
|
usernameText.text = args.savedLoginItem.username.toEditable()
|
||||||
passwordText.text = args.savedLoginItem.password.toEditable()
|
passwordText.text = args.savedLoginItem.password.toEditable()
|
||||||
|
|
||||||
|
clearUsernameTextButton.isEnabled = oldLogin.username.isNotEmpty()
|
||||||
|
|
||||||
formatEditableValues()
|
formatEditableValues()
|
||||||
initSaveState()
|
|
||||||
setUpClickListeners()
|
setUpClickListeners()
|
||||||
setUpTextListeners()
|
setUpTextListeners()
|
||||||
togglePasswordReveal(passwordText, revealPasswordButton)
|
togglePasswordReveal(passwordText, revealPasswordButton)
|
||||||
@ -101,18 +100,6 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initSaveState() {
|
|
||||||
saveEnabled = false // don't enable saving until something has been changed
|
|
||||||
val saveButton =
|
|
||||||
activity?.findViewById<ActionMenuItemView>(R.id.save_login_button)
|
|
||||||
saveButton?.isEnabled = saveEnabled
|
|
||||||
|
|
||||||
usernameChanged = false
|
|
||||||
passwordChanged = false
|
|
||||||
|
|
||||||
clearUsernameTextButton.isEnabled = oldLogin.username.isNotEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatEditableValues() {
|
private fun formatEditableValues() {
|
||||||
hostnameText.isClickable = false
|
hostnameText.isClickable = false
|
||||||
hostnameText.isFocusable = false
|
hostnameText.isFocusable = false
|
||||||
@ -263,20 +250,20 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setSaveButtonState() {
|
private fun setSaveButtonState() {
|
||||||
val saveButton = activity?.findViewById<ActionMenuItemView>(R.id.save_login_button)
|
activity?.invalidateOptionsMenu()
|
||||||
val changesMadeWithNoErrors =
|
|
||||||
validUsername && validPassword && (usernameChanged || passwordChanged)
|
|
||||||
|
|
||||||
changesMadeWithNoErrors.let {
|
|
||||||
saveButton?.isEnabled = it
|
|
||||||
saveEnabled = it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
inflater.inflate(R.menu.login_save, menu)
|
inflater.inflate(R.menu.login_save, menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||||
|
val saveButton = menu.findItem(R.id.save_login_button)
|
||||||
|
val changesMadeWithNoErrors =
|
||||||
|
validUsername && validPassword && (usernameChanged || passwordChanged)
|
||||||
|
saveButton.isEnabled = changesMadeWithNoErrors // don't enable saving until something has been changed
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
redirectToReAuth(
|
redirectToReAuth(
|
||||||
listOf(R.id.loginDetailFragment),
|
listOf(R.id.loginDetailFragment),
|
||||||
@ -288,14 +275,12 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||||
R.id.save_login_button -> {
|
R.id.save_login_button -> {
|
||||||
view?.hideKeyboard()
|
view?.hideKeyboard()
|
||||||
if (saveEnabled) {
|
interactor.onSaveLogin(
|
||||||
interactor.onSaveLogin(
|
args.savedLoginItem.guid,
|
||||||
args.savedLoginItem.guid,
|
usernameText.text.toString(),
|
||||||
usernameText.text.toString(),
|
passwordText.text.toString()
|
||||||
passwordText.text.toString()
|
)
|
||||||
)
|
requireComponents.analytics.metrics.track(Event.EditLoginSave)
|
||||||
requireComponents.analytics.metrics.track(Event.EditLoginSave)
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> false
|
else -> false
|
||||||
|
Loading…
Reference in New Issue
Block a user