Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #24919: Add option menu in the address editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed May 9, 2022
1 parent eba8cd9 commit ff444ba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand All @@ -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 changes: 20 additions & 0 deletions app/src/main/res/menu/address_editor.xml
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit ff444ba

Please sign in to comment.