ProfileSwitchActivity -> kt

This commit is contained in:
Milos Kozak 2022-04-23 11:29:21 +02:00
parent 9a90400f37
commit 59394e5260
9 changed files with 122 additions and 152 deletions

View file

@ -569,8 +569,8 @@
android:exported="true"
android:label="@string/action_insulin" />
<activity
android:name=".interaction.actions.CPPActivity"
android:label="@string/status_cpp" />
android:name=".interaction.actions.ProfileSwitchActivity"
android:label="@string/status_profile_switch" />
<activity
android:name=".interaction.actions.AcceptActivity"
android:label="@string/action_confirm"

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventWearToMobile
import info.nightscout.androidaps.interaction.WatchfaceConfigurationActivity
import info.nightscout.androidaps.interaction.actions.AcceptActivity
import info.nightscout.androidaps.interaction.actions.CPPActivity
import info.nightscout.androidaps.interaction.actions.ProfileSwitchActivity
import info.nightscout.androidaps.interaction.utils.Persistence
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.tile.ActionsTileService
@ -101,7 +101,7 @@ class DataHandlerWear @Inject constructor(
.observeOn(aapsSchedulers.io)
.subscribe { event ->
aapsLogger.debug(LTag.WEAR, "ActionProfileSwitchOpenActivity received from ${event.sourceNodeId}")
context.startActivity(Intent(context, CPPActivity::class.java).apply {
context.startActivity(Intent(context, ProfileSwitchActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtras(Bundle().also { bundle ->
bundle.putInt("percentage", event.percentage)

View file

@ -23,7 +23,7 @@ abstract class WearActivitiesModule {
@ContributesAndroidInjector abstract fun contributesAcceptActivity(): AcceptActivity
@ContributesAndroidInjector abstract fun contributesBolusActivity(): BolusActivity
@ContributesAndroidInjector abstract fun contributesCarbActivity(): CarbActivity
@ContributesAndroidInjector abstract fun contributesCPPActivity(): CPPActivity
@ContributesAndroidInjector abstract fun contributesProfileSwitchActivity(): ProfileSwitchActivity
@ContributesAndroidInjector abstract fun contributesECarbActivity(): ECarbActivity
@ContributesAndroidInjector abstract fun contributesFillActivity(): FillActivity
@ContributesAndroidInjector abstract fun contributesTempTargetActivity(): TempTargetActivity

View file

@ -35,12 +35,12 @@ class TileConfigurationActivity : WearPreferenceActivity() {
// Note that TileService updates are hard limited to once every 20 seconds.
when {
configFileName === "tile_configuration_activity" -> {
aapsLogger.info(LTag.WEAR, "onDestroy a: requestUpdate!!")
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!!")
aapsLogger.info(LTag.WEAR, "onDestroy tt: requestUpdate")
TileService.getUpdater(this).requestUpdate(TempTargetTileService::class.java)
}

View file

@ -33,10 +33,10 @@ class AcceptActivity : ViewSelectorActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dismissThread = DismissThread()
dismissThread!!.start()
dismissThread?.start()
val extras = intent.extras
message = extras!!.getString("message", "")
actionKey = extras.getString(DataLayerListenerServiceWear.KEY_ACTION_DATA, "")
message = extras?.getString("message", "") ?: ""
actionKey = extras?.getString(DataLayerListenerServiceWear.KEY_ACTION_DATA, "") ?: ""
if (message.isEmpty() || actionKey.isEmpty()) {
finish()
return
@ -117,19 +117,16 @@ class AcceptActivity : ViewSelectorActivity() {
override fun run() {
SystemClock.sleep((60 * 1000L))
synchronized(this) {
if (valid) finish()
}
synchronized(this) { if (valid) finish() }
}
}
@Synchronized override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (dismissThread != null) dismissThread!!.invalidate()
val extras = intent.extras
val msgIntent = Intent(this, AcceptActivity::class.java)
msgIntent.putExtras(extras!!)
startActivity(msgIntent)
finish()
dismissThread?.invalidate()
intent.extras?.let {
startActivity(Intent(this, AcceptActivity::class.java).apply { putExtras(it) })
finish()
}
}
}

View file

@ -1,121 +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 CPPActivity extends ViewSelectorActivity {
PlusMinusEditText editPercentage;
PlusMinusEditText editTimeshift;
int percentage = -1;
int timeshift = -25;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
percentage = extras.getInt("percentage", -1);
timeshift = extras.getInt("timeshift", -1);
if (percentage == -1 || timeshift == -25) {
finish();
return;
}
if (timeshift < 0) timeshift += 24;
setAdapter(new MyGridViewPagerAdapter());
}
@Override
protected void onPause() {
super.onPause();
finish();
}
@SuppressWarnings("deprecation")
private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) {
return 3;
}
@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 = timeshift;
if (editTimeshift != null) {
def = SafeParse.stringToDouble(editTimeshift.editText.getText().toString());
}
editTimeshift = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0d, 23d, 1d, new DecimalFormat("0"), true, true);
setLabelToPlusMinusView(view, getString(R.string.action_timeshift));
container.addView(view);
view.requestFocus();
return view;
} else if (col == 1) {
final View view = getInflatedPlusMinusView(container);
double def = percentage;
if (editPercentage != null) {
def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
}
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 30d, 250d, 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) -> {
//check if it can happen that the fragment is never created that hold data?
// (you have to swipe past them anyways - but still)
EventData.ActionProfileSwitchPreCheck ps =
new EventData.ActionProfileSwitchPreCheck(SafeParse.stringToInt(editTimeshift.editText.getText().toString()), SafeParse.stringToInt(editPercentage.editText.getText().toString()));
rxBus.send(new EventWearToMobile(ps));
showToast(CPPActivity.this, R.string.action_cpp_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,94 @@
@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.ActionProfileSwitchPreCheck
import java.text.DecimalFormat
class ProfileSwitchActivity : ViewSelectorActivity() {
var editPercentage: PlusMinusEditText? = null
var editTimeshift: PlusMinusEditText? = null
var percentage = -1
var timeshift = -25
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
percentage = intent.extras?.getInt("percentage", -1) ?: -1
timeshift = intent.extras?.getInt("timeshift", -25) ?: -25
if (percentage == -1 || timeshift == -25) {
finish()
return
}
if (timeshift < 0) timeshift += 24
setAdapter(MyGridViewPagerAdapter())
}
override fun onPause() {
super.onPause()
finish()
}
private inner class MyGridViewPagerAdapter : GridPagerAdapter() {
override fun getColumnCount(arg0: Int): Int = 3
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 = timeshift.toDouble()
if (editTimeshift != null) {
def = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString())
}
editTimeshift = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 0.0, 23.0, 1.0, DecimalFormat("0"), true, true)
setLabelToPlusMinusView(view, getString(R.string.action_timeshift))
container.addView(view)
view.requestFocus()
view
} else if (col == 1) {
val view = getInflatedPlusMinusView(container)
var def = percentage.toDouble()
if (editPercentage != null) {
def = SafeParse.stringToDouble(editPercentage?.editText?.text.toString())
}
editPercentage = PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 30.0, 250.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 {
//check if it can happen that the fragment is never created that hold data?
// (you have to swipe past them anyways - but still)
val ps = ActionProfileSwitchPreCheck(SafeParse.stringToInt(editTimeshift?.editText?.text.toString()), SafeParse.stringToInt(editPercentage?.editText?.text.toString()))
rxBus.send(EventWearToMobile(ps))
showToast(this@ProfileSwitchActivity, R.string.action_profile_switch_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`
}
}
}

View file

@ -32,7 +32,7 @@ class MainMenuActivity : MenuListActivity() {
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_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_profile_switch)))
add(MenuItem(R.drawable.ic_settings, getString(R.string.menu_settings)))
add(MenuItem(R.drawable.ic_status, getString(R.string.menu_status)))
if (sp.getBoolean(R.string.key_prime_fill, false))
@ -42,15 +42,15 @@ class MainMenuActivity : MenuListActivity() {
override fun doAction(action: String) {
when (action) {
getString(R.string.menu_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
getString(R.string.menu_resync) -> rxBus.send(EventWearToMobile(ActionResendData("Re-Sync")))
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_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) })
getString(R.string.menu_ecarb) -> startActivity(Intent(this, ECarbActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
getString(R.string.menu_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
getString(R.string.menu_resync) -> rxBus.send(EventWearToMobile(ActionResendData("Re-Sync")))
getString(R.string.status_profile_switch) -> 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_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) })
getString(R.string.menu_ecarb) -> startActivity(Intent(this, ECarbActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
}
}
}

View file

@ -98,7 +98,7 @@
<string name="action_wizard_confirmation">Calculation Requested</string>
<string name="action_fill_confirmation">Fill Requested</string>
<string name="action_ecarb_confirmation">Carbs Requested</string>
<string name="action_cpp_confirmation">CPP Requested</string>
<string name="action_profile_switch_confirmation">Profile Switch Requested</string>
<string name="action_target" comment="In temp target menu, single target value">Target</string>
<string name="action_low" comment="In temp target menu, lower value from range">Low</string>
<string name="action_high" comment="In temp target menu, higher value from range">High</string>
@ -122,7 +122,7 @@
<string name="status_pump">Pump</string>
<string name="status_loop">Loop</string>
<string name="status_cpp">CPP</string>
<string name="status_profile_switch">Profile switch</string>
<string name="status_tdd">TDD</string>
<string name="activity_carb">Carb</string>