2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/24919: Add option menu in the address editor.

This commit is contained in:
mcarare 2022-05-03 16:57:47 +03:00 committed by mergify[bot]
parent adc764ca0a
commit 785b88334c
3 changed files with 56 additions and 0 deletions

View File

@ -5,6 +5,9 @@
package org.mozilla.fenix.settings.address package org.mozilla.fenix.settings.address
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View import android.view.View
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
@ -36,6 +39,8 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
private val isEditing: Boolean private val isEditing: Boolean
get() = args.address != null get() = args.address != null
private lateinit var menu: Menu
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -50,11 +55,17 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
) )
val binding = FragmentAddressEditorBinding.bind(view) val binding = FragmentAddressEditorBinding.bind(view)
setHasOptionsMenu(true)
addressEditorView = AddressEditorView(binding, interactor, args.address) addressEditorView = AddressEditorView(binding, interactor, args.address)
addressEditorView.bind() addressEditorView.bind()
} }
override fun onPause() {
super.onPause()
menu.close()
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (isEditing) { if (isEditing) {
@ -68,4 +79,25 @@ class AddressEditorFragment : SecureFragment(R.layout.fragment_address_editor) {
super.onStop() super.onStop()
this.view?.hideKeyboard() 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
}
} }

View 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>

View File

@ -1582,6 +1582,10 @@
<string name="addressess_confirm_dialog_ok_button">Delete</string> <string name="addressess_confirm_dialog_ok_button">Delete</string>
<!-- The text for the negative button on "Delete address" dialog --> <!-- The text for the negative button on "Delete address" dialog -->
<string name="addressess_confirm_dialog_cancel_button">Cancel</string> <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 --> <!-- Title of the Add search engine screen -->
<string name="search_engine_add_custom_search_engine_title">Add search engine</string> <string name="search_engine_add_custom_search_engine_title">Add search engine</string>