Remember activity for monitor

This commit is contained in:
Mygod
2019-07-05 01:40:03 +08:00
parent 931a424fc7
commit f629efc4f0

View File

@@ -105,12 +105,13 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
} }
private fun updateMonitorList(canMonitor: List<String> = emptyList()) { private fun updateMonitorList(canMonitor: List<String> = emptyList()) {
val activity = activity
val item = activity?.toolbar?.menu?.findItem(R.id.monitor) ?: return // assuming no longer foreground val item = activity?.toolbar?.menu?.findItem(R.id.monitor) ?: return // assuming no longer foreground
item.isNotGone = canMonitor.isNotEmpty() item.isNotGone = canMonitor.isNotEmpty()
item.subMenu.apply { item.subMenu.apply {
clear() clear()
for (iface in canMonitor.sorted()) add(iface).setOnMenuItemClickListener { for (iface in canMonitor.sorted()) add(iface).setOnMenuItemClickListener {
ContextCompat.startForegroundService(requireContext(), Intent(context, TetheringService::class.java) ContextCompat.startForegroundService(activity, Intent(activity, TetheringService::class.java)
.putExtra(TetheringService.EXTRA_ADD_INTERFACE_MONITOR, iface)) .putExtra(TetheringService.EXTRA_ADD_INTERFACE_MONITOR, iface))
true true
} }