Merge pull request #2178 from 2flea/dev

Countdown time for temporary PS in overview
This commit is contained in:
Milos Kozak 2019-11-14 11:39:01 +01:00 committed by GitHub
commit 3e5206b4cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
@ -75,35 +76,42 @@ public class ProfileFunctions {
} }
public String getProfileName() { public String getProfileName() {
return getProfileName(System.currentTimeMillis()); return getProfileName(System.currentTimeMillis(), true, false);
} }
public String getProfileName(boolean customized) { public String getProfileName(boolean customized) {
return getProfileName(System.currentTimeMillis(), customized); return getProfileName(System.currentTimeMillis(), customized, false);
} }
public String getProfileName(long time) { public String getProfileNameWithDuration() {
return getProfileName(time, true); return getProfileName(System.currentTimeMillis(), true, true);
} }
public String getProfileName(long time, boolean customized) { public String getProfileName(long time, boolean customized, boolean showRemainingTime) {
String profileName = MainApp.gs(R.string.noprofileselected);
TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin(); TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin();
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface(); ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time);
if (profileSwitch != null) { if (profileSwitch != null) {
if (profileSwitch.profileJson != null) { if (profileSwitch.profileJson != null) {
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName; profileName = customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
} else { } else {
ProfileStore profileStore = activeProfile.getProfile(); ProfileStore profileStore = activeProfile.getProfile();
if (profileStore != null) { if (profileStore != null) {
Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName); Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName);
if (profile != null) if (profile != null)
return profileSwitch.profileName; profileName = profileSwitch.profileName;
} }
} }
if (showRemainingTime && profileSwitch.durationInMinutes != 0) {
profileName += DateUtil.untilString(profileSwitch.originalEnd());
}
return profileName;
} }
return MainApp.gs(R.string.noprofileselected); return profileName;
} }
public boolean isProfileValid(String from) { public boolean isProfileValid(String from) {
@ -176,7 +184,7 @@ public class ProfileFunctions {
profileSwitch = new ProfileSwitch(); profileSwitch = new ProfileSwitch();
profileSwitch.date = System.currentTimeMillis(); profileSwitch.date = System.currentTimeMillis();
profileSwitch.source = Source.USER; profileSwitch.source = Source.USER;
profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false); profileSwitch.profileName = getInstance().getProfileName(System.currentTimeMillis(), false, false);
profileSwitch.profileJson = getInstance().getProfile().getData().toString(); profileSwitch.profileJson = getInstance().getProfile().getData().toString();
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName(); profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
profileSwitch.durationInMinutes = duration; profileSwitch.durationInMinutes = duration;

View file

@ -1223,7 +1223,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
extendedBolusView.setVisibility(View.VISIBLE); extendedBolusView.setVisibility(View.VISIBLE);
} }
activeProfileView.setText(ProfileFunctions.getInstance().getProfileName()); activeProfileView.setText(ProfileFunctions.getInstance().getProfileNameWithDuration());
if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) { if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) {
activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning)); activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));