Skip to content

Commit

Permalink
setHasOptionsMenu is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
justdave committed May 20, 2024
1 parent 179eb2e commit 306bfb6
Showing 1 changed file with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ package net.justdave.nwsweatheralertswidget

import android.os.Bundle
import android.util.Log
import android.view.*
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.view.MenuHost
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
Expand All @@ -18,8 +25,28 @@ class AlertsDisplayFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
(requireActivity() as MenuHost).addMenuProvider(object: MenuProvider{
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.alerts_display_options, menu)
}

setHasOptionsMenu(true)
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.option_debug -> {
findNavController().navigate(AlertsDisplayFragmentDirections.actionAlertsDisplayFragmentToDebugFragment())
return true
}
R.id.action_about -> {
val about = AboutDialog(requireActivity())
about.setTitle(R.string.action_about)
about.show()
return true
}

}
return false
}
})

binding = AlertsDisplayFragmentBinding.inflate(inflater, container, false)
binding.parsedEvents.emptyView = binding.emptytext
Expand All @@ -45,29 +72,5 @@ class AlertsDisplayFragment : Fragment() {
}*/
}

@Deprecated("Deprecated in Java")
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
//super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.alerts_display_options, menu)
}

@Deprecated("Deprecated in Java")
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle item selection
return when (item.itemId) {
R.id.option_debug -> {
findNavController().navigate(AlertsDisplayFragmentDirections.actionAlertsDisplayFragmentToDebugFragment())
true
}
R.id.action_about -> {
val about = AboutDialog(requireActivity())
about.setTitle(R.string.action_about)
about.show()
true
}
else -> super.onOptionsItemSelected(item)
}
}

}

0 comments on commit 306bfb6

Please sign in to comment.