Skip to content

Commit

Permalink
Dexcom: restore open button
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosKozak committed Jan 7, 2025
1 parent 1e6bfc6 commit f5c2fba
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ interface DexcomBoyda {

fun isEnabled(): Boolean
fun requestPermissionIfNeeded()
fun dexcomPackages(): List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import app.aaps.core.interfaces.db.PersistenceLayer
import app.aaps.core.interfaces.iob.GlucoseStatusProvider
import app.aaps.core.interfaces.iob.IobCobCalculator
import app.aaps.core.interfaces.logging.AAPSLogger
import app.aaps.core.interfaces.logging.LTag
import app.aaps.core.interfaces.logging.UserEntryLogger
import app.aaps.core.interfaces.nsclient.NSSettingsStatus
import app.aaps.core.interfaces.nsclient.ProcessedDeviceStatusData
Expand Down Expand Up @@ -424,8 +425,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
}

R.id.cgm_button -> {
if (xDripSource.isEnabled())
openCgmApp("com.eveningoutpost.dexdrip", "Home")
if (xDripSource.isEnabled()) openCgmApp("com.eveningoutpost.dexdrip")
else if (dexcomBoyda.isEnabled()) dexcomBoyda.dexcomPackages().forEach { openCgmApp(it) }
}

R.id.calibration_button -> {
Expand Down Expand Up @@ -468,12 +469,16 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
}
}

@Suppress("SameParameterValue")
private fun openCgmApp(packageName: String, launchActivity: String) {
try {
requireContext().startActivity(Intent(Intent.ACTION_MAIN).setClassName(packageName, "$packageName.$launchActivity"))
} catch (_: ActivityNotFoundException) {
OKDialog.show(requireContext(), "", rh.gs(R.string.error_starting_cgm))
private fun openCgmApp(packageName: String) {
context?.let {
val packageManager = it.packageManager
try {
val intent = packageManager.getLaunchIntentForPackage(packageName) ?: throw ActivityNotFoundException()
intent.addCategory(Intent.CATEGORY_LAUNCHER)
it.startActivity(intent)
} catch (_: ActivityNotFoundException) {
aapsLogger.debug(LTag.CORE, "Error opening CGM app")
}
}
}

Expand Down Expand Up @@ -594,16 +599,24 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList

// **** Calibration & CGM buttons ****
val xDripIsBgSource = xDripSource.isEnabled()
val dexcomIsSource = dexcomBoyda.isEnabled()
binding.buttonsLayout.calibrationButton.visibility = (xDripIsBgSource && actualBG != null && preferences.get(BooleanKey.OverviewShowCalibrationButton)).toVisibility()
if (xDripIsBgSource) {
if (dexcomIsSource) {
binding.buttonsLayout.cgmButton.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_byoda), null, null)
for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) {
drawable?.mutate()
drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, app.aaps.core.ui.R.attr.cgmDexColor), PorterDuff.Mode.SRC_IN)
}
binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, app.aaps.core.ui.R.attr.cgmDexColor))
} else if (xDripIsBgSource) {
binding.buttonsLayout.cgmButton.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(app.aaps.core.objects.R.drawable.ic_xdrip), null, null)
for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) {
drawable?.mutate()
drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, app.aaps.core.ui.R.attr.cgmXdripColor), PorterDuff.Mode.SRC_IN)
}
binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, app.aaps.core.ui.R.attr.cgmXdripColor))
}
binding.buttonsLayout.cgmButton.visibility = (preferences.get(BooleanKey.OverviewShowCgmButton) && xDripIsBgSource).toVisibility()
binding.buttonsLayout.cgmButton.visibility = (preferences.get(BooleanKey.OverviewShowCgmButton) && (xDripIsBgSource || dexcomIsSource)).toVisibility()

// Automation buttons
binding.buttonsLayout.userButtonsLayout.removeAllViews()
Expand Down Expand Up @@ -1143,7 +1156,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_as_below
else -> app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
else -> app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
}
}
?: app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
Expand All @@ -1154,14 +1167,13 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_below
else -> app.aaps.core.objects.R.drawable.ic_x_swap_vert
else -> app.aaps.core.objects.R.drawable.ic_x_swap_vert
}
}
?: app.aaps.core.objects.R.drawable.ic_x_swap_vert
)
}


// Show variable sensitivity
val profile = profileFunction.getProfile()
val request = loop.lastRun?.request
Expand All @@ -1180,7 +1192,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val autoSensMax = 100.0 + (preferences.get(DoubleKey.AutosensMax) - 1.0) * autoSensHiddenRange * 100.0
val autoSensMin = 100.0 + (preferences.get(DoubleKey.AutosensMin) - 1.0) * autoSensHiddenRange * 100.0
lastAutosensRatio?.let {
if(it < autoSensMin || it > autoSensMax)
if (it < autoSensMin || it > autoSensMax)
overViewText.add(rh.gs(app.aaps.core.ui.R.string.autosens_short, it))
okDialogText.add(rh.gs(app.aaps.core.ui.R.string.autosens_long, it))
}
Expand All @@ -1200,15 +1212,15 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
if (config.APS) {
val aps = activePlugin.activeAPS
aps.getSensitivityOverviewString()?.let {
okDialogText.add("$it")
okDialogText.add(it)
}
}
binding.infoLayout.asLayout.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(app.aaps.core.ui.R.string.sensitivity), okDialogText.joinToString("\n")) } }

} else {
binding.infoLayout.sensitivity.text =
lastAutosensData?.let {
rh.gs(app.aaps.core.ui.R.string.autosens_short,it.autosensResult.ratio * 100)
rh.gs(app.aaps.core.ui.R.string.autosens_short, it.autosensResult.ratio * 100)
} ?: ""
binding.infoLayout.variableSensitivity.visibility = View.GONE
binding.infoLayout.sensitivity.visibility = View.VISIBLE
Expand Down
3 changes: 1 addition & 2 deletions plugins/main/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@
<string name="description_overview">Displays the current state of your loop and buttons for most common actions</string>
<string name="overview_buttons_selection">Buttons</string>
<string name="show_calibration_button_summary">Sends a calibration to xDrip+ (ensure \'Accept Calibrations\' is enabled in xDrip+ under Inter-App settings).</string>
<string name="show_cgm_button_summary">Opens xDrip+ (you can use back button to return to AAPS).</string>
<string name="error_starting_cgm">Could not launch CGM application. Make sure it is installed.</string>
<string name="show_cgm_button_summary">Opens xDrip+ or Dexcom App (you can use back button to return to AAPS).</string>
<string name="not_available_full">Not available</string>
<string name="constraints_violation">Constraints violation</string>
<string name="change_your_input">Change your input!</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ class DexcomPlugin @Inject constructor(
}
}

override fun dexcomPackages() = PACKAGE_NAMES

companion object {

private val PACKAGE_NAMES = listOf(
"com.dexcom.g6.region1.mmol", "com.dexcom.g6.region2.mgdl",
"com.dexcom.g6.region3.mgdl", "com.dexcom.g6.region3.mmol",
"com.dexcom.g6", "com.dexcom.g7"
)
const val PERMISSION = "com.dexcom.cgm.EXTERNAL_PERMISSION"
}
}

0 comments on commit f5c2fba

Please sign in to comment.