CarbActivity -> kt
This commit is contained in:
parent
1306388a45
commit
fc33d78418
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.di
|
|||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.interaction.TileConfigurationActivity
|
||||
import info.nightscout.androidaps.interaction.actions.*
|
||||
import info.nightscout.androidaps.interaction.menus.FillMenuActivity
|
||||
import info.nightscout.androidaps.interaction.menus.MainMenuActivity
|
||||
|
@ -12,6 +13,8 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity
|
|||
@Suppress("unused")
|
||||
abstract class WearActivitiesModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesTileConfigurationActivity(): TileConfigurationActivity
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesBackgroundActionActivity(): BackgroundActionActivity
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesViewSelectorActivity(): ViewSelectorActivity
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
package info.nightscout.androidaps.interaction
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.ViewGroup
|
||||
import androidx.wear.tiles.TileService
|
||||
import preference.WearPreferenceActivity
|
||||
import info.nightscout.androidaps.tile.ActionsTileService
|
||||
import info.nightscout.androidaps.tile.TempTargetTileService
|
||||
|
||||
var TAG = "ASTAG-config"
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.logging.LTag
|
||||
import preference.WearPreferenceActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class TileConfigurationActivity : WearPreferenceActivity() {
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
private var configFileName: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -19,8 +21,8 @@ class TileConfigurationActivity : WearPreferenceActivity() {
|
|||
title = "Tile"
|
||||
configFileName = intent.action
|
||||
val resXmlId = resources.getIdentifier(configFileName, "xml", applicationContext.packageName)
|
||||
Log.d("ConfigurationActivity::onCreate --->> getIntent().getAction()", configFileName!!)
|
||||
Log.d("ConfigurationActivity::onCreate --->> resXmlId", resXmlId.toString())
|
||||
aapsLogger.debug(LTag.WEAR, "ConfigurationActivity::onCreate --->> getIntent().getAction() $configFileName")
|
||||
aapsLogger.debug(LTag.WEAR, "ConfigurationActivity::onCreate --->> resXmlId $resXmlId")
|
||||
addPreferencesFromResource(resXmlId)
|
||||
val view = window.decorView as ViewGroup
|
||||
view.requestFocus()
|
||||
|
@ -29,16 +31,20 @@ class TileConfigurationActivity : WearPreferenceActivity() {
|
|||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
// Note that TileService updates are hard limited to once every 20 seconds.
|
||||
if (configFileName === "tile_configuration_activity") {
|
||||
Log.i(TAG, "onDestroy a: requestUpdate!!")
|
||||
TileService.getUpdater(this)
|
||||
.requestUpdate(ActionsTileService::class.java)
|
||||
} else if (configFileName === "tile_configuration_tempt") {
|
||||
Log.i(TAG, "onDestroy tt: requestUpdate!!")
|
||||
TileService.getUpdater(this)
|
||||
.requestUpdate(TempTargetTileService::class.java)
|
||||
} else {
|
||||
Log.i(TAG, "onDestroy : NO tile service available for $configFileName")
|
||||
when {
|
||||
configFileName === "tile_configuration_activity" -> {
|
||||
aapsLogger.info(LTag.WEAR, "onDestroy a: requestUpdate!!")
|
||||
TileService.getUpdater(this).requestUpdate(ActionsTileService::class.java)
|
||||
}
|
||||
|
||||
configFileName === "tile_configuration_tempt" -> {
|
||||
aapsLogger.info(LTag.WEAR, "onDestroy tt: requestUpdate!!")
|
||||
TileService.getUpdater(this).requestUpdate(TempTargetTileService::class.java)
|
||||
}
|
||||
|
||||
else -> {
|
||||
aapsLogger.info(LTag.WEAR, "onDestroy : NO tile service available for $configFileName")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +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;
|
||||
|
||||
public class CarbActivity extends ViewSelectorActivity {
|
||||
|
||||
PlusMinusEditText editCarbs;
|
||||
int maxCarbs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setAdapter(new MyGridViewPagerAdapter());
|
||||
maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 48);
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
final View view;
|
||||
if (col == 0) {
|
||||
view = getInflatedPlusMinusView(container);
|
||||
double def = 0;
|
||||
if (editCarbs != null) {
|
||||
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"), true);
|
||||
setLabelToPlusMinusView(view, getString(R.string.action_carbs));
|
||||
container.addView(view);
|
||||
view.requestFocus();
|
||||
} else {
|
||||
view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
|
||||
final ImageView confirmButton = view.findViewById(R.id.confirmbutton);
|
||||
confirmButton.setOnClickListener((View v) -> {
|
||||
// With start time 0 and duration 0
|
||||
EventData.ActionECarbsPreCheck bolus =
|
||||
new EventData.ActionECarbsPreCheck(
|
||||
SafeParse.stringToInt(editCarbs.editText.getText().toString()),
|
||||
0,
|
||||
0
|
||||
);
|
||||
rxBus.send(new EventWearToMobile(bolus));
|
||||
showToast(CarbActivity.this, R.string.action_ecarb_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,72 @@
|
|||
@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.ActionECarbsPreCheck
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class CarbActivity : ViewSelectorActivity() {
|
||||
|
||||
var editCarbs: 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 {
|
||||
val view: View
|
||||
if (col == 0) {
|
||||
view = getInflatedPlusMinusView(container)
|
||||
var def = 0.0
|
||||
if (editCarbs != null) {
|
||||
def = SafeParse.stringToDouble(editCarbs?.editText?.text.toString())
|
||||
}
|
||||
val maxCarbs = sp.getInt(getString(R.string.key_treatmentssafety_maxcarbs), 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)
|
||||
view.requestFocus()
|
||||
} else {
|
||||
view = LayoutInflater.from(applicationContext).inflate(R.layout.action_send_item, container, false)
|
||||
val confirmButton = view.findViewById<ImageView>(R.id.confirmbutton)
|
||||
confirmButton.setOnClickListener {
|
||||
// With start time 0 and duration 0
|
||||
val bolus = ActionECarbsPreCheck(SafeParse.stringToInt(editCarbs?.editText?.text.toString()), 0, 0)
|
||||
rxBus.send(EventWearToMobile(bolus))
|
||||
showToast(this@CarbActivity, R.string.action_ecarb_confirmation)
|
||||
finishAffinity()
|
||||
}
|
||||
container.addView(view)
|
||||
}
|
||||
return 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`
|
||||
}
|
||||
}
|
|
@ -32,7 +32,6 @@ class MainMenuActivity : MenuListActivity() {
|
|||
add(MenuItem(R.drawable.ic_calculator, getString(R.string.menu_wizard)))
|
||||
add(MenuItem(R.drawable.ic_e_carbs, getString(R.string.menu_ecarb)))
|
||||
add(MenuItem(R.drawable.ic_treatment, getString(R.string.menu_treatment)))
|
||||
add(MenuItem(R.drawable.ic_bolus, getString(R.string.menu_bolus)))
|
||||
add(MenuItem(R.drawable.ic_temptarget, getString(R.string.menu_tempt)))
|
||||
add(MenuItem(R.drawable.ic_status, getString(R.string.status_cpp)))
|
||||
add(MenuItem(R.drawable.ic_settings, getString(R.string.menu_settings)))
|
||||
|
@ -49,7 +48,6 @@ class MainMenuActivity : MenuListActivity() {
|
|||
getString(R.string.status_cpp) -> rxBus.send(EventWearToMobile(EventData.ActionProfileSwitchSendInitialData(System.currentTimeMillis())))
|
||||
getString(R.string.menu_tempt) -> startActivity(Intent(this, TempTargetActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
getString(R.string.menu_treatment) -> startActivity(Intent(this, TreatmentActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
getString(R.string.menu_bolus) -> startActivity(Intent(this, BolusActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
getString(R.string.menu_wizard) -> startActivity(Intent(this, WizardActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
getString(R.string.menu_status) -> startActivity(Intent(this, StatusMenuActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
getString(R.string.menu_prime_fill) -> startActivity(Intent(this, FillMenuActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
|
||||
|
|
|
@ -172,6 +172,7 @@ public abstract class BaseWatchFace extends WatchFace {
|
|||
.toObservable(EventData.Status.class)
|
||||
.observeOn(aapsSchedulers.getMain())
|
||||
.subscribe(event -> {
|
||||
status = event;
|
||||
// this event is received as last batch of data
|
||||
if (isSimpleUi()) {
|
||||
if (needUpdate()) {
|
||||
|
|
Loading…
Reference in a new issue