Migrate to MenuProvider
This commit is contained in:
parent
d1ea43ca5e
commit
c3a8bc687d
16 changed files with 168 additions and 217 deletions
|
@ -295,6 +295,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
this.menu = menu
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
|
@ -306,6 +307,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
super.onOptionsItemSelected(item)
|
||||
when (item.itemId) {
|
||||
R.id.nav_preferences -> {
|
||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -28,6 +30,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange
|
|||
import info.nightscout.androidaps.extensions.iobCalc
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
|
@ -40,7 +43,6 @@ import info.nightscout.androidaps.utils.FabricPrivacy
|
|||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
@ -52,7 +54,7 @@ import io.reactivex.rxjava3.kotlin.subscribeBy
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
||||
class TreatmentsBolusCarbsFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var sp: SP
|
||||
|
@ -93,11 +95,11 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun bolusMealLinksWithInvalid(now: Long) = repository
|
||||
|
@ -215,7 +217,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
holder.binding.bolusInvalid.visibility = bolus.isValid.not().toVisibility()
|
||||
val iob = bolus.iobCalc(activePlugin, System.currentTimeMillis(), profile.dia)
|
||||
if (iob.iobContrib > 0.01) {
|
||||
holder.binding.iob.setTextColor(rh.gac(context , R.attr.activeColor))
|
||||
holder.binding.iob.setTextColor(rh.gac(context, R.attr.activeColor))
|
||||
holder.binding.iob.text = rh.gs(R.string.formatinsulinunits, iob.iobContrib)
|
||||
holder.binding.iobLabel.visibility = View.VISIBLE
|
||||
holder.binding.iob.visibility = View.VISIBLE
|
||||
|
@ -225,8 +227,8 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
holder.binding.iobLabel.visibility = View.GONE
|
||||
holder.binding.iob.visibility = View.GONE
|
||||
}
|
||||
if (bolus.timestamp > dateUtil.now()) holder.binding.date.setTextColor(rh.gac(context, R.attr.scheduledColor)) else holder.binding.date.setTextColor(holder.binding.carbs
|
||||
.currentTextColor)
|
||||
if (bolus.timestamp > dateUtil.now())
|
||||
holder.binding.date.setTextColor(rh.gac(context, R.attr.scheduledColor)) else holder.binding.date.setTextColor(holder.binding.carbs.currentTextColor)
|
||||
holder.binding.mealOrCorrection.text =
|
||||
when (ml.bolus.type) {
|
||||
Bolus.Type.SMB -> "SMB"
|
||||
|
@ -291,10 +293,14 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_carbs_bolus, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_insulin, false) || !sp.getBoolean(R.string.key_ns_receive_carbs, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
val hasItems = (binding.recyclerview.adapter?.itemCount ?: 0) > 0
|
||||
menu.findItem(R.id.nav_delete_future)?.isVisible = hasItems
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -302,17 +308,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_insulin, false) || !sp.getBoolean(R.string.key_ns_receive_carbs, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
val hasItems = (binding.recyclerview.adapter?.itemCount ?: 0) > 0
|
||||
menu.findItem(R.id.nav_delete_future)?.isVisible = hasItems
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
@ -369,7 +365,7 @@ class TreatmentsBolusCarbsFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteFutureTreatments() {
|
||||
private fun deleteFutureTreatments() {
|
||||
activity?.let { activity ->
|
||||
OKDialog.showConfirmation(activity, rh.gs(R.string.overview_treatment_label), rh.gs(R.string.deletefuturetreatments) + "?", Runnable {
|
||||
uel.log(Action.DELETE_FUTURE_TREATMENTS, Sources.Treatments)
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -20,13 +22,13 @@ import info.nightscout.androidaps.databinding.TreatmentsCareportalFragmentBindin
|
|||
import info.nightscout.androidaps.databinding.TreatmentsCareportalItemBinding
|
||||
import info.nightscout.androidaps.events.EventTherapyEventChange
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
@ -38,7 +40,7 @@ import io.reactivex.rxjava3.kotlin.subscribeBy
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsCareportalFragment : DaggerFragment() {
|
||||
class TreatmentsCareportalFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
|
@ -70,11 +72,11 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun refreshFromNightscout() {
|
||||
|
@ -184,18 +186,12 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_careportal, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_therapy_events, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -203,7 +199,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
@ -265,5 +261,4 @@ class TreatmentsCareportalFragment : DaggerFragment() {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -42,7 +44,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
||||
class TreatmentsExtendedBolusesFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
|
@ -76,11 +78,11 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
fun swapAdapter() {
|
||||
|
@ -174,10 +176,10 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_extended_bolus, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -185,12 +187,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
@ -243,5 +240,4 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -48,7 +50,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
|
|||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
||||
class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var sp: SP
|
||||
|
@ -81,11 +83,11 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun refreshFromNightscout() {
|
||||
|
@ -272,10 +274,12 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_profile_switch, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_profile_switch, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -283,15 +287,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_profile_switch, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -27,6 +29,7 @@ import info.nightscout.androidaps.extensions.friendlyDescription
|
|||
import info.nightscout.androidaps.extensions.highValueToUnitsToString
|
||||
import info.nightscout.androidaps.extensions.lowValueToUnitsToString
|
||||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
|
@ -35,7 +38,6 @@ import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientR
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
@ -47,7 +49,7 @@ import io.reactivex.rxjava3.kotlin.subscribeBy
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsTempTargetFragment : DaggerFragment() {
|
||||
class TreatmentsTempTargetFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
|
@ -81,10 +83,10 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun refreshFromNightscout() {
|
||||
|
@ -203,10 +205,12 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_temp_target, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_temp_target, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -214,15 +218,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
val nsUploadOnly = !sp.getBoolean(R.string.key_ns_receive_temp_target, false) || !buildHelper.isEngineeringMode()
|
||||
menu.findItem(R.id.nav_refresh_ns)?.isVisible = !nsUploadOnly
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -48,7 +50,7 @@ import java.util.concurrent.TimeUnit
|
|||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
||||
class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
||||
class TreatmentsTemporaryBasalsFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
|
@ -81,11 +83,11 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun tempBasalsWithInvalid(now: Long) = repository
|
||||
|
@ -216,10 +218,10 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_temp_basal, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -227,13 +229,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_invalidated)?.isVisible = !showInvalidated
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_remove_items -> actionHelper.startRemove()
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.activities.fragments
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -16,6 +18,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange
|
|||
import info.nightscout.androidaps.extensions.toVisibility
|
||||
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
|
@ -24,14 +27,13 @@ import info.nightscout.androidaps.utils.T
|
|||
import info.nightscout.androidaps.utils.ToastUtils
|
||||
import info.nightscout.androidaps.utils.Translator
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsUserEntryFragment : DaggerFragment() {
|
||||
class TreatmentsUserEntryFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
|
@ -60,11 +62,11 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
|
||||
binding.recyclerview.emptyView = binding.noRecordsText
|
||||
binding.recyclerview.loadingView = binding.progressBar
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
private fun exportUserEntries() {
|
||||
|
@ -144,10 +146,10 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
override fun getItemCount() = entries.size
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
this.menu = menu
|
||||
inflater.inflate(R.menu.menu_treatments_user_entry, menu)
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
updateMenuVisibility()
|
||||
}
|
||||
|
||||
private fun updateMenuVisibility() {
|
||||
|
@ -155,12 +157,7 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
menu?.findItem(R.id.nav_show_loop)?.isVisible = !showLoop
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
updateMenuVisibility()
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
R.id.nav_show_loop -> {
|
||||
showLoop = true
|
||||
|
@ -185,5 +182,4 @@ class TreatmentsUserEntryFragment : DaggerFragment() {
|
|||
|
||||
else -> false
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,18 +2,20 @@ package info.nightscout.androidaps.plugins.aps.loop
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.databinding.LoopFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.interfaces.Loop
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopSetLastRunGui
|
||||
import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -21,7 +23,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
|
|||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoopFragment : DaggerFragment() {
|
||||
class LoopFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
|
@ -32,7 +34,7 @@ class LoopFragment : DaggerFragment() {
|
|||
@Inject lateinit var loop: Loop
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
private val ID_MENU_RUN = 1
|
||||
private val ID_MENU_RUN = 501
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -45,7 +47,7 @@ class LoopFragment : DaggerFragment() {
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
LoopFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
setHasOptionsMenu(true)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -54,22 +56,18 @@ class LoopFragment : DaggerFragment() {
|
|||
with(binding.swipeRefresh) {
|
||||
setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
Thread { loop.invoke("Loop swiperefresh", true) }.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
if (isResumed) {
|
||||
menu.removeItem(ID_MENU_RUN)
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
|
|
|
@ -3,16 +3,18 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA
|
|||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.*
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.JSONFormatter
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
@ -22,7 +24,7 @@ import org.json.JSONArray
|
|||
import org.json.JSONException
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSAMAFragment : DaggerFragment() {
|
||||
class OpenAPSAMAFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -35,7 +37,8 @@ class OpenAPSAMAFragment : DaggerFragment() {
|
|||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var jsonFormatter: JSONFormatter
|
||||
|
||||
private val ID_MENU_RUN = 1
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val ID_MENU_RUN = 502
|
||||
|
||||
private var _binding: OpenapsamaFragmentBinding? = null
|
||||
|
||||
|
@ -46,7 +49,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
OpenapsamaFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
setHasOptionsMenu(true)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -55,23 +58,19 @@ class OpenAPSAMAFragment : DaggerFragment() {
|
|||
with(binding.swipeRefresh) {
|
||||
setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
|
||||
Thread { openAPSAMAPlugin.invoke("OpenAPSAMA swiperefresh", false) }.start()
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
Thread { openAPSAMAPlugin.invoke("OpenAPSAMA swipe refresh", false) }.start()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
if (isResumed) {
|
||||
menu.removeItem(ID_MENU_RUN)
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
|
|
|
@ -4,17 +4,19 @@ import android.annotation.SuppressLint
|
|||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.*
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.databinding.OpenapsamaFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.JSONFormatter
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
|
@ -24,7 +26,7 @@ import org.json.JSONArray
|
|||
import org.json.JSONException
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSSMBFragment : DaggerFragment() {
|
||||
class OpenAPSSMBFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
|
@ -36,9 +38,9 @@ class OpenAPSSMBFragment : DaggerFragment() {
|
|||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var jsonFormatter: JSONFormatter
|
||||
private lateinit var refreshDialog: Runnable
|
||||
|
||||
private val ID_MENU_RUN = 1
|
||||
@Suppress("PrivatePropertyName")
|
||||
private val ID_MENU_RUN = 503
|
||||
|
||||
private var _binding: OpenapsamaFragmentBinding? = null
|
||||
|
||||
|
@ -49,7 +51,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
OpenapsamaFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
setHasOptionsMenu(true)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -58,22 +60,18 @@ class OpenAPSSMBFragment : DaggerFragment() {
|
|||
with(binding.swipeRefresh) {
|
||||
setColorSchemeColors(rh.gac(context, R.attr.colorPrimaryDark), rh.gac(context, R.attr.colorPrimary), rh.gac(context, R.attr.colorSecondary))
|
||||
setOnRefreshListener {
|
||||
binding.lastrun.text = rh.gs(info.nightscout.androidaps.R.string.executing)
|
||||
Thread { activePlugin.activeAPS.invoke("OpenAPSSMB swiperefresh", false) }.start()
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
Thread { activePlugin.activeAPS.invoke("OpenAPSSMB swipe refresh", false) }.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
if (isResumed) {
|
||||
menu.removeItem(ID_MENU_RUN)
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.openapsma_run)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
binding.lastrun.text = rh.gs(R.string.executing)
|
||||
|
|
|
@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.general.nsclient
|
|||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.widget.ScrollView
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
|
@ -22,7 +24,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
|
|||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
class NSClientFragment : DaggerFragment() {
|
||||
class NSClientFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var nsClientPlugin: NSClientPlugin
|
||||
@Inject lateinit var sp: SP
|
||||
|
@ -35,10 +37,10 @@ class NSClientFragment : DaggerFragment() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val ID_MENU_CLEAR_LOG = 6
|
||||
const val ID_MENU_RESTART = 7
|
||||
const val ID_MENU_SEND_NOW = 8
|
||||
const val ID_MENU_FULL_SYNC = 9
|
||||
const val ID_MENU_CLEAR_LOG = 507
|
||||
const val ID_MENU_RESTART = 508
|
||||
const val ID_MENU_SEND_NOW = 509
|
||||
const val ID_MENU_FULL_SYNC = 510
|
||||
}
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
@ -52,7 +54,7 @@ class NSClientFragment : DaggerFragment() {
|
|||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
|
||||
NsClientFragmentBinding.inflate(inflater, container, false).also {
|
||||
_binding = it
|
||||
setHasOptionsMenu(true)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -73,18 +75,15 @@ class NSClientFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
if (isResumed) {
|
||||
menu.add(Menu.FIRST, ID_MENU_CLEAR_LOG, 0, rh.gs(R.string.clearlog)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_RESTART, 0, rh.gs(R.string.restart)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_SEND_NOW, 0, rh.gs(R.string.deliver_now)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(Menu.FIRST, ID_MENU_CLEAR_LOG, 0, rh.gs(R.string.clearlog)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_RESTART, 0, rh.gs(R.string.restart)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_SEND_NOW, 0, rh.gs(R.string.deliver_now)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
when (item.itemId) {
|
||||
ID_MENU_CLEAR_LOG -> {
|
||||
nsClientPlugin.clearLog()
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.os.Bundle
|
|||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dagger.android.support.DaggerFragment
|
||||
|
@ -39,7 +41,7 @@ import io.reactivex.rxjava3.kotlin.plusAssign
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class BGSourceFragment : DaggerFragment() {
|
||||
class BGSourceFragment : DaggerFragment(), MenuProvider {
|
||||
|
||||
@Inject lateinit var rxBus: RxBus
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
|
@ -66,7 +68,7 @@ class BGSourceFragment : DaggerFragment() {
|
|||
actionHelper = ActionModeHelper(rh, activity, this)
|
||||
actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { handler -> removeSelected(handler) }
|
||||
setHasOptionsMenu(true)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}.root
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
@ -104,13 +106,8 @@ class BGSourceFragment : DaggerFragment() {
|
|||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
actionHelper.onCreateOptionsMenu(menu, inflater)
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
actionHelper.onPrepareOptionsMenu(menu)
|
||||
}
|
||||
|
||||
|
@ -121,7 +118,7 @@ class BGSourceFragment : DaggerFragment() {
|
|||
_binding = null
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem) =
|
||||
override fun onMenuItemSelected(item: MenuItem) =
|
||||
actionHelper.onOptionsItemSelected(item)
|
||||
|
||||
inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List<GlucoseValue>) : RecyclerView.Adapter<RecyclerViewAdapter.GlucoseValuesViewHolder>() {
|
||||
|
|
|
@ -5,11 +5,19 @@ import android.content.Context
|
|||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.util.SparseArray
|
||||
import android.view.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.util.forEach
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -40,7 +48,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
|
|||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import javax.inject.Inject
|
||||
|
||||
class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
||||
class AutomationFragment : DaggerFragment(), OnStartDragListener, MenuProvider {
|
||||
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var rh: ResourceHelper
|
||||
|
@ -52,9 +60,9 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
|
||||
companion object {
|
||||
|
||||
const val ID_MENU_ADD = 3
|
||||
const val ID_MENU_RUN = 4
|
||||
const val ID_MENU_EDIT_MOVE = 5
|
||||
const val ID_MENU_ADD = 504
|
||||
const val ID_MENU_RUN = 505
|
||||
const val ID_MENU_EDIT_MOVE = 506
|
||||
}
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
@ -73,7 +81,6 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
actionHelper.setUpdateListHandler { binding.eventListView.adapter?.notifyDataSetChanged() }
|
||||
actionHelper.setOnRemoveHandler { removeSelected(it) }
|
||||
actionHelper.enableSort = true
|
||||
setHasOptionsMenu(true)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
@ -85,43 +92,38 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
binding.logView.movementMethod = ScrollingMovementMethod()
|
||||
|
||||
itemTouchHelper.attachToRecyclerView(binding.eventListView)
|
||||
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
if (isResumed) {
|
||||
actionHelper.onCreateOptionsMenu(menu, inflater)
|
||||
menu.removeItem(ID_MENU_ADD)
|
||||
menu.removeItem(ID_MENU_RUN)
|
||||
menu.add(Menu.FIRST, ID_MENU_ADD, 0, rh.gs(R.string.add_automation)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.run_automations)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_EDIT_MOVE, 0, rh.gs(R.string.remove_sort)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
|
||||
actionHelper.onCreateOptionsMenu(menu, inflater)
|
||||
menu.add(Menu.FIRST, ID_MENU_ADD, 0, rh.gs(R.string.add_automation)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_RUN, 0, rh.gs(R.string.run_automations)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.add(Menu.FIRST, ID_MENU_EDIT_MOVE, 0, rh.gs(R.string.remove_sort)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||
override fun onMenuItemSelected(item: MenuItem): Boolean =
|
||||
if (actionHelper.onOptionsItemSelected(item)) true
|
||||
else
|
||||
when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
Thread { automationPlugin.processActions() }.start()
|
||||
true
|
||||
}
|
||||
|
||||
ID_MENU_ADD -> {
|
||||
add()
|
||||
true
|
||||
}
|
||||
|
||||
ID_MENU_EDIT_MOVE -> {
|
||||
actionHelper.startAction()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
else when (item.itemId) {
|
||||
ID_MENU_RUN -> {
|
||||
Thread { automationPlugin.processActions() }.start()
|
||||
true
|
||||
}
|
||||
|
||||
ID_MENU_ADD -> {
|
||||
add()
|
||||
true
|
||||
}
|
||||
|
||||
ID_MENU_EDIT_MOVE -> {
|
||||
actionHelper.startAction()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Synchronized
|
||||
override fun onResume() {
|
||||
|
@ -129,15 +131,11 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
|
|||
disposable += rxBus
|
||||
.toObservable(EventAutomationUpdateGui::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
updateGui()
|
||||
}, fabricPrivacy::logException)
|
||||
.subscribe({ updateGui() }, fabricPrivacy::logException)
|
||||
disposable += rxBus
|
||||
.toObservable(EventAutomationDataChanged::class.java)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
eventListAdapter.notifyDataSetChanged()
|
||||
}, fabricPrivacy::logException)
|
||||
.subscribe({ eventListAdapter.notifyDataSetChanged() }, fabricPrivacy::logException)
|
||||
updateGui()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ buildscript {
|
|||
rxandroid_version = '3.0.0'
|
||||
rxkotlin_version = '3.0.1'
|
||||
room_version = '2.4.3'
|
||||
lifecycle_version = '2.5.0'
|
||||
dagger_version = '2.42'
|
||||
lifecycle_version = '2.5.1'
|
||||
dagger_version = '2.43'
|
||||
coroutines_version = '1.6.4'
|
||||
activity_version = '1.4.0'
|
||||
fragmentktx_version = '1.4.1'
|
||||
|
|
|
@ -27,15 +27,12 @@ class ActionModeHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity
|
|||
return parentClass == "SingleFragmentActivity"
|
||||
}
|
||||
|
||||
val enableRemove: Boolean
|
||||
private val enableRemove: Boolean
|
||||
get() = onRemove != null
|
||||
|
||||
val isNoAction: Boolean
|
||||
get() = actionMode == null && removeActionMode == null && sortActionMode == null
|
||||
|
||||
val isAction: Boolean
|
||||
get() = actionMode != null
|
||||
|
||||
val isSorting: Boolean
|
||||
get() = sortActionMode != null
|
||||
|
||||
|
@ -98,14 +95,6 @@ class ActionModeHelper<T>(val rh: ResourceHelper, val activity: FragmentActivity
|
|||
return false
|
||||
}
|
||||
|
||||
fun startSort(): Boolean {
|
||||
if (sortActionMode == null) {
|
||||
sortActionMode = activity?.startActionMode(SortActionModeCallback())
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun isSelected(position: Int) =
|
||||
selectedItems.get(position) != null
|
||||
|
||||
|
|
Loading…
Reference in a new issue