feat: request protection from menu
This commit is contained in:
parent
02e553ecc6
commit
2c60ec44e5
3 changed files with 94 additions and 64 deletions
|
@ -10,23 +10,26 @@ import android.widget.*
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.interfaces.Config
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
|
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
||||||
import info.nightscout.androidaps.databinding.ConfigbuilderFragmentBinding
|
import info.nightscout.androidaps.databinding.ConfigbuilderFragmentBinding
|
||||||
import info.nightscout.androidaps.events.EventRebuildTabs
|
import info.nightscout.androidaps.events.EventRebuildTabs
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
|
import info.nightscout.androidaps.interfaces.Config
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.events.EventConfigBuilderUpdateGui
|
import info.nightscout.androidaps.plugins.configBuilder.events.EventConfigBuilderUpdateGui
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
|
||||||
import info.nightscout.androidaps.extensions.toVisibility
|
|
||||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||||
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.PREFERENCES
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import java.util.*
|
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ConfigBuilderFragment : DaggerFragment() {
|
class ConfigBuilderFragment : DaggerFragment() {
|
||||||
|
@ -44,48 +47,36 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
private val pluginViewHolders = ArrayList<PluginViewHolder>()
|
private val pluginViewHolders = ArrayList<PluginViewHolder>()
|
||||||
|
private var inMenu = false
|
||||||
|
private var queryingProtection = false
|
||||||
private var _binding: ConfigbuilderFragmentBinding? = null
|
private var _binding: ConfigbuilderFragmentBinding? = null
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
// This property is only valid between onCreateView and onDestroyView.
|
||||||
// onDestroyView.
|
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
savedInstanceState: Bundle?): View {
|
|
||||||
_binding = ConfigbuilderFragmentBinding.inflate(inflater, container, false)
|
_binding = ConfigbuilderFragmentBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
val parentClass = this.activity?.let { it::class.java }
|
||||||
if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES))
|
inMenu = parentClass == SingleFragmentActivity::class.java
|
||||||
binding.mainLayout.visibility = View.GONE
|
updateProtectedUi()
|
||||||
else
|
binding.unlock.setOnClickListener { queryProtection() }
|
||||||
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
|
@Synchronized
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (inMenu) queryProtection() else updateProtectedUi()
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
.toObservable(EventConfigBuilderUpdateGui::class.java)
|
.toObservable(EventConfigBuilderUpdateGui::class.java)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
for (pluginViewHolder in pluginViewHolders) pluginViewHolder.update()
|
for (pluginViewHolder in pluginViewHolders) pluginViewHolder.update()
|
||||||
}, fabricPrivacy::logException)
|
}, fabricPrivacy::logException)
|
||||||
updateGUI()
|
updateGUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,4 +206,21 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP
|
return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateProtectedUi() {
|
||||||
|
val isLocked = protectionCheck.isLocked(PREFERENCES)
|
||||||
|
binding.mainLayout.visibility = isLocked.not().toVisibility()
|
||||||
|
binding.unlock.visibility = isLocked.toVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun queryProtection() {
|
||||||
|
val isLocked = protectionCheck.isLocked(PREFERENCES)
|
||||||
|
if (isLocked && !queryingProtection) {
|
||||||
|
activity?.let { activity ->
|
||||||
|
queryingProtection = true
|
||||||
|
val doUpdate = { activity.runOnUiThread { queryingProtection = false; updateProtectedUi() } }
|
||||||
|
protectionCheck.queryProtection(activity, PREFERENCES, doUpdate, doUpdate, doUpdate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
||||||
import info.nightscout.androidaps.dana.database.DanaHistoryDatabase
|
import info.nightscout.androidaps.dana.database.DanaHistoryDatabase
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
|
@ -14,6 +15,7 @@ import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
||||||
import info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase
|
import info.nightscout.androidaps.diaconn.database.DiaconnHistoryDatabase
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
import info.nightscout.androidaps.insight.database.InsightDatabase
|
import info.nightscout.androidaps.insight.database.InsightDatabase
|
||||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||||
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
||||||
|
@ -28,6 +30,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.history.database.Das
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
|
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||||
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck.Protection.PREFERENCES
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import io.reactivex.rxjava3.core.Completable.fromAction
|
import io.reactivex.rxjava3.core.Completable.fromAction
|
||||||
|
@ -57,11 +60,11 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
@Inject lateinit var overviewData: OverviewData
|
@Inject lateinit var overviewData: OverviewData
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
private var inMenu = false
|
||||||
|
private var queryingProtection = false
|
||||||
private var _binding: MaintenanceFragmentBinding? = null
|
private var _binding: MaintenanceFragmentBinding? = null
|
||||||
|
|
||||||
// This property is only valid between onCreateView and
|
// This property is only valid between onCreateView and onDestroyView.
|
||||||
// onDestroyView.
|
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
|
@ -71,6 +74,9 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
val parentClass = this.activity?.let { it::class.java }
|
||||||
|
inMenu = parentClass == SingleFragmentActivity::class.java
|
||||||
|
updateProtectedUi()
|
||||||
binding.logSend.setOnClickListener { maintenancePlugin.sendLogs() }
|
binding.logSend.setOnClickListener { maintenancePlugin.sendLogs() }
|
||||||
binding.logDelete.setOnClickListener {
|
binding.logDelete.setOnClickListener {
|
||||||
uel.log(Action.DELETE_LOGS, Sources.Maintenance)
|
uel.log(Action.DELETE_LOGS, Sources.Maintenance)
|
||||||
|
@ -131,22 +137,12 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)) {
|
binding.unlock.setOnClickListener { queryProtection() }
|
||||||
binding.mainLayout.visibility = View.GONE
|
}
|
||||||
} else {
|
|
||||||
binding.unlock.visibility = View.GONE
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.unlock.setOnClickListener {
|
override fun onResume() {
|
||||||
activity?.let { activity ->
|
super.onResume()
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, {
|
if (inMenu) queryProtection() else updateProtectedUi()
|
||||||
activity.runOnUiThread {
|
|
||||||
binding.mainLayout.visibility = View.VISIBLE
|
|
||||||
binding.unlock.visibility = View.GONE
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
|
@ -155,4 +151,21 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
compositeDisposable.clear()
|
compositeDisposable.clear()
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private fun updateProtectedUi() {
|
||||||
|
val isLocked = protectionCheck.isLocked(PREFERENCES)
|
||||||
|
binding.mainLayout.visibility = isLocked.not().toVisibility()
|
||||||
|
binding.unlock.visibility = isLocked.toVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun queryProtection() {
|
||||||
|
val isLocked = protectionCheck.isLocked(PREFERENCES)
|
||||||
|
if (isLocked && !queryingProtection) {
|
||||||
|
activity?.let { activity ->
|
||||||
|
queryingProtection = true
|
||||||
|
val doUpdate = { activity.runOnUiThread { queryingProtection = false; updateProtectedUi() } }
|
||||||
|
protectionCheck.queryProtection(activity, PREFERENCES, doUpdate, doUpdate, doUpdate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -12,12 +12,14 @@ import android.widget.ArrayAdapter
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
||||||
import info.nightscout.androidaps.data.ProfileSealed
|
import info.nightscout.androidaps.data.ProfileSealed
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||||
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
import info.nightscout.androidaps.database.entities.ValueWithUnit
|
||||||
import info.nightscout.androidaps.databinding.LocalprofileFragmentBinding
|
import info.nightscout.androidaps.databinding.LocalprofileFragmentBinding
|
||||||
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
||||||
|
import info.nightscout.androidaps.extensions.toVisibility
|
||||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||||
import info.nightscout.androidaps.interfaces.Profile
|
import info.nightscout.androidaps.interfaces.Profile
|
||||||
|
@ -56,7 +58,8 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
private var inMenu = false
|
||||||
|
private var queryingProtection = false
|
||||||
private var basalView: TimeListEdit? = null
|
private var basalView: TimeListEdit? = null
|
||||||
|
|
||||||
private val save = Runnable {
|
private val save = Runnable {
|
||||||
|
@ -99,6 +102,9 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
val parentClass = this.activity?.let { it::class.java }
|
||||||
|
inMenu = parentClass == SingleFragmentActivity::class.java
|
||||||
|
updateProtectedUi()
|
||||||
// activate DIA tab
|
// activate DIA tab
|
||||||
processVisibilityOnClick(binding.diaTab)
|
processVisibilityOnClick(binding.diaTab)
|
||||||
binding.diaPlaceholder.visibility = View.VISIBLE
|
binding.diaPlaceholder.visibility = View.VISIBLE
|
||||||
|
@ -125,22 +131,7 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
binding.dia.editText?.id?.let { binding.diaLabel.labelFor = it }
|
binding.dia.editText?.id?.let { binding.diaLabel.labelFor = it }
|
||||||
|
|
||||||
if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)) {
|
binding.unlock.setOnClickListener { queryProtection() }
|
||||||
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() {
|
fun build() {
|
||||||
|
@ -345,6 +336,7 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (inMenu) queryProtection() else updateProtectedUi()
|
||||||
disposable += rxBus
|
disposable += rxBus
|
||||||
.toObservable(EventLocalProfileChanged::class.java)
|
.toObservable(EventLocalProfileChanged::class.java)
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
|
@ -421,4 +413,21 @@ class LocalProfileFragment : DaggerFragment() {
|
||||||
binding.basal.visibility = View.GONE
|
binding.basal.visibility = View.GONE
|
||||||
binding.target.visibility = View.GONE
|
binding.target.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateProtectedUi() {
|
||||||
|
val isLocked = protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)
|
||||||
|
binding.mainLayout.visibility = isLocked.not().toVisibility()
|
||||||
|
binding.unlock.visibility = isLocked.toVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun queryProtection() {
|
||||||
|
val isLocked = protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)
|
||||||
|
if (isLocked && !queryingProtection) {
|
||||||
|
activity?.let { activity ->
|
||||||
|
queryingProtection = true
|
||||||
|
val doUpdate = { activity.runOnUiThread { queryingProtection = false; updateProtectedUi() } }
|
||||||
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, doUpdate, doUpdate, doUpdate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue