For #24919: Add option menu in the address editor.
This commit is contained in:
parent
2192d55da3
commit
a4a78717af
|
@ -5,6 +5,9 @@
|
|||
package org.mozilla.fenix.settings.address
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
|
@ -36,6 +39,8 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
|
|||
private val isEditing: Boolean
|
||||
get() = args.address != null
|
||||
|
||||
private lateinit var menu: Menu
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
|
@ -50,11 +55,17 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
|
|||
)
|
||||
|
||||
val binding = FragmentAddressEditorBinding.bind(view)
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
addressEditorView = AddressEditorView(binding, interactor, args.address)
|
||||
addressEditorView.bind()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
menu.close()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (isEditing) {
|
||||
|
@ -68,4 +79,25 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
|
|||
super.onStop()
|
||||
this.view?.hideKeyboard()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.address_editor, menu)
|
||||
this.menu = menu
|
||||
|
||||
menu.findItem(R.id.delete_address_button).isVisible = isEditing
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||
R.id.delete_address_button -> {
|
||||
args.address?.let {
|
||||
addressEditorView.showConfirmDeleteAddressDialog(requireContext(), it.guid)
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.save_address_button -> {
|
||||
addressEditorView.saveAddress()
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
20
app/src/main/res/menu/address_editor.xml
Normal file
20
app/src/main/res/menu/address_editor.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/delete_address_button"
|
||||
android:icon="@drawable/ic_delete"
|
||||
android:title="@string/address_menu_delete_address"
|
||||
android:visible="false"
|
||||
app:iconTint="?attr/textPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/save_address_button"
|
||||
android:icon="@drawable/mozac_ic_check"
|
||||
android:title="@string/address_menu_save_address"
|
||||
app:iconTint="?attr/textPrimary"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
|
@ -1582,6 +1582,10 @@
|
|||
<string name="addressess_confirm_dialog_ok_button">Delete</string>
|
||||
<!-- The text for the negative button on "Delete address" dialog -->
|
||||
<string name="addressess_confirm_dialog_cancel_button">Cancel</string>
|
||||
<!-- The text for the "Save address" menu item for saving an address -->
|
||||
<string name="address_menu_save_address">Save address</string>
|
||||
<!-- The text for the "Delete address" menu item for deleting an address -->
|
||||
<string name="address_menu_delete_address">Delete address</string>
|
||||
|
||||
<!-- Title of the Add search engine screen -->
|
||||
<string name="search_engine_add_custom_search_engine_title">Add search engine</string>
|
||||
|
|
Loading…
Reference in New Issue
Block a user