CarbActivity -> kt

This commit is contained in:
Milos Kozak 2022-04-23 10:13:01 +02:00
parent 1306388a45
commit fc33d78418
6 changed files with 98 additions and 114 deletions

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.di
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.interaction.TileConfigurationActivity
import info.nightscout.androidaps.interaction.actions.* import info.nightscout.androidaps.interaction.actions.*
import info.nightscout.androidaps.interaction.menus.FillMenuActivity import info.nightscout.androidaps.interaction.menus.FillMenuActivity
import info.nightscout.androidaps.interaction.menus.MainMenuActivity import info.nightscout.androidaps.interaction.menus.MainMenuActivity
@ -12,6 +13,8 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity
@Suppress("unused") @Suppress("unused")
abstract class WearActivitiesModule { abstract class WearActivitiesModule {
@ContributesAndroidInjector abstract fun contributesTileConfigurationActivity(): TileConfigurationActivity
@ContributesAndroidInjector abstract fun contributesBackgroundActionActivity(): BackgroundActionActivity @ContributesAndroidInjector abstract fun contributesBackgroundActionActivity(): BackgroundActionActivity
@ContributesAndroidInjector abstract fun contributesViewSelectorActivity(): ViewSelectorActivity @ContributesAndroidInjector abstract fun contributesViewSelectorActivity(): ViewSelectorActivity

View file

@ -1,17 +1,19 @@
package info.nightscout.androidaps.interaction package info.nightscout.androidaps.interaction
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.ViewGroup import android.view.ViewGroup
import androidx.wear.tiles.TileService import androidx.wear.tiles.TileService
import preference.WearPreferenceActivity
import info.nightscout.androidaps.tile.ActionsTileService import info.nightscout.androidaps.tile.ActionsTileService
import info.nightscout.androidaps.tile.TempTargetTileService import info.nightscout.androidaps.tile.TempTargetTileService
import info.nightscout.shared.logging.AAPSLogger
var TAG = "ASTAG-config" import info.nightscout.shared.logging.LTag
import preference.WearPreferenceActivity
import javax.inject.Inject
class TileConfigurationActivity : WearPreferenceActivity() { class TileConfigurationActivity : WearPreferenceActivity() {
@Inject lateinit var aapsLogger: AAPSLogger
private var configFileName: String? = null private var configFileName: String? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -19,8 +21,8 @@ class TileConfigurationActivity : WearPreferenceActivity() {
title = "Tile" title = "Tile"
configFileName = intent.action configFileName = intent.action
val resXmlId = resources.getIdentifier(configFileName, "xml", applicationContext.packageName) val resXmlId = resources.getIdentifier(configFileName, "xml", applicationContext.packageName)
Log.d("ConfigurationActivity::onCreate --->> getIntent().getAction()", configFileName!!) aapsLogger.debug(LTag.WEAR, "ConfigurationActivity::onCreate --->> getIntent().getAction() $configFileName")
Log.d("ConfigurationActivity::onCreate --->> resXmlId", resXmlId.toString()) aapsLogger.debug(LTag.WEAR, "ConfigurationActivity::onCreate --->> resXmlId $resXmlId")
addPreferencesFromResource(resXmlId) addPreferencesFromResource(resXmlId)
val view = window.decorView as ViewGroup val view = window.decorView as ViewGroup
view.requestFocus() view.requestFocus()
@ -29,16 +31,20 @@ class TileConfigurationActivity : WearPreferenceActivity() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
// Note that TileService updates are hard limited to once every 20 seconds. // Note that TileService updates are hard limited to once every 20 seconds.
if (configFileName === "tile_configuration_activity") { when {
Log.i(TAG, "onDestroy a: requestUpdate!!") configFileName === "tile_configuration_activity" -> {
TileService.getUpdater(this) aapsLogger.info(LTag.WEAR, "onDestroy a: requestUpdate!!")
.requestUpdate(ActionsTileService::class.java) TileService.getUpdater(this).requestUpdate(ActionsTileService::class.java)
} else if (configFileName === "tile_configuration_tempt") { }
Log.i(TAG, "onDestroy tt: requestUpdate!!")
TileService.getUpdater(this) configFileName === "tile_configuration_tempt" -> {
.requestUpdate(TempTargetTileService::class.java) aapsLogger.info(LTag.WEAR, "onDestroy tt: requestUpdate!!")
} else { TileService.getUpdater(this).requestUpdate(TempTargetTileService::class.java)
Log.i(TAG, "onDestroy : NO tile service available for $configFileName") }
else -> {
aapsLogger.info(LTag.WEAR, "onDestroy : NO tile service available for $configFileName")
}
} }
} }
} }

View file

@ -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;
}
}
}

View file

@ -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`
}
}

View file

@ -32,7 +32,6 @@ class MainMenuActivity : MenuListActivity() {
add(MenuItem(R.drawable.ic_calculator, getString(R.string.menu_wizard))) 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_e_carbs, getString(R.string.menu_ecarb)))
add(MenuItem(R.drawable.ic_treatment, getString(R.string.menu_treatment))) 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_temptarget, getString(R.string.menu_tempt)))
add(MenuItem(R.drawable.ic_status, getString(R.string.status_cpp))) add(MenuItem(R.drawable.ic_status, getString(R.string.status_cpp)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.menu_settings))) 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.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_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_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_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_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) }) getString(R.string.menu_prime_fill) -> startActivity(Intent(this, FillMenuActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })

View file

@ -172,6 +172,7 @@ public abstract class BaseWatchFace extends WatchFace {
.toObservable(EventData.Status.class) .toObservable(EventData.Status.class)
.observeOn(aapsSchedulers.getMain()) .observeOn(aapsSchedulers.getMain())
.subscribe(event -> { .subscribe(event -> {
status = event;
// this event is received as last batch of data // this event is received as last batch of data
if (isSimpleUi()) { if (isSimpleUi()) {
if (needUpdate()) { if (needUpdate()) {