diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt b/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt index a1e2b1a5ad..d457732323 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt +++ b/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt @@ -179,9 +179,9 @@ class DataHandlerWear @Inject constructor( } } sp.putBoolean(R.string.key_units_mgdl, it.unitsMgdl) - sp.putInt(R.string.key_boluswizard_percentage, it.bolusPercentage) - sp.putInt(R.string.key_treatmentssafety_maxcarbs, it.maxCarbs) - sp.putDouble(R.string.key_treatmentssafety_maxbolus, it.maxBolus) + sp.putInt(R.string.key_bolus_wizard_percentage, it.bolusPercentage) + sp.putInt(R.string.key_treatments_safety_max_carbs, it.maxCarbs) + sp.putDouble(R.string.key_treatments_safety_max_bolus, it.maxBolus) } disposable += rxBus .toObservable(EventData.QuickWizard::class.java) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt index 890da028fb..979ba52887 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/BolusActivity.kt @@ -38,7 +38,7 @@ class BolusActivity : ViewSelectorActivity() { if (col == 0) { view = getInflatedPlusMinusView(container) val initValue = if (editInsulin != null) SafeParse.stringToDouble(editInsulin?.editText?.text.toString()) else 0.0 - val maxBolus = sp.getDouble(getString(R.string.key_treatmentssafety_maxbolus), 3.0) + val maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0) editInsulin = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, initValue, 0.0, maxBolus, 0.1, DecimalFormat("#0.0"), false) setLabelToPlusMinusView(view, getString(R.string.action_insulin)) container.addView(view) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt index ed4472b6bd..44d226debd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/CarbActivity.kt @@ -41,7 +41,7 @@ class CarbActivity : ViewSelectorActivity() { if (editCarbs != null) { def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString()) } - val maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48) + val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) editCarbs = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), true) setLabelToPlusMinusView(view, getString(R.string.action_carbs)) container.addView(view) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt index 6fcc695fc2..c0207f6baa 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/ECarbActivity.kt @@ -43,7 +43,7 @@ class ECarbActivity : ViewSelectorActivity() { if (editCarbs != null) { def = stringToDouble(editCarbs?.editText?.text.toString()) } - val maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48) + val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48) editCarbs = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), true) setLabelToPlusMinusView(view, getString(R.string.action_carbs)) container.addView(view) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java deleted file mode 100644 index 22cb47811f..0000000000 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.java +++ /dev/null @@ -1,152 +0,0 @@ -package info.nightscout.androidaps.interaction.actions; - -import android.os.Bundle; -import android.support.wearable.view.GridPagerAdapter; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; - -import java.text.DecimalFormat; - -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventWearToMobile; -import info.nightscout.androidaps.interaction.utils.PlusMinusEditText; -import info.nightscout.shared.SafeParse; -import info.nightscout.shared.weardata.EventData; - -/** - * Created by adrian on 09/02/17. - */ - -public class TempTargetActivity extends ViewSelectorActivity { - - PlusMinusEditText lowRange; - PlusMinusEditText highRange; - PlusMinusEditText time; - boolean isMGDL; - boolean isSingleTarget; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setAdapter(new MyGridViewPagerAdapter()); - - isMGDL = sp.getBoolean("units_mgdl", true); - isSingleTarget = sp.getBoolean("singletarget", true); - } - - @Override - protected void onPause() { - super.onPause(); - finish(); - } - - @SuppressWarnings("deprecation") - private class MyGridViewPagerAdapter extends GridPagerAdapter { - @Override - public int getColumnCount(int arg0) { - return isSingleTarget ? 3 : 4; - } - - @Override - public int getRowCount() { - return 1; - } - - @Override - public Object instantiateItem(ViewGroup container, int row, int col) { - - if (col == 0) { - final View view = getInflatedPlusMinusView(container); - if (time == null) { - time = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 60d, 0d, 24 * 60d, 5d, new DecimalFormat("0"), false); - } else { - double def = SafeParse.stringToDouble(time.editText.getText().toString()); - time = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 24 * 60d, 5d, new DecimalFormat("0"), false); - } - setLabelToPlusMinusView(view, getString(R.string.action_duration)); - container.addView(view); - view.requestFocus(); - return view; - - } else if (col == 1) { - final View view = getInflatedPlusMinusView(container); - if (isMGDL) { - double def = 100; - if (lowRange != null) { - def = SafeParse.stringToDouble(lowRange.editText.getText().toString()); - } - lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false); - } else { - double def = 5.5; - if (lowRange != null) { - def = SafeParse.stringToDouble(lowRange.editText.getText().toString()); - } - lowRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); - } - if (isSingleTarget) { - setLabelToPlusMinusView(view, getString(R.string.action_target)); - } else { - setLabelToPlusMinusView(view, getString(R.string.action_low)); - } - container.addView(view); - return view; - } else if (col == 2 && !isSingleTarget) { - final View view = getInflatedPlusMinusView(container); - if (isMGDL) { - double def = 100; - if (highRange != null) { - def = SafeParse.stringToDouble(highRange.editText.getText().toString()); - } - highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72d, 180d, 1d, new DecimalFormat("0"), false); - } else { - double def = 5.5; - if (highRange != null) { - def = SafeParse.stringToDouble(highRange.editText.getText().toString()); - } - highRange = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4d, 10d, 0.1d, new DecimalFormat("#0.0"), false); - } - setLabelToPlusMinusView(view, getString(R.string.action_high)); - container.addView(view); - return view; - } else { - - final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); - final ImageView confirmButton = view.findViewById(R.id.confirmbutton); - confirmButton.setOnClickListener((View v) -> { - //check if it can happen that the fragment is never created that hold data? - // (you have to swipe past them anyways - but still) - - EventData.ActionTempTargetPreCheck action = new EventData.ActionTempTargetPreCheck( - EventData.ActionTempTargetPreCheck.TempTargetCommand.MANUAL, - isMGDL, - SafeParse.stringToInt(time.editText.getText().toString()), - SafeParse.stringToDouble(lowRange.editText.getText().toString()), - (isSingleTarget ? - SafeParse.stringToDouble(lowRange.editText.getText().toString()) : SafeParse.stringToDouble(highRange.editText.getText().toString())) - ); - rxBus.send(new EventWearToMobile(action)); - showToast(TempTargetActivity.this, R.string.action_tempt_confirmation); - finishAffinity(); - }); - container.addView(view); - return view; - } - } - - @Override - public void destroyItem(ViewGroup container, int row, int col, Object view) { - // Handle this to get the data before the view is destroyed? - // Object should still be kept by this, just setup for re-init? - container.removeView((View) view); - } - - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - - } -} diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt new file mode 100644 index 0000000000..d999a61eb1 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TempTargetActivity.kt @@ -0,0 +1,122 @@ +@file:Suppress("DEPRECATION") + +package info.nightscout.androidaps.interaction.actions + +import android.os.Bundle +import android.support.wearable.view.GridPagerAdapter +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import info.nightscout.androidaps.R +import info.nightscout.androidaps.events.EventWearToMobile +import info.nightscout.androidaps.interaction.utils.PlusMinusEditText +import info.nightscout.shared.SafeParse +import info.nightscout.shared.weardata.EventData.ActionTempTargetPreCheck +import java.text.DecimalFormat + +class TempTargetActivity : ViewSelectorActivity() { + + var lowRange: PlusMinusEditText? = null + var highRange: PlusMinusEditText? = null + var time: PlusMinusEditText? = null + var isMGDL = false + var isSingleTarget = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setAdapter(MyGridViewPagerAdapter()) + isMGDL = sp.getBoolean(R.string.key_units_mgdl, true) + isSingleTarget = sp.getBoolean(R.string.key_single_target, true) + } + + override fun onPause() { + super.onPause() + finish() + } + + private inner class MyGridViewPagerAdapter : GridPagerAdapter() { + + override fun getColumnCount(arg0: Int): Int { + return if (isSingleTarget) 3 else 4 + } + + override fun getRowCount(): Int { + return 1 + } + + override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any { + return if (col == 0) { + val view = getInflatedPlusMinusView(container) + time = if (time == null) { + PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 60.0, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false) + } else { + val def = SafeParse.stringToDouble(time?.editText?.text.toString()) + PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 24 * 60.0, 5.0, DecimalFormat("0"), false) + } + setLabelToPlusMinusView(view, getString(R.string.action_duration)) + container.addView(view) + view.requestFocus() + view + } else if (col == 1) { + val view = getInflatedPlusMinusView(container) + if (isMGDL) { + var def = 100.0 + if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) + lowRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false) + } else { + var def = 5.5 + if (lowRange != null) def = SafeParse.stringToDouble(lowRange?.editText?.text.toString()) + lowRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false) + } + if (isSingleTarget) setLabelToPlusMinusView(view, getString(R.string.action_target)) + else setLabelToPlusMinusView(view, getString(R.string.action_low)) + container.addView(view) + view + } else if (col == 2 && !isSingleTarget) { + val view = getInflatedPlusMinusView(container) + if (isMGDL) { + var def = 100.0 + if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) + highRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 72.0, 180.0, 1.0, DecimalFormat("0"), false) + } else { + var def = 5.5 + if (highRange != null) def = SafeParse.stringToDouble(highRange?.editText?.text.toString()) + highRange = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 4.0, 10.0, 0.1, DecimalFormat("#0.0"), false) + } + setLabelToPlusMinusView(view, getString(R.string.action_high)) + container.addView(view) + view + } else { + val view = LayoutInflater.from(applicationContext).inflate(R.layout.action_send_item, container, false) + val confirmButton = view.findViewById(R.id.confirmbutton) + confirmButton.setOnClickListener { + //check if it can happen that the fragment is never created that hold data? + // (you have to swipe past them anyways - but still) + val action = ActionTempTargetPreCheck( + ActionTempTargetPreCheck.TempTargetCommand.MANUAL, + isMGDL, + SafeParse.stringToInt(time?.editText?.text.toString()), + SafeParse.stringToDouble(lowRange?.editText?.text.toString()), + if (isSingleTarget) SafeParse.stringToDouble(lowRange?.editText?.text.toString()) else SafeParse.stringToDouble(highRange?.editText?.text.toString()) + ) + rxBus.send(EventWearToMobile(action)) + showToast(this@TempTargetActivity, R.string.action_tempt_confirmation) + finishAffinity() + } + container.addView(view) + view + } + } + + override fun destroyItem(container: ViewGroup, row: Int, col: Int, view: Any) { + // Handle this to get the data before the view is destroyed? + // Object should still be kept by this, just setup for re-init? + container.removeView(view as View) + } + + override fun isViewFromObject(view: View, `object`: Any): Boolean { + return view === `object` + } + } +} \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.java index fa353128ba..d523eebbd4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/TreatmentActivity.java @@ -30,8 +30,8 @@ public class TreatmentActivity extends ViewSelectorActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAdapter(new MyGridViewPagerAdapter()); - maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48); - maxBolus = sp.getDouble(getString(R.string.key_treatmentssafety_maxbolus), 3.0); + maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48); + maxBolus = sp.getDouble(getString(R.string.key_treatments_safety_max_bolus), 3.0); } @Override diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java index 698c3fc59d..4917a34dcd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/actions/WizardActivity.java @@ -33,8 +33,8 @@ public class WizardActivity extends ViewSelectorActivity { super.onCreate(savedInstanceState); setAdapter(new MyGridViewPagerAdapter()); hasPercentage = sp.getBoolean("wizardpercentage", false); - percentage = sp.getInt(getString(R.string.key_boluswizard_percentage), 100); - maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48); + percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100); + maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48); } @Override diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index 648f1745e2..8d8ce23c8e 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -187,11 +187,12 @@ QuickWizard wearcontrol units_mgdl - boluswizard_percentage - treatmentssafety_maxcarbs - treatmentssafety_maxbolus + boluswizard_percentage + treatmentssafety_maxcarbs + treatmentssafety_maxbolus quick_wizard_data primefill showWizard + singletarget diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index efadbc39d9..3ec4a5bbec 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -134,7 +134,7 @@