FillActivity -> kt
This commit is contained in:
parent
5720320958
commit
d94ab441da
2 changed files with 71 additions and 94 deletions
|
@ -1,94 +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 FillActivity extends ViewSelectorActivity {
|
|
||||||
|
|
||||||
PlusMinusEditText editInsulin;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setAdapter(new MyGridViewPagerAdapter());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private class MyGridViewPagerAdapter extends GridPagerAdapter {
|
|
||||||
@Override
|
|
||||||
public int getColumnCount(int arg0) {
|
|
||||||
return 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);
|
|
||||||
double def = 0d;
|
|
||||||
if (editInsulin != null) {
|
|
||||||
def = SafeParse.stringToDouble(editInsulin.editText.getText().toString());
|
|
||||||
}
|
|
||||||
editInsulin = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 30d, 0.1d, new DecimalFormat("#0.0"), false);
|
|
||||||
setLabelToPlusMinusView(view, getString(R.string.action_insulin));
|
|
||||||
container.addView(view);
|
|
||||||
view.requestFocus();
|
|
||||||
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 fagment is never created that hold data?
|
|
||||||
// (you have to swipe past them anyways - but still)
|
|
||||||
|
|
||||||
rxBus.send(new EventWearToMobile(new EventData.ActionFillPreCheck(SafeParse.stringToDouble(editInsulin.editText.getText().toString()))));
|
|
||||||
showToast(FillActivity.this, R.string.action_fill_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 reinit?
|
|
||||||
container.removeView((View) view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isViewFromObject(View view, Object object) {
|
|
||||||
return view == object;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
@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.stringToDouble
|
||||||
|
import info.nightscout.shared.weardata.EventData.ActionFillPreCheck
|
||||||
|
import java.text.DecimalFormat
|
||||||
|
|
||||||
|
class FillActivity : ViewSelectorActivity() {
|
||||||
|
|
||||||
|
var editInsulin: PlusMinusEditText? = null
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setAdapter(MyGridViewPagerAdapter())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class MyGridViewPagerAdapter : GridPagerAdapter() {
|
||||||
|
|
||||||
|
override fun getColumnCount(arg0: Int): Int = 2
|
||||||
|
override fun getRowCount(): Int = 1
|
||||||
|
|
||||||
|
override fun instantiateItem(container: ViewGroup, row: Int, col: Int): Any {
|
||||||
|
return if (col == 0) {
|
||||||
|
val view = getInflatedPlusMinusView(container)
|
||||||
|
var def = 0.0
|
||||||
|
if (editInsulin != null) {
|
||||||
|
def = stringToDouble(editInsulin?.editText?.text.toString())
|
||||||
|
}
|
||||||
|
editInsulin = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 30.0, 0.1, DecimalFormat("#0.0"), false)
|
||||||
|
setLabelToPlusMinusView(view, getString(R.string.action_insulin))
|
||||||
|
container.addView(view)
|
||||||
|
view.requestFocus()
|
||||||
|
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)
|
||||||
|
rxBus.send(EventWearToMobile(ActionFillPreCheck(stringToDouble(editInsulin?.editText?.text.toString()))))
|
||||||
|
showToast(this@FillActivity, R.string.action_fill_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`
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue