WizardActivity -> kt
This commit is contained in:
parent
60fc476f6d
commit
7050cd507c
4 changed files with 92 additions and 120 deletions
|
@ -1,119 +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 WizardActivity extends ViewSelectorActivity {
|
||||
|
||||
PlusMinusEditText editCarbs;
|
||||
PlusMinusEditText editPercentage;
|
||||
|
||||
boolean hasPercentage;
|
||||
int percentage;
|
||||
int maxCarbs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setAdapter(new MyGridViewPagerAdapter());
|
||||
hasPercentage = sp.getBoolean("wizardpercentage", false);
|
||||
percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100);
|
||||
maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
finish();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
||||
@Override
|
||||
public int getColumnCount(int arg0) {
|
||||
return hasPercentage ? 3 : 2;
|
||||
}
|
||||
|
||||
@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 (editCarbs == null) {
|
||||
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0d, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"), false);
|
||||
} else {
|
||||
double def = SafeParse.stringToDouble(editCarbs.editText.getText().toString());
|
||||
editCarbs = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, (double)maxCarbs, 1d, new DecimalFormat("0"),false);
|
||||
}
|
||||
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
|
||||
container.addView(view);
|
||||
view.requestFocus();
|
||||
return view;
|
||||
} else if (col == 1 && hasPercentage) {
|
||||
final View view = getInflatedPlusMinusView(container);
|
||||
if (editPercentage == null) {
|
||||
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, (double)percentage, 50d, 150d, 1d, new DecimalFormat("0"), false);
|
||||
} else {
|
||||
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
|
||||
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
|
||||
}
|
||||
setLabelToPlusMinusView(view, getString(R.string.action_percentage));
|
||||
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) -> {
|
||||
if (editPercentage != null) {
|
||||
percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
|
||||
}
|
||||
|
||||
EventData.ActionWizardPreCheck action = new EventData.ActionWizardPreCheck(
|
||||
SafeParse.stringToInt(editCarbs.editText.getText().toString()),
|
||||
percentage
|
||||
);
|
||||
rxBus.send(new EventWearToMobile(action));
|
||||
showToast(WizardActivity.this, R.string.action_wizard_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,90 @@
|
|||
@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.ActionWizardPreCheck
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class WizardActivity : ViewSelectorActivity() {
|
||||
|
||||
var editCarbs: PlusMinusEditText? = null
|
||||
var editPercentage: PlusMinusEditText? = null
|
||||
var hasPercentage = false
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setAdapter(MyGridViewPagerAdapter())
|
||||
hasPercentage = sp.getBoolean(R.string.key_wizard_percentage, false)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
finish()
|
||||
}
|
||||
|
||||
private inner class MyGridViewPagerAdapter : GridPagerAdapter() {
|
||||
|
||||
override fun getColumnCount(arg0: Int): Int = if (hasPercentage) 3 else 2
|
||||
override fun getRowCount(): Int = 1
|
||||
|
||||
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any {
|
||||
return if (col == 0) {
|
||||
val view = getInflatedPlusMinusView(container)
|
||||
val maxCarbs = sp.getInt(getString(R.string.key_treatments_safety_max_carbs), 48)
|
||||
editCarbs = if (editCarbs == null) {
|
||||
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 0.0, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false)
|
||||
} else {
|
||||
val def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString())
|
||||
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, maxCarbs.toDouble(), 1.0, DecimalFormat("0"), false)
|
||||
}
|
||||
setLabelToPlusMinusView(view, getString(R.string.action_carbs))
|
||||
container.addView(view)
|
||||
view.requestFocus()
|
||||
view
|
||||
} else if (col == 1 && hasPercentage) {
|
||||
val view = getInflatedPlusMinusView(container)
|
||||
val percentage = sp.getInt(getString(R.string.key_bolus_wizard_percentage), 100)
|
||||
editPercentage = if (editPercentage == null) {
|
||||
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, percentage.toDouble(), 50.0, 150.0, 1.0, DecimalFormat("0"), false)
|
||||
} else {
|
||||
val def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
|
||||
PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50.0, 150.0, 1.0, DecimalFormat("0"), false)
|
||||
}
|
||||
setLabelToPlusMinusView(view, getString(R.string.action_percentage))
|
||||
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 {
|
||||
val action = ActionWizardPreCheck(
|
||||
SafeParse.stringToInt(editCarbs?.editText?.text.toString()),
|
||||
SafeParse.stringToInt(editPercentage?.editText?.text.toString())
|
||||
)
|
||||
rxBus.send(EventWearToMobile(action))
|
||||
showToast(this@WizardActivity, R.string.action_wizard_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 = view === `object`
|
||||
}
|
||||
}
|
|
@ -194,5 +194,6 @@
|
|||
<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>
|
||||
<string name="key_wizard_percentage" translatable="false">wizardpercentage</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="wizardpercentage"
|
||||
android:key="@string/key_wizard_percentage"
|
||||
android:summary="Percentage correction."
|
||||
android:title="@string/pref_wizard_percentage"
|
||||
app:wear_iconOff="@drawable/settings_off"
|
||||
|
|
Loading…
Reference in a new issue