From c8c1ba84e911cecdb7e2b48821efb0aaea4ea8b7 Mon Sep 17 00:00:00 2001 From: Andries Smit Date: Thu, 3 Mar 2022 20:54:42 +0100 Subject: [PATCH] fix: add missing protection --- .../general/actions/ActionsFragment.kt | 21 +- .../maintenance/MaintenanceFragment.kt | 19 + .../profile/local/LocalProfileFragment.kt | 22 +- .../main/res/layout/localprofile_fragment.xml | 598 +++++++++--------- .../main/res/layout/maintenance_fragment.xml | 9 + .../dash/ui/OmnipodDashOverviewFragment.kt | 13 +- 6 files changed, 382 insertions(+), 300 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index 111df21369..a7a3a59f36 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -157,10 +157,20 @@ class ActionsFragment : DaggerFragment() { cannulaOrPatch = view.findViewById(R.id.cannula_or_patch) profileSwitch?.setOnClickListener { - ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog") + activity?.let { activity -> + protectionCheck.queryProtection( + activity, + ProtectionCheck.Protection.BOLUS, + UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog")}) + } } tempTarget?.setOnClickListener { - TempTargetDialog().show(childFragmentManager, "Actions") + activity?.let { activity -> + protectionCheck.queryProtection( + activity, + ProtectionCheck.Protection.BOLUS, + UIRunnable { TempTargetDialog().show(childFragmentManager, "Actions") }) + } } extendedBolus?.setOnClickListener { activity?.let { activity -> @@ -187,7 +197,12 @@ class ActionsFragment : DaggerFragment() { } } setTempBasal?.setOnClickListener { - TempBasalDialog().show(childFragmentManager, "Actions") + activity?.let { activity -> + protectionCheck.queryProtection( + activity, + ProtectionCheck.Protection.BOLUS, + UIRunnable { TempBasalDialog().show(childFragmentManager, "Actions") }) + } } cancelTempBasal?.setOnClickListener { if (iobCobCalculator.getTempBasalIncludingConvertedExtended(dateUtil.now()) != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt index b39883538b..6bc0b06bab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenanceFragment.kt @@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewData import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.DashHistoryDatabase import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase import info.nightscout.androidaps.utils.alertDialogs.OKDialog +import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import io.reactivex.Completable.fromAction @@ -48,6 +49,7 @@ class MaintenanceFragment : DaggerFragment() { @Inject lateinit var diaconnDatabase: DiaconnHistoryDatabase @Inject lateinit var erosDatabase: ErosHistoryDatabase @Inject lateinit var dashDatabase: DashHistoryDatabase + @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var uel: UserEntryLogger @Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var pumpSync: PumpSync @@ -128,6 +130,23 @@ class MaintenanceFragment : DaggerFragment() { } } } + + if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)) { + binding.mainLayout.visibility = View.GONE + } else { + binding.unlock.visibility = View.GONE + } + + binding.unlock.setOnClickListener { + activity?.let { activity -> + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, { + activity.runOnUiThread { + binding.mainLayout.visibility = View.VISIBLE + binding.unlock.visibility = View.GONE + } + }) + } + } } @Synchronized diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index 78a31caa92..c556a8c864 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -29,6 +29,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.alertDialogs.OKDialog +import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.ui.TimeListEdit @@ -49,6 +50,7 @@ class LocalProfileFragment : DaggerFragment() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var hardLimits: HardLimits + @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var dateUtil: DateUtil @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var uel: UserEntryLogger @@ -88,8 +90,7 @@ class LocalProfileFragment : DaggerFragment() { private var _binding: LocalprofileFragmentBinding? = null - // This property is only valid between onCreateView and - // onDestroyView. + // This property is only valid between onCreateView and onDestroyView. private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { @@ -124,6 +125,23 @@ class LocalProfileFragment : DaggerFragment() { binding.target.visibility = View.VISIBLE } binding.dia.editText?.id?.let { binding.diaLabel.labelFor = it } + + if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)) { + binding.mainLayout.visibility = View.GONE + } else { + binding.unlock.visibility = View.GONE + } + + binding.unlock.setOnClickListener { + activity?.let { activity -> + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, { + activity.runOnUiThread { + binding.mainLayout.visibility = View.VISIBLE + binding.unlock.visibility = View.GONE + } + }) + } + } } fun build() { diff --git a/app/src/main/res/layout/localprofile_fragment.xml b/app/src/main/res/layout/localprofile_fragment.xml index ae4db5ca29..ae7f788b54 100644 --- a/app/src/main/res/layout/localprofile_fragment.xml +++ b/app/src/main/res/layout/localprofile_fragment.xml @@ -10,353 +10,369 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - + android:layout_gravity="center" + android:text="@string/unlock_settings" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_marginStart="5dp" + android:layout_marginEnd="5dp" + android:hint="@string/select_profile" + android:textColorHint="@color/white" + app:boxStrokeColor="@color/list_delimiter"> + + + + + android:layout_marginBottom="10dp" + android:orientation="horizontal"> - - - + android:layout_marginStart="10dp" + android:layout_weight="1" + android:ems="10" + android:importantForAutofill="no" + android:inputType="text" /> - - - - - - + android:gravity="start" + android:orientation="horizontal"> - + - + - + + + + + + + + android:orientation="horizontal" + android:paddingBottom="10dp" + android:weightSum="5"> - + - + - + + + + + + + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + + + + + + + + + + + + android:id="@+id/ic" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + android:orientation="horizontal"> + + + + + - diff --git a/app/src/main/res/layout/maintenance_fragment.xml b/app/src/main/res/layout/maintenance_fragment.xml index 2e994e142e..eed3be06d2 100644 --- a/app/src/main/res/layout/maintenance_fragment.xml +++ b/app/src/main/res/layout/maintenance_fragment.xml @@ -5,7 +5,16 @@ android:paddingTop="2dp" tools:context=".plugins.general.maintenance.MaintenanceFragment"> + + diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 2ab79b26c4..8f7310a968 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -40,6 +40,7 @@ import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper +import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.shared.sharedPreferences.SP @@ -64,6 +65,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { @Inject lateinit var omnipodDashPumpPlugin: OmnipodDashPumpPlugin @Inject lateinit var podStateManager: OmnipodDashPodStateManager @Inject lateinit var sp: SP + @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var dateUtil: DateUtil @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var pumpSync: PumpSync @@ -93,8 +95,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private var _podInfoBinding: OmnipodCommonOverviewPodInfoBinding? = null private var _buttonBinding: OmnipodCommonOverviewButtonsBinding? = null - // These properties are only valid between onCreateView and - // onDestroyView. + // These properties are only valid between onCreateView and onDestroyView. val binding get() = _binding!! private val bluetoothStatusBinding get() = _bluetoothStatusBinding!! private val podInfoBinding get() = _podInfoBinding!! @@ -112,8 +113,12 @@ class OmnipodDashOverviewFragment : DaggerFragment() { super.onViewCreated(view, savedInstanceState) buttonBinding.buttonPodManagement.setOnClickListener { - // TODO add protection - startActivity(Intent(context, DashPodManagementActivity::class.java)) + activity?.let { activity -> + protectionCheck.queryProtection( + activity, + ProtectionCheck.Protection.PREFERENCES, + UIRunnable { startActivity(Intent(context, DashPodManagementActivity::class.java)) }) + } } buttonBinding.buttonResumeDelivery.setOnClickListener {