TempTargetActivity -> kt
This commit is contained in:
parent
d94ab441da
commit
70d96d42cc
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<ImageView>(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`
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -187,11 +187,12 @@
|
|||
<string name="key_quickwizard" translatable="false">QuickWizard</string>
|
||||
<string name="key_wear_control" translatable="false">wearcontrol</string>
|
||||
<string name="key_units_mgdl" translatable="false">units_mgdl</string>
|
||||
<string name="key_boluswizard_percentage" translatable="false">boluswizard_percentage</string>
|
||||
<string name="key_treatmentssafety_maxcarbs" translatable="false">treatmentssafety_maxcarbs</string>
|
||||
<string name="key_treatmentssafety_maxbolus" translatable="false">treatmentssafety_maxbolus</string>
|
||||
<string name="key_bolus_wizard_percentage" translatable="false">boluswizard_percentage</string>
|
||||
<string name="key_treatments_safety_max_carbs" translatable="false">treatmentssafety_maxcarbs</string>
|
||||
<string name="key_treatments_safety_max_bolus" translatable="false">treatmentssafety_maxbolus</string>
|
||||
<string name="key_quick_wizard_data" translatable="false">quick_wizard_data</string>
|
||||
<string name="key_prime_fill" translatable="false">primefill</string>
|
||||
<string name="key_show_wizard" translatable="false">showWizard</string>
|
||||
<string name="key_single_target" translatable="false">singletarget</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -134,7 +134,7 @@
|
|||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="singletarget"
|
||||
android:key="@string/key_single_target"
|
||||
android:summary="Single temp-target instead of a range."
|
||||
android:title="@string/pref_single_target"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
|
|
Loading…
Reference in a new issue