From e4ccc78a7d96a87e26c3742ebd5ed719ab353aa5 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 11 Nov 2022 09:38:36 +0100 Subject: [PATCH] ProfileViewerDialog -> ui --- .../implementations/ActivityNamesImpl.kt | 16 ++++- .../androidaps/plugins/aps/loop/LoopPlugin.kt | 4 +- .../aps/openAPSAMA/OpenAPSAMAPlugin.kt | 4 +- .../aps/openAPSSMB/OpenAPSSMBPlugin.kt | 4 +- .../configBuilder/ProfileFunctionImpl.kt | 2 +- .../general/overview/OverviewFragment.kt | 14 ++--- .../PersistentNotificationPlugin.kt | 2 +- .../androidaps/di/CoreFragmentsModule.kt | 3 - .../core-main/src/main/res/values/strings.xml | 4 +- .../nightscout/interfaces/ui/ActivityNames.kt | 8 +++ .../general/autotune/AutotuneFragment.kt | 37 ++++++------ .../smsCommunicator/SmsCommunicatorPlugin.kt | 4 +- .../androidaps/dana/DanaFragment.kt | 19 +++--- .../ui/activities/ProfileHelperActivity.kt | 5 +- .../ui/activities/SurveyActivity.kt | 22 ++++--- .../TreatmentsProfileSwitchFragment.kt | 7 ++- .../java/info/nightscout/ui/di/UiModule.kt | 2 + .../ui}/dialogs/ProfileViewerDialog.kt | 58 +++++++++---------- .../main/res/layout/dialog_profileviewer.xml | 16 ++--- 19 files changed, 121 insertions(+), 110 deletions(-) rename {core/core-main/src/main/java/info/nightscout/androidaps => ui/src/main/java/info/nightscout/ui}/dialogs/ProfileViewerDialog.kt (88%) rename {core/core-main => ui}/src/main/res/layout/dialog_profileviewer.xml (97%) diff --git a/app/src/main/java/info/nightscout/androidaps/implementations/ActivityNamesImpl.kt b/app/src/main/java/info/nightscout/androidaps/implementations/ActivityNamesImpl.kt index 307ab4bf13..c5e52dbf43 100644 --- a/app/src/main/java/info/nightscout/androidaps/implementations/ActivityNamesImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/implementations/ActivityNamesImpl.kt @@ -14,6 +14,7 @@ import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.ui.activities.BolusProgressHelperActivity import info.nightscout.ui.activities.ErrorHelperActivity import info.nightscout.ui.activities.TDDStatsActivity +import info.nightscout.ui.dialogs.ProfileViewerDialog import javax.inject.Inject class ActivityNamesImpl @Inject constructor() : ActivityNames { @@ -24,7 +25,6 @@ class ActivityNamesImpl @Inject constructor() : ActivityNames { override val bolusProgressHelperActivity: Class<*> = BolusProgressHelperActivity::class.java override val singleFragmentActivity: Class<*> = SingleFragmentActivity::class.java - override fun runAlarm(ctx: Context, status: String, title: String, @RawRes soundId: Int) { val i = Intent(ctx, errorHelperActivity) i.putExtra(AlarmSoundService.SOUND_ID, soundId) @@ -49,4 +49,18 @@ class ActivityNamesImpl @Inject constructor() : ActivityNames { .also { it.arguments = Bundle().also { bundle -> bundle.putString("profileName", profileName) } } .show(fragmentManager, "ProfileSwitchDialog") } + + override fun runProfileViewerDialog(fragmentManager: FragmentManager, time: Long, mode: ActivityNames.Mode, customProfile: String?, customProfilename: String?, customProfile2: String?) { + ProfileViewerDialog() + .also { + it.arguments = Bundle().also { bundle -> + bundle.putLong("time", time) + bundle.putInt("mode", mode.ordinal) + bundle.putString("customProfile", customProfile) + bundle.putString("customProfileName", customProfilename) + bundle.putString("customProfile2", customProfile2) + } + } + .show(fragmentManager, "ProfileSwitchDialog") + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt index 4edc518e93..9de27b1751 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt @@ -237,8 +237,8 @@ class LoopPlugin @Inject constructor( if (!isEnabled(PluginType.LOOP)) return val profile = profileFunction.getProfile() if (profile == null || !profileFunction.isProfileValid("Loop")) { - aapsLogger.debug(LTag.APS, rh.gs(R.string.noprofileset)) - rxBus.send(EventLoopSetLastRunGui(rh.gs(R.string.noprofileset))) + aapsLogger.debug(LTag.APS, rh.gs(R.string.no_profile_set)) + rxBus.send(EventLoopSetLastRunGui(rh.gs(R.string.no_profile_set))) return } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt index 592c2fe9ed..b880fa7f5b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.kt @@ -97,8 +97,8 @@ class OpenAPSAMAPlugin @Inject constructor( val profile = profileFunction.getProfile() val pump = activePlugin.activePump if (profile == null) { - rxBus.send(EventOpenAPSUpdateResultGui(rh.gs(R.string.noprofileset))) - aapsLogger.debug(LTag.APS, rh.gs(R.string.noprofileset)) + rxBus.send(EventOpenAPSUpdateResultGui(rh.gs(R.string.no_profile_set))) + aapsLogger.debug(LTag.APS, rh.gs(R.string.no_profile_set)) return } if (!isEnabled()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt index 784ef4cf24..483f22b3b2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.kt @@ -106,8 +106,8 @@ class OpenAPSSMBPlugin @Inject constructor( val profile = profileFunction.getProfile() val pump = activePlugin.activePump if (profile == null) { - rxBus.send(EventOpenAPSUpdateResultGui(rh.gs(R.string.noprofileset))) - aapsLogger.debug(LTag.APS, rh.gs(R.string.noprofileset)) + rxBus.send(EventOpenAPSUpdateResultGui(rh.gs(R.string.no_profile_set))) + aapsLogger.debug(LTag.APS, rh.gs(R.string.no_profile_set)) return } if (!isEnabled()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt index a09d1bb413..c991199e57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctionImpl.kt @@ -73,7 +73,7 @@ class ProfileFunctionImpl @Inject constructor( getProfileName(System.currentTimeMillis(), customized = true, showRemainingTime = true) fun getProfileName(time: Long, customized: Boolean, showRemainingTime: Boolean): String { - var profileName = rh.gs(R.string.noprofileset) + var profileName = rh.gs(R.string.no_profile_set) val profileSwitch = repository.getEffectiveProfileSwitchActiveAt(time).blockingGet() if (profileSwitch is ValueWrapper.Existing) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index a5bbeba151..edbd00df16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -33,7 +33,6 @@ import info.nightscout.androidaps.databinding.OverviewFragmentBinding import info.nightscout.androidaps.dialogs.InsulinDialog import info.nightscout.androidaps.dialogs.LoopDialog import info.nightscout.androidaps.dialogs.ProfileSwitchDialog -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.dialogs.TempTargetDialog import info.nightscout.androidaps.dialogs.TreatmentDialog import info.nightscout.androidaps.dialogs.WizardDialog @@ -88,6 +87,7 @@ import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.pump.defs.PumpType +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.utils.JsonHelper import info.nightscout.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin import info.nightscout.plugins.general.overview.notifications.NotificationStore @@ -157,6 +157,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList @Inject lateinit var overviewData: OverviewData @Inject lateinit var automationPlugin: AutomationPlugin @Inject lateinit var bgQualityCheckPlugin: BgQualityCheckPlugin + @Inject lateinit var activityNames: ActivityNames private val disposable = CompositeDisposable() @@ -403,12 +404,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList UIRunnable { if (isAdded) TempTargetDialog().show(childFragmentManager, "Overview") }) R.id.active_profile -> { - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", dateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) - } - }.show(childFragmentManager, "ProfileViewDialog") + activityNames.runProfileViewerDialog( + childFragmentManager, + dateUtil.now(), + ActivityNames.Mode.RUNNING_PROFILE + ) } R.id.cgm_button -> { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index 6e3e986393..36b7c7eb00 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -194,7 +194,7 @@ class PersistentNotificationPlugin @Inject constructor( unreadConversationBuilder.addMessage(line3aa) /// End Android Auto } else { - line1 = rh.gs(R.string.noprofileset) + line1 = rh.gs(R.string.no_profile_set) } val builder = NotificationCompat.Builder(context, notificationHolder.channelID) builder.setOngoing(true) diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/di/CoreFragmentsModule.kt b/core/core-main/src/main/java/info/nightscout/androidaps/di/CoreFragmentsModule.kt index acdb351b18..cd37905343 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/di/CoreFragmentsModule.kt +++ b/core/core-main/src/main/java/info/nightscout/androidaps/di/CoreFragmentsModule.kt @@ -4,7 +4,6 @@ import dagger.Module import dagger.android.ContributesAndroidInjector import info.nightscout.androidaps.dialogs.BolusProgressDialog import info.nightscout.androidaps.dialogs.ErrorDialog -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity import info.nightscout.androidaps.utils.ui.SingleClickButton @@ -15,8 +14,6 @@ abstract class CoreFragmentsModule { @ContributesAndroidInjector abstract fun contributesPrefImportListActivity(): PrefImportListActivity @ContributesAndroidInjector abstract fun contributesBolusProgressDialog(): BolusProgressDialog @ContributesAndroidInjector abstract fun contributesErrorDialog(): ErrorDialog - @ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog - @ContributesAndroidInjector abstract fun contributesSingleClickButton(): SingleClickButton } diff --git a/core/core-main/src/main/res/values/strings.xml b/core/core-main/src/main/res/values/strings.xml index 8a6823005f..109022b62d 100644 --- a/core/core-main/src/main/res/values/strings.xml +++ b/core/core-main/src/main/res/values/strings.xml @@ -131,8 +131,8 @@ STOP PRESSED Stop Carbs - Invalid profile! - NO PROFILE SET + Invalid profile! + NO PROFILE SET ]]> Date Units diff --git a/interfaces/src/main/java/info/nightscout/interfaces/ui/ActivityNames.kt b/interfaces/src/main/java/info/nightscout/interfaces/ui/ActivityNames.kt index f1d53938f1..feac287d00 100644 --- a/interfaces/src/main/java/info/nightscout/interfaces/ui/ActivityNames.kt +++ b/interfaces/src/main/java/info/nightscout/interfaces/ui/ActivityNames.kt @@ -26,4 +26,12 @@ interface ActivityNames { fun runAlarm(ctx: Context, status: String, title: String, @RawRes soundId: Int = 0) fun runWizard(fragmentManager: FragmentManager, carbs: Int, name: String) fun runProfileSwitchDialog(fragmentManager: FragmentManager, profileName: String?) + + enum class Mode(val i: Int) { + RUNNING_PROFILE(1), + CUSTOM_PROFILE(2), + DB_PROFILE(3), + PROFILE_COMPARE(4) + } + fun runProfileViewerDialog(fragmentManager: FragmentManager, time: Long, mode: Mode, customProfile: String?= null, customProfileName: String? = null, customProfile2: String? = null) } \ No newline at end of file diff --git a/plugins/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt b/plugins/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt index 6d2cbc2b51..5a78aafbbe 100644 --- a/plugins/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt +++ b/plugins/src/main/java/info/nightscout/plugins/general/autotune/AutotuneFragment.kt @@ -20,7 +20,6 @@ import android.widget.TextView import dagger.android.HasAndroidInjector import dagger.android.support.DaggerFragment import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger @@ -34,6 +33,7 @@ import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileStore +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.utils.MidnightTime import info.nightscout.interfaces.utils.Round import info.nightscout.plugins.R @@ -72,6 +72,7 @@ class AutotuneFragment : DaggerFragment() { @Inject lateinit var rxBus: RxBus @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var aapsSchedulers: AapsSchedulers + @Inject lateinit var activityNames: ActivityNames private var disposable: CompositeDisposable = CompositeDisposable() private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) @@ -200,15 +201,13 @@ class AutotuneFragment : DaggerFragment() { } } pumpProfile?.let { - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", dateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.CUSTOM_PROFILE.ordinal) - it.putString("customProfile", pumpProfile.profile.toPureNsJson(dateUtil).toString()) - it.putString("customProfileUnits", profileFunction.getUnits().asText) - it.putString("customProfileName", pumpProfile.profilename) - } - }.show(childFragmentManager, "ProfileViewDialog") + activityNames.runProfileViewerDialog( + fragmentManager = childFragmentManager, + time = dateUtil.now(), + mode = ActivityNames.Mode.CUSTOM_PROFILE, + customProfile = pumpProfile.profile.toPureNsJson(dateUtil).toString(), + customProfileName = pumpProfile.profilename + ) } } @@ -216,16 +215,14 @@ class AutotuneFragment : DaggerFragment() { val pumpProfile = autotunePlugin.pumpProfile val circadian = sp.getBoolean(R.string.key_autotune_circadian_ic_isf, false) val tunedProfile = if (circadian) autotunePlugin.tunedProfile?.circadianProfile else autotunePlugin.tunedProfile?.profile - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", dateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) - it.putString("customProfile", pumpProfile.profile.toPureNsJson(dateUtil).toString()) - it.putString("customProfile2", tunedProfile?.toPureNsJson(dateUtil).toString()) - it.putString("customProfileUnits", profileFunction.getUnits().asText) - it.putString("customProfileName", pumpProfile.profilename + "\n" + rh.gs(R.string.autotune_tunedprofile_name)) - } - }.show(childFragmentManager, "ProfileViewDialog") + activityNames.runProfileViewerDialog( + fragmentManager = childFragmentManager, + time = dateUtil.now(), + mode = ActivityNames.Mode.PROFILE_COMPARE, + customProfile = pumpProfile.profile.toPureNsJson(dateUtil).toString(), + customProfileName = pumpProfile.profilename + "\n" + rh.gs(R.string.autotune_tunedprofile_name), + customProfile2 = tunedProfile?.toPureNsJson(dateUtil).toString() + ) } binding.autotuneProfileswitch.setOnClickListener { diff --git a/plugins/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index dff5adfdac..9f4119edd7 100644 --- a/plugins/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -620,7 +620,7 @@ class SmsCommunicatorPlugin @Inject constructor( if (divided[1].uppercase(Locale.getDefault()) == "STATUS") { sendSMS(Sms(receivedSms.phoneNumber, profileName)) } else if (divided[1].uppercase(Locale.getDefault()) == "LIST") { - if (list.isEmpty()) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.invalidprofile))) + if (list.isEmpty()) sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.invalid_profile))) else { var reply = "" for (i in list.indices) { @@ -655,7 +655,7 @@ class SmsCommunicatorPlugin @Inject constructor( ValueWithUnit.SimpleString(rh.gsNotLocalised(R.string.sms_profile_switch_created)) ) } else { - sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.invalidprofile))) + sendSMS(Sms(receivedSms.phoneNumber, rh.gs(R.string.invalid_profile))) } } }) diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt index 0b742be32b..2007faee04 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt @@ -14,7 +14,6 @@ import info.nightscout.androidaps.dana.activities.DanaHistoryActivity import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding import info.nightscout.androidaps.dana.events.EventDanaRNewStatus -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.CommandQueue @@ -98,15 +97,13 @@ class DanaFragment : DaggerFragment() { ?: return@setOnClickListener val profileName = danaPump.createConvertedProfile()?.getDefaultProfileName() ?: return@setOnClickListener - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { args -> - args.putLong("time", dateUtil.now()) - args.putInt("mode", ProfileViewerDialog.Mode.CUSTOM_PROFILE.ordinal) - args.putString("customProfile", profile.toString()) - args.putString("customProfileName", profileName) - } - - }.show(childFragmentManager, "ProfileViewDialog") + activityNames.runProfileViewerDialog( + fragmentManager = childFragmentManager, + time = dateUtil.now(), + mode = ActivityNames.Mode.CUSTOM_PROFILE, + customProfile = profile.toString(), + customProfileName = profileName + ) } binding.stats.setOnClickListener { startActivity(Intent(context, activityNames.tddStatsActivity)) } binding.userOptions.setOnClickListener { startActivity(Intent(context, DanaUserOptionsActivity::class.java)) } @@ -160,8 +157,10 @@ class DanaFragment : DaggerFragment() { pumpStatusIcon = when (it.status) { EventPumpStatusChanged.Status.CONNECTING -> "{fa-bluetooth-b spin} ${it.secondsElapsed}s" + EventPumpStatusChanged.Status.CONNECTED -> "{fa-bluetooth}" + EventPumpStatusChanged.Status.DISCONNECTED -> "{fa-bluetooth-b}" diff --git a/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt b/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt index fa47e2b9ff..5a4706c8d6 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/ProfileHelperActivity.kt @@ -10,7 +10,6 @@ import com.google.android.material.tabs.TabLayout import com.google.common.collect.Lists import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.stats.TddCalculator @@ -20,6 +19,7 @@ import info.nightscout.core.fabric.FabricPrivacy import info.nightscout.database.entities.EffectiveProfileSwitch import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.profile.PureProfile +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.events.EventLocalProfileChanged import info.nightscout.shared.extensions.toVisibility @@ -29,6 +29,7 @@ import info.nightscout.ui.R import info.nightscout.ui.databinding.ActivityProfilehelperBinding import info.nightscout.ui.defaultProfile.DefaultProfile import info.nightscout.ui.defaultProfile.DefaultProfileDPV +import info.nightscout.ui.dialogs.ProfileViewerDialog import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign @@ -215,7 +216,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() { ProfileViewerDialog().also { pvd -> pvd.arguments = Bundle().also { it.putLong("time", dateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) + it.putInt("mode", ActivityNames.Mode.PROFILE_COMPARE.ordinal) it.putString("customProfile", profile0.jsonObject.toString()) it.putString("customProfile2", profile1.jsonObject.toString()) it.putString( diff --git a/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt b/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt index 73d40f1253..9aa6565f74 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/SurveyActivity.kt @@ -3,11 +3,10 @@ package info.nightscout.ui.activities import android.os.Bundle import android.widget.ArrayAdapter import info.nightscout.androidaps.activities.NoSplashAppCompatActivity -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction -import info.nightscout.androidaps.interfaces.stats.TddCalculator import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.shared.SafeParse import info.nightscout.shared.utils.DateUtil import info.nightscout.ui.R @@ -18,10 +17,10 @@ import javax.inject.Inject class SurveyActivity : NoSplashAppCompatActivity() { @Inject lateinit var activePlugin: ActivePlugin - @Inject lateinit var tddCalculator: TddCalculator @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var defaultProfile: DefaultProfile @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var activityNames: ActivityNames private lateinit var binding: ActivitySurveyBinding @@ -54,15 +53,14 @@ class SurveyActivity : NoSplashAppCompatActivity() { } profileFunction.getProfile()?.let { runningProfile -> defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())?.let { profile -> - ProfileViewerDialog().also { pvd -> - pvd.arguments = Bundle().also { - it.putLong("time", dateUtil.now()) - it.putInt("mode", ProfileViewerDialog.Mode.PROFILE_COMPARE.ordinal) - it.putString("customProfile", runningProfile.toPureNsJson(dateUtil).toString()) - it.putString("customProfile2", profile.jsonObject.toString()) - it.putString("customProfileName", "Age: $age TDD: $tdd Weight: $weight") - } - }.show(supportFragmentManager, "ProfileViewDialog") + activityNames.runProfileViewerDialog( + fragmentManager = supportFragmentManager, + time = dateUtil.now(), + mode = ActivityNames.Mode.PROFILE_COMPARE, + customProfile = runningProfile.toPureNsJson(dateUtil).toString(), + customProfileName = "Age: $age TDD: $tdd Weight: $weight", + customProfile2 = profile.jsonObject.toString() + ) } } } diff --git a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsProfileSwitchFragment.kt b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsProfileSwitchFragment.kt index 9ec3f45056..7e1e142aea 100644 --- a/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsProfileSwitchFragment.kt +++ b/ui/src/main/java/info/nightscout/ui/activities/fragments/TreatmentsProfileSwitchFragment.kt @@ -17,7 +17,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.support.DaggerFragment import info.nightscout.androidaps.data.ProfileSealed -import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged import info.nightscout.androidaps.events.EventNewHistoryData import info.nightscout.androidaps.extensions.getCustomizedName @@ -33,6 +32,7 @@ import info.nightscout.database.entities.ValueWithUnit import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.InvalidateProfileSwitchTransaction import info.nightscout.interfaces.BuildHelper +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventLocalProfileChanged @@ -49,6 +49,7 @@ import info.nightscout.ui.R import info.nightscout.ui.activities.fragments.TreatmentsProfileSwitchFragment.RecyclerProfileViewAdapter.ProfileSwitchViewHolder import info.nightscout.ui.databinding.TreatmentsProfileswitchFragmentBinding import info.nightscout.ui.databinding.TreatmentsProfileswitchItemBinding +import info.nightscout.ui.dialogs.ProfileViewerDialog import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign @@ -261,7 +262,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider { ProfileViewerDialog().also { pvd -> pvd.arguments = Bundle().also { args -> args.putLong("time", (it.tag as ProfileSealed).timestamp) - args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) + args.putInt("mode", ActivityNames.Mode.RUNNING_PROFILE.ordinal) } pvd.show(childFragmentManager, "ProfileViewDialog") } @@ -270,7 +271,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment(), MenuProvider { ProfileViewerDialog().also { pvd -> pvd.arguments = Bundle().also { args -> args.putLong("time", (it.tag as ProfileSealed).timestamp) - args.putInt("mode", ProfileViewerDialog.Mode.RUNNING_PROFILE.ordinal) + args.putInt("mode", ActivityNames.Mode.RUNNING_PROFILE.ordinal) } pvd.show(childFragmentManager, "ProfileViewDialog") } diff --git a/ui/src/main/java/info/nightscout/ui/di/UiModule.kt b/ui/src/main/java/info/nightscout/ui/di/UiModule.kt index ae386942e8..2d87682a8b 100644 --- a/ui/src/main/java/info/nightscout/ui/di/UiModule.kt +++ b/ui/src/main/java/info/nightscout/ui/di/UiModule.kt @@ -19,6 +19,7 @@ import info.nightscout.ui.activities.fragments.TreatmentsUserEntryFragment import info.nightscout.ui.dialogs.CalibrationDialog import info.nightscout.ui.dialogs.CarbsDialog import info.nightscout.ui.dialogs.CareDialog +import info.nightscout.ui.dialogs.ProfileViewerDialog import info.nightscout.ui.dialogs.WizardInfoDialog @Module @@ -29,6 +30,7 @@ abstract class UiModule { @ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog @ContributesAndroidInjector abstract fun contributesCareDialog(): CareDialog @ContributesAndroidInjector abstract fun contributesWizardInfoDialog(): WizardInfoDialog + @ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog @ContributesAndroidInjector abstract fun contributesTDDStatsActivity(): TDDStatsActivity @ContributesAndroidInjector abstract fun contributeBolusProgressHelperActivity(): BolusProgressHelperActivity diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt b/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt similarity index 88% rename from core/core-main/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt rename to ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt index 4d41ee73af..e522261ef8 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/dialogs/ProfileViewerDialog.kt +++ b/ui/src/main/java/info/nightscout/ui/dialogs/ProfileViewerDialog.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.dialogs +package info.nightscout.ui.dialogs import android.os.Bundle import android.text.Spanned @@ -15,7 +15,6 @@ import info.nightscout.androidaps.extensions.pureProfileFromJson import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.core.main.R -import info.nightscout.core.main.databinding.DialogProfileviewerBinding import info.nightscout.core.profile.fromMgdlToUnits import info.nightscout.core.profile.toUnitsString import info.nightscout.database.impl.AppRepository @@ -23,12 +22,14 @@ import info.nightscout.database.impl.ValueWrapper import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants import info.nightscout.interfaces.profile.Profile +import info.nightscout.interfaces.ui.ActivityNames import info.nightscout.interfaces.utils.HardLimits import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.rx.bus.RxBus import info.nightscout.shared.extensions.toVisibility import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil +import info.nightscout.ui.databinding.DialogProfileviewerBinding import org.json.JSONObject import java.text.DecimalFormat import javax.inject.Inject @@ -47,14 +48,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { private var time: Long = 0 - enum class Mode(val i: Int) { - RUNNING_PROFILE(1), - CUSTOM_PROFILE(2), - DB_PROFILE(3), - PROFILE_COMPARE(4) - } - - private var mode: Mode = Mode.RUNNING_PROFILE + private var mode: ActivityNames.Mode = ActivityNames.Mode.RUNNING_PROFILE private var customProfileJson: String = "" private var customProfileJson2: String = "" private var customProfileName: String = "" @@ -72,10 +66,10 @@ class ProfileViewerDialog : DaggerDialogFragment() { // load data from bundle (savedInstanceState ?: arguments)?.let { bundle -> time = bundle.getLong("time", 0) - mode = Mode.values()[bundle.getInt("mode", Mode.RUNNING_PROFILE.ordinal)] + mode = ActivityNames.Mode.values()[bundle.getInt("mode", ActivityNames.Mode.RUNNING_PROFILE.ordinal)] customProfileJson = bundle.getString("customProfile", "") customProfileName = bundle.getString("customProfileName", "") - if (mode == Mode.PROFILE_COMPARE) + if (mode == ActivityNames.Mode.PROFILE_COMPARE) customProfileJson2 = bundle.getString("customProfile2", "") } @@ -98,7 +92,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { val profileName: String? val date: String? when (mode) { - Mode.RUNNING_PROFILE -> { + ActivityNames.Mode.RUNNING_PROFILE -> { val eps = repository.getEffectiveProfileSwitchActiveAt(time).blockingGet() if (eps !is ValueWrapper.Existing) { dismiss() @@ -108,45 +102,45 @@ class ProfileViewerDialog : DaggerDialogFragment() { profile2 = null profileName = eps.value.originalCustomizedName date = dateUtil.dateAndTimeString(eps.value.timestamp) - binding.datelayout.visibility = View.VISIBLE + binding.dateLayout.visibility = View.VISIBLE } - Mode.CUSTOM_PROFILE -> { + ActivityNames.Mode.CUSTOM_PROFILE -> { profile = pureProfileFromJson(JSONObject(customProfileJson), dateUtil)?.let { ProfileSealed.Pure(it) } profile2 = null profileName = customProfileName date = "" - binding.datelayout.visibility = View.GONE + binding.dateLayout.visibility = View.GONE } - Mode.PROFILE_COMPARE -> { + ActivityNames.Mode.PROFILE_COMPARE -> { profile = pureProfileFromJson(JSONObject(customProfileJson), dateUtil)?.let { ProfileSealed.Pure(it) } profile2 = pureProfileFromJson(JSONObject(customProfileJson2), dateUtil)?.let { ProfileSealed.Pure(it) } profileName = customProfileName binding.headerIcon.setImageResource(R.drawable.ic_compare_profiles) date = "" - binding.datelayout.visibility = View.GONE + binding.dateLayout.visibility = View.GONE } - Mode.DB_PROFILE -> { + ActivityNames.Mode.DB_PROFILE -> { //val profileList = databaseHelper.getProfileSwitchData(time, true) val profileList = repository.getAllProfileSwitches().blockingGet() profile = if (profileList.isNotEmpty()) ProfileSealed.PS(profileList[0]) else null profile2 = null profileName = if (profileList.isNotEmpty()) profileList[0].getCustomizedName() else null date = if (profileList.isNotEmpty()) dateUtil.dateAndTimeString(profileList[0].timestamp) else null - binding.datelayout.visibility = View.VISIBLE + binding.dateLayout.visibility = View.VISIBLE } } - binding.noprofile.visibility = View.VISIBLE + binding.noProfile.visibility = View.VISIBLE - if (mode == Mode.PROFILE_COMPARE) + if (mode == ActivityNames.Mode.PROFILE_COMPARE) profile?.let { profile1 -> profile2?.let { profile2 -> binding.units.text = profileFunction.getUnits().asText binding.dia.text = HtmlHelper.fromHtml(formatColors("", profile1.dia, profile2.dia, DecimalFormat("0.00"), rh.gs(R.string.shorthour))) val profileNames = profileName!!.split("\n").toTypedArray() - binding.activeprofile.text = HtmlHelper.fromHtml(formatColors(profileNames[0], profileNames[1])) + binding.activeProfile.text = HtmlHelper.fromHtml(formatColors(profileNames[0], profileNames[1])) binding.date.text = date binding.ic.text = ics(profile1, profile2) binding.isf.text = isfs(profile1, profile2) @@ -158,16 +152,16 @@ class ProfileViewerDialog : DaggerDialogFragment() { binding.targetGraph.show(profile1, profile2) } - binding.noprofile.visibility = View.GONE + binding.noProfile.visibility = View.GONE val validity = profile1.isValid("ProfileViewDialog", activePlugin.activePump, config, rh, rxBus, hardLimits, false) - binding.invalidprofile.text = rh.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n") - binding.invalidprofile.visibility = validity.isValid.not().toVisibility() + binding.invalidProfile.text = rh.gs(R.string.invalid_profile) + "\n" + validity.reasons.joinToString(separator = "\n") + binding.invalidProfile.visibility = validity.isValid.not().toVisibility() } else profile?.let { binding.units.text = it.units.asText binding.dia.text = rh.gs(R.string.format_hours, it.dia) - binding.activeprofile.text = profileName + binding.activeProfile.text = profileName binding.date.text = date binding.ic.text = it.getIcList(rh, dateUtil) binding.isf.text = it.getIsfList(rh, dateUtil) @@ -178,10 +172,10 @@ class ProfileViewerDialog : DaggerDialogFragment() { binding.icGraph.show(it) binding.targetGraph.show(it) - binding.noprofile.visibility = View.GONE + binding.noProfile.visibility = View.GONE val validity = it.isValid("ProfileViewDialog", activePlugin.activePump, config, rh, rxBus, hardLimits, false) - binding.invalidprofile.text = rh.gs(R.string.invalidprofile) + "\n" + validity.reasons.joinToString(separator = "\n") - binding.invalidprofile.visibility = validity.isValid.not().toVisibility() + binding.invalidProfile.text = rh.gs(R.string.invalid_profile) + "\n" + validity.reasons.joinToString(separator = "\n") + binding.invalidProfile.visibility = validity.isValid.not().toVisibility() } } @@ -196,7 +190,7 @@ class ProfileViewerDialog : DaggerDialogFragment() { bundle.putInt("mode", mode.ordinal) bundle.putString("customProfile", customProfileJson) bundle.putString("customProfileName", customProfileName) - if (mode == Mode.PROFILE_COMPARE) + if (mode == ActivityNames.Mode.PROFILE_COMPARE) bundle.putString("customProfile2", customProfileJson2) } @@ -323,4 +317,4 @@ class ProfileViewerDialog : DaggerDialogFragment() { } return HtmlHelper.fromHtml(s.delete(s.length - 4, s.length).toString()) } -} +} \ No newline at end of file diff --git a/core/core-main/src/main/res/layout/dialog_profileviewer.xml b/ui/src/main/res/layout/dialog_profileviewer.xml similarity index 97% rename from core/core-main/src/main/res/layout/dialog_profileviewer.xml rename to ui/src/main/res/layout/dialog_profileviewer.xml index 9443131400..8b16417c24 100644 --- a/core/core-main/src/main/res/layout/dialog_profileviewer.xml +++ b/ui/src/main/res/layout/dialog_profileviewer.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:focusableInTouchMode="true" - tools:context="info.nightscout.androidaps.dialogs.ProfileViewerDialog"> + tools:context=".dialogs.ProfileViewerDialog">