ProfileViewerDialog -> ui

This commit is contained in:
Milos Kozak 2022-11-11 09:38:36 +01:00
parent 18204d06b9
commit e4ccc78a7d
19 changed files with 121 additions and 110 deletions

View file

@ -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")
}
}

View file

@ -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
}

View file

@ -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()) {

View file

@ -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()) {

View file

@ -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) {

View file

@ -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 -> {

View file

@ -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)

View file

@ -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
}

View file

@ -131,8 +131,8 @@
<string name="stoppressed">STOP PRESSED</string>
<string name="stop">Stop</string>
<string name="carbs">Carbs</string>
<string name="invalidprofile">Invalid profile!</string>
<string name="noprofileset">NO PROFILE SET</string>
<string name="invalid_profile">Invalid profile!</string>
<string name="no_profile_set">NO PROFILE SET</string>
<string name="active"><![CDATA[<Active>]]></string>
<string name="date">Date</string>
<string name="units_label">Units</string>

View file

@ -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)
}

View file

@ -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 {

View file

@ -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)))
}
}
})

View file

@ -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}"

View file

@ -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(

View file

@ -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()
)
}
}
}

View file

@ -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")
}

View file

@ -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

View file

@ -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())
}
}
}

View file

@ -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">
<LinearLayout
android:layout_width="match_parent"
@ -27,7 +27,7 @@
app:srcCompat="@drawable/ic_home_profile" />
<TextView
android:id="@+id/activeprofile"
android:id="@+id/active_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
@ -49,29 +49,29 @@
android:padding="5dp" />
<TextView
android:id="@+id/invalidprofile"
android:id="@+id/invalid_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/invalidprofile"
android:text="@string/invalid_profile"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?attr/alarmColor"
android:textStyle="bold"
android:visibility="gone" />
<TextView
android:id="@+id/noprofile"
android:id="@+id/no_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/noprofileset"
android:text="@string/no_profile_set"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?attr/alarmColor"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:id="@+id/datelayout"
android:id="@+id/date_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
@ -378,7 +378,7 @@
android:textSize="14sp" />
<TextView
android:id="@+id/basaltotal"
android:id="@+id/basal_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"