Skip to content

Commit

Permalink
Fix search menu click
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Mar 20, 2024
1 parent a3e509f commit f4ead5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
}

Expand Down

0 comments on commit f4ead5c

Please sign in to comment.