From f4ead5cebf1936d60be261d06b765e5a4f1d11f6 Mon Sep 17 00:00:00 2001 From: brahmkshatriya <69040506+brahmkshatriya@users.noreply.github.com> Date: Wed, 20 Mar 2024 19:44:13 +0530 Subject: [PATCH] Fix search menu click --- .../echo/ui/adapters/HeaderAdapter.kt | 37 +++++++++++-------- .../echo/ui/adapters/SearchHeaderAdapter.kt | 20 +--------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/HeaderAdapter.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/HeaderAdapter.kt index 435cf10c..8da6f4d4 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/HeaderAdapter.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/HeaderAdapter.kt @@ -3,6 +3,7 @@ package dev.brahmkshatriya.echo.ui.adapters import android.content.Intent import android.os.Parcelable import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import androidx.core.view.isVisible import androidx.navigation.findNavController @@ -31,21 +32,7 @@ class HeaderAdapter( val binding = holder.binding binding.topAppBarHeader.setText(header) binding.topAppBar.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.menu_settings -> { - val intent = Intent(binding.root.context, SettingsActivity::class.java) - binding.root.context.startActivity(intent) - true - } - - R.id.menu_extensions -> { - val action = ExtensionDialogFragmentDirections.actionExtension() - binding.root.findNavController().navigate(action) - true - } - - else -> false - } + menuItemClicked(menuItem.itemId, binding.root) } binding.chipRecyclerView.apply { adapter = ChipAdapter { @@ -74,4 +61,24 @@ class HeaderAdapter( this.chips = chips notifyItemChanged(0) } + + companion object { + fun menuItemClicked(id: Int, view: View): Boolean { + return when (id) { + R.id.menu_settings -> { + val intent = Intent(view.context, SettingsActivity::class.java) + view.context.startActivity(intent) + true + } + + R.id.menu_extensions -> { + val action = ExtensionDialogFragmentDirections.actionExtension() + view.findNavController().navigate(action) + true + } + + else -> false + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/SearchHeaderAdapter.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/SearchHeaderAdapter.kt index f886595e..9e4871ec 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/SearchHeaderAdapter.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/adapters/SearchHeaderAdapter.kt @@ -2,13 +2,9 @@ package dev.brahmkshatriya.echo.ui.adapters import android.view.LayoutInflater import android.view.ViewGroup -import androidx.navigation.findNavController import androidx.recyclerview.widget.RecyclerView import com.google.android.material.search.SearchBar -import dev.brahmkshatriya.echo.R import dev.brahmkshatriya.echo.databinding.ItemSearchHeaderBinding -import dev.brahmkshatriya.echo.ui.extension.ExtensionDialogFragmentDirections -import dev.brahmkshatriya.echo.ui.settings.SettingsFragmentDirections class SearchHeaderAdapter( @@ -31,21 +27,7 @@ class SearchHeaderAdapter( searchbar = binding.catSearchBar binding.topAppBar.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.menu_settings -> { - val action = SettingsFragmentDirections.actionSettings() - binding.root.findNavController().navigate(action) - true - } - - R.id.menu_extensions -> { - val action = ExtensionDialogFragmentDirections.actionExtension() - binding.root.findNavController().navigate(action) - true - } - - else -> false - } + HeaderAdapter.menuItemClicked(menuItem.itemId, binding.root) } }