Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Profile Switch Negative Timeshift and string for Wear Loop State #3784

Merged
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Constants {
// Circadian Percentage Profile
const val CPP_MIN_PERCENTAGE = 30
const val CPP_MAX_PERCENTAGE = 250
const val CPP_MIN_TIMESHIFT = -6
const val CPP_MIN_TIMESHIFT = -23
const val CPP_MAX_TIMESHIFT = 23
const val MAX_PROFILE_SWITCH_DURATION = (7 * 24 * 60).toDouble()// [min] ~ 7 days

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,11 @@ class DataHandlerMobile @Inject constructor(
if (command.percentage < Constants.CPP_MIN_PERCENTAGE || command.percentage > Constants.CPP_MAX_PERCENTAGE) {
sendError(rh.gs(app.aaps.core.ui.R.string.valueoutofrange, "Profile-Percentage"))
}
if (command.timeShift < 0 || command.timeShift > 23) {
if (command.timeShift < Constants.CPP_MIN_TIMESHIFT || command.timeShift > Constants.CPP_MAX_TIMESHIFT) {
sendError(rh.gs(app.aaps.core.ui.R.string.valueoutofrange, "Profile-Timeshift"))
}
val message = rh.gs(R.string.profile_message, command.timeShift, command.percentage)
val profileName = profileFunction.getOriginalProfileName()
val message = rh.gs(R.string.profile_message, profileName, command.timeShift, command.percentage)
rxBus.send(
EventMobileToWear(
EventData.ConfirmAction(
Expand Down Expand Up @@ -1763,7 +1764,7 @@ class DataHandlerMobile @Inject constructor(
//check for validity
if (command.percentage < Constants.CPP_MIN_PERCENTAGE || command.percentage > Constants.CPP_MAX_PERCENTAGE)
return
if (command.timeShift < 0 || command.timeShift > 23)
if (command.timeShift < Constants.CPP_MIN_TIMESHIFT || command.timeShift > Constants.CPP_MAX_TIMESHIFT)
return
profileFunction.getProfile() ?: return
//send profile to pump
Expand Down
2 changes: 1 addition & 1 deletion plugins/sync/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<string name="grams_short">g</string>
<string name="hour_short">h</string>
<string name="no_active_profile">No active profile switch!</string>
<string name="profile_message">Profile:\n\nTimeshift: %1$d\nPercentage: %2$d%%\"</string>
<string name="profile_message">Profile: %1$s\nTimeshift: %2$d h\nPercentage: %3$d%%</string>
<string name="target_only_aps_mode">Targets only apply in APS mode!</string>
<string name="no_history">No history data!</string>
<string name="temp_target">Temp Target</string>
Expand Down
1 change: 1 addition & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ dependencies {
implementation(project(":core:interfaces"))
implementation(project(":core:keys"))
implementation(project(":core:ui"))
implementation(project(":core:data"))

implementation(libs.androidx.appcompat)
implementation(libs.androidx.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LoopStateTimedActivity : ViewSelectorActivity() {
val title = if (isHours)
getString(R.string.action_duration_h)
else
getString(R.string.action_duration)
getString(app.aaps.core.ui.R.string.duration_min_label)
editDuration = PlusMinusEditText(
viewAdapter,
minValue.toDouble(), minValue.toDouble(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import app.aaps.core.data.configuration.Constants
import app.aaps.core.interfaces.rx.events.EventWearToMobile
import app.aaps.core.interfaces.rx.weardata.EventData.ActionProfileSwitchPreCheck
import app.aaps.core.interfaces.utils.SafeParse
Expand All @@ -30,7 +31,6 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
finish()
return
}
if (timeshift < 0) timeshift += 24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be afraid to remove this. it makes timeshit always positive value. I'm not sure what will happen elsewhere ....

Copy link
Contributor Author

@olorinmaia olorinmaia Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback!

Profile switch in wear checks phone what current timeshift and percentage is. So if f.ex. a - 2h timeshift and 120% profile is set in phone it automatically preselect these values in wear app when using wear profile switch button.

Problem is when a negative timeshift is set on phone, with this line of code, wear app adds +24h to the -2h from phone and displays +22h instead which is wrong.

I don't know if there is any way to avoid this except removing it, limits are set to -23/+23 so user can't enter higher or lower?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (timeshift < 0) timeshift += 24
This was ensuring the timeshift remained in a 0-23 range, but it's no longer needed if we go for aligning phone/wear range.

setAdapter(MyGridViewPagerAdapter())
}

Expand All @@ -48,8 +48,8 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
0 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var initValue = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString(), timeshift.toDouble())
editTimeshift = PlusMinusEditText(viewAdapter, initValue, 0.0, 23.0, 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true)
val initValue = SafeParse.stringToDouble(editTimeshift?.editText?.text.toString(), timeshift.toDouble())
editTimeshift = PlusMinusEditText(viewAdapter, initValue, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), true, getString(R.string.action_timeshift), true)
container.addView(view)
view.requestFocus()
view
Expand All @@ -58,8 +58,8 @@ class ProfileSwitchActivity : ViewSelectorActivity() {
1 -> {
val viewAdapter = EditPlusMinusViewAdapter.getViewAdapter(sp, applicationContext, container, false)
val view = viewAdapter.root
var initValue = SafeParse.stringToDouble(editPercentage?.editText?.text.toString(), percentage.toDouble())
editPercentage = PlusMinusEditText(viewAdapter, initValue, 30.0, 250.0, 1.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
val initValue = SafeParse.stringToDouble(editPercentage?.editText?.text.toString(), percentage.toDouble())
editPercentage = PlusMinusEditText(viewAdapter, initValue, 30.0, 250.0, 5.0, DecimalFormat("0"), false, getString(R.string.action_percentage))
container.addView(view)
view
}
Expand Down