Add percentage in quickwizard
This commit is contained in:
parent
eda1c097a9
commit
606a7d6c27
6 changed files with 96 additions and 13 deletions
|
@ -35,7 +35,6 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
@Inject lateinit var sp: SP
|
||||
|
||||
var position = -1
|
||||
|
||||
var fromSeconds: Int = 0
|
||||
var toSeconds: Int = 0
|
||||
|
||||
|
@ -45,8 +44,10 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
// onDestroyView.
|
||||
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 {
|
||||
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||
isCancelable = true
|
||||
|
@ -82,6 +83,9 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
entry.storage.put("useTrend", binding.useTrend.selectedItemPosition)
|
||||
entry.storage.put("useSuperBolus", binding.useSuperBolus.selectedItemPosition)
|
||||
entry.storage.put("useTempTarget", binding.useTempTarget.selectedItemPosition)
|
||||
entry.storage.put("usePercentage", binding.usePercentage.selectedItemPosition)
|
||||
val percentage = SafeParse.stringToInt(binding.percentage.text.toString())
|
||||
entry.storage.put("percentage", percentage)
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
}
|
||||
|
@ -100,7 +104,8 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
|
||||
binding.from.setOnClickListener {
|
||||
context?.let {
|
||||
TimePickerDialog(it, fromTimeSetListener,
|
||||
TimePickerDialog(
|
||||
it, fromTimeSetListener,
|
||||
T.secs(fromSeconds.toLong()).hours().toInt(),
|
||||
T.secs((fromSeconds % 3600).toLong()).mins().toInt(),
|
||||
DateFormat.is24HourFormat(context)
|
||||
|
@ -117,13 +122,29 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
|
||||
binding.to.setOnClickListener {
|
||||
context?.let {
|
||||
TimePickerDialog(it, toTimeSetListener,
|
||||
TimePickerDialog(
|
||||
it, toTimeSetListener,
|
||||
T.secs(toSeconds.toLong()).hours().toInt(),
|
||||
T.secs((toSeconds % 3600).toLong()).mins().toInt(),
|
||||
DateFormat.is24HourFormat(context)
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun usePercentage(custom: Boolean) {
|
||||
if (custom) {
|
||||
binding.percentageLabel.visibility = View.VISIBLE
|
||||
binding.percentage.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.percentageLabel.visibility = View.GONE
|
||||
binding.percentage.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
binding.usePercentage.setOnCheckedChangeListener { _, checkedId ->
|
||||
usePercentage(checkedId == R.id.use_percentage_custom)
|
||||
}
|
||||
|
||||
toSeconds = entry.validTo()
|
||||
binding.to.text = dateUtil.timeString(dateUtil.secondsOfTheDayToMilliseconds(toSeconds))
|
||||
|
||||
|
@ -138,7 +159,9 @@ class EditQuickWizardDialog : DaggerDialogFragment(), View.OnClickListener {
|
|||
binding.useTrend.setSelection(entry.useTrend())
|
||||
binding.useSuperBolus.setSelection(entry.useSuperBolus())
|
||||
binding.useTempTarget.setSelection(entry.useTempTarget())
|
||||
|
||||
binding.usePercentage.setSelection(entry.usePercentage())
|
||||
usePercentage(entry.usePercentage() == QuickWizardEntry.CUSTOM)
|
||||
binding.percentage.setText(entry.percentage().toString())
|
||||
binding.useCobYes.setOnClickListener(this)
|
||||
binding.useCobNo.setOnClickListener(this)
|
||||
processCob()
|
||||
|
|
|
@ -405,9 +405,9 @@ class BolusWizard @Inject constructor(
|
|||
if (useBg) message += "\n" + rh.gs(R.string.wizard_explain_bg, insulinFromBG)
|
||||
if (includeBolusIOB) message += "\n" + rh.gs(R.string.wizard_explain_bolus_iob, insulinFromBolusIOB)
|
||||
if (includeBasalIOB) message += "\n" + rh.gs(R.string.wizard_explain_basal_iob, insulinFromBasalIOB)
|
||||
if (usePercentage) message += "\n" + rh.gs(R.string.wizard_explain_trend, insulinFromTrend)
|
||||
if (useTrend) message += "\n" + rh.gs(R.string.wizard_explain_trend, insulinFromTrend)
|
||||
if (useSuperBolus) message += "\n" + rh.gs(R.string.wizard_explain_superbolus, insulinFromSuperBolus)
|
||||
if (usePercentage) {
|
||||
if (percentageCorrection != 100) {
|
||||
message += "\n" + rh.gs(R.string.wizard_explain_percent, totalBeforePercentageAdjustment, percentageCorrection, calculatedTotalInsulin)
|
||||
}
|
||||
return message
|
||||
|
|
|
@ -45,12 +45,23 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
|
|||
const val DEVICE_ALL = 0
|
||||
const val DEVICE_PHONE = 1
|
||||
const val DEVICE_WATCH = 2
|
||||
const val DEFAULT = 0
|
||||
const val CUSTOM = 1
|
||||
}
|
||||
|
||||
init {
|
||||
injector.androidInjector().inject(this)
|
||||
val guid = UUID.randomUUID().toString()
|
||||
val emptyData = "{\"guid\": \"$guid\",\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340, \"device\": \"all\"}"
|
||||
val emptyData = """{
|
||||
"guid": "$guid",
|
||||
"buttonText": "",
|
||||
"carbs": 0,
|
||||
"validFrom": 0,
|
||||
"validTo": 86340,
|
||||
"device": "all",
|
||||
"usePercentage": "default",
|
||||
"percentage": 100
|
||||
}""".trimMargin()
|
||||
try {
|
||||
storage = JSONObject(emptyData)
|
||||
} catch (e: JSONException) {
|
||||
|
@ -73,6 +84,8 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
|
|||
useTrend: 0,
|
||||
useSuperBolus: 0,
|
||||
useTemptarget: 0
|
||||
usePercentage: string, // default, custom
|
||||
percentage: int,
|
||||
}
|
||||
*/
|
||||
fun from(entry: JSONObject, position: Int): QuickWizardEntry {
|
||||
|
@ -127,7 +140,7 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
|
|||
} else if (useTrend() == NEGATIVE_ONLY && glucoseStatus != null && glucoseStatus.shortAvgDelta < 0) {
|
||||
trend = true
|
||||
}
|
||||
val percentage = sp.getInt(R.string.key_boluswizard_percentage, 100)
|
||||
val percentage = if (usePercentage() == DEFAULT) sp.getInt(R.string.key_boluswizard_percentage, 100) else percentage()
|
||||
return BolusWizard(injector).doCalc(profile, profileName, tempTarget, carbs(), cob, bg, 0.0, percentage, true, useCOB() == YES, bolusIOB, basalIOB, superBolus, useTempTarget() == YES, trend, false, buttonText(), quickWizard = true) //tbc, ok if only quickwizard, but if other sources elsewhere use Sources.QuickWizard
|
||||
}
|
||||
|
||||
|
@ -162,4 +175,8 @@ class QuickWizardEntry @Inject constructor(private val injector: HasAndroidInjec
|
|||
fun useSuperBolus(): Int = safeGetInt(storage, "useSuperBolus", NO)
|
||||
|
||||
fun useTempTarget(): Int = safeGetInt(storage, "useTempTarget", NO)
|
||||
|
||||
fun usePercentage(): Int = safeGetInt(storage, "usePercentage", DEFAULT)
|
||||
|
||||
fun percentage(): Int = safeGetInt(storage, "percentage", 100)
|
||||
}
|
||||
|
|
|
@ -305,7 +305,6 @@
|
|||
|
||||
</RadioGroup>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -330,6 +329,47 @@
|
|||
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/overview_editquickwizard_usepercentage"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/use_percentage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="15dp">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/use_percentage_default"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_default" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/use_percentage_custom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/custom" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/percentage_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/overview_editquickwizard_percentage"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/percentage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="number"
|
||||
android:maxLength="3"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<include
|
||||
android:id="@+id/okcancel"
|
||||
|
|
|
@ -617,6 +617,7 @@
|
|||
<string name="negativeonly">Negative only</string>
|
||||
<string name="overview_editquickwizard_usecob">COB calculation</string>
|
||||
<string name="overview_editquickwizard_usetemptarget">Temporary target calculation</string>
|
||||
<string name="overview_editquickwizard_usepercentage">Percentage calculation</string>
|
||||
<string name="loopenabled">Loop enabled</string>
|
||||
<string name="apsselected">APS selected</string>
|
||||
<string name="nsclienthaswritepermission">NSClient has write permission</string>
|
||||
|
@ -1191,10 +1192,12 @@
|
|||
<string name="wizard_explain_bolus_iob">Bolus IOB: %1$.2fU</string>
|
||||
<string name="wizard_explain_superbolus">Superbolus: %1$.2fU</string>
|
||||
<string name="wizard_explain_trend">15\' trend: %1$.2fU</string>
|
||||
<string name="wizard_explain_percent">Perctage: %1$.2fU x %2$d% = %3$.2fU</string>
|
||||
<string name="wizard_explain_percent">Percentage: %1$.2fU x %2$d%% ≈ %3$.2fU</string>
|
||||
<string name="wizard_constraint_bolus_size">Insulin constraint violation!\nCannot deliver %1$.2fU</string>
|
||||
<string name="wizard_explain_tt">TempT: %1$s</string>
|
||||
<string name="wizard_explain_tt_to">%1$s to %2$s</string>
|
||||
<string name="wizard_pump_not_available">No pump available!</string>
|
||||
<string name="wear_unknown_action_string">Unknown action command:</string>
|
||||
<string name="overview_editquickwizard_percentage">Percentage</string>
|
||||
<string name="app_default">Application default</string>
|
||||
</resources>
|
||||
|
|
|
@ -613,7 +613,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
|||
// Log.d(TAG, logPrefix + "onConnected call requestData");
|
||||
|
||||
Wearable.ChannelApi.addListener(googleApiClient, this);
|
||||
requestData();
|
||||
// requestData();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue