Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile Payments] Remove duplicate back button from the Try Tap to Pay customer provided note screen #12787

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package com.woocommerce.android.ui.payments.simplepayments

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.core.view.MenuProvider
import androidx.core.widget.doAfterTextChanged
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.FragmentOrderCreateEditCustomerNoteBinding
import com.woocommerce.android.extensions.navigateBackWithResult
import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.main.AppBarStatus
import org.wordpress.android.util.ActivityUtils
import org.wordpress.android.util.DisplayUtils

class SimplePaymentsCustomerNoteFragment :
BaseFragment(R.layout.fragment_order_create_edit_customer_note),
MenuProvider {
BaseFragment(R.layout.fragment_order_create_edit_customer_note) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 I think we are not using any functionality provided by BaseFragment, so I suggest switching to the plain Fragment class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using override val activityAppBarStatus: AppBarStatus get() = AppBarStatus.Hidden from BaseFragment to hide the default toolbar and use our own. I think using plain Fragment would again cause multiple toolbar (one from our own custom toolbar and another that exist from previous screen)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you're right 👍🏼

private var _binding: FragmentOrderCreateEditCustomerNoteBinding? = null
val binding
get() = _binding!!

private val navArgs: SimplePaymentsCustomerNoteFragmentArgs by navArgs()
private lateinit var doneMenuItem: MenuItem

override val activityAppBarStatus: AppBarStatus
get() = AppBarStatus.Hidden

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
requireActivity().addMenuProvider(this, viewLifecycleOwner)

_binding = FragmentOrderCreateEditCustomerNoteBinding.bind(view)
setupToolbar()
if (savedInstanceState == null) {
binding.customerOrderNoteEditor.setText(navArgs.customerNote)
if (binding.customerOrderNoteEditor.requestFocus() && !DisplayUtils.isLandscape(requireActivity())) {
Expand All @@ -49,6 +50,17 @@ class SimplePaymentsCustomerNoteFragment :
}
}

private fun setupToolbar() {
binding.toolbar.title = getString(R.string.orderdetail_customer_provided_note)
onCreateMenu(_binding)
binding.toolbar.setOnMenuItemClickListener { menuItem ->
onMenuItemSelected(menuItem)
}
binding.toolbar.setNavigationOnClickListener {
findNavController().navigateUp()
}
}

override fun onResume() {
super.onResume()
AnalyticsTracker.trackViewShown(this)
Expand All @@ -59,14 +71,13 @@ class SimplePaymentsCustomerNoteFragment :
_binding = null
}

override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
menu.clear()
inflater.inflate(R.menu.menu_done, menu)
doneMenuItem = menu.findItem(R.id.menu_done)
private fun onCreateMenu(binding: FragmentOrderCreateEditCustomerNoteBinding?) {
binding?.toolbar?.inflateMenu(R.menu.menu_done)
doneMenuItem = binding?.toolbar?.menu?.findItem(R.id.menu_done)!!
doneMenuItem.isEnabled = hasChanges()
}

override fun onMenuItemSelected(item: MenuItem): Boolean {
private fun onMenuItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.menu_done -> {
navigateBackWithResult(
Expand All @@ -79,8 +90,6 @@ class SimplePaymentsCustomerNoteFragment :
}
}

override fun getFragmentTitle() = getString(R.string.orderdetail_customer_provided_note)

private fun hasChanges() =
binding.customerOrderNoteEditor.text.toString() != navArgs.customerNote

Expand Down
Loading