Instead of computing name in overview fragment add function

ProfileFunctions.getInstance().getProfileNameWithDuration()

to be called
This commit is contained in:
andreas 2019-11-05 15:43:11 +01:00 committed by adorfler
parent 70172bf8e4
commit 2044fe6860
2 changed files with 18 additions and 20 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.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP;
import io.reactivex.disposables.CompositeDisposable;
@ -75,35 +76,42 @@ public class ProfileFunctions {
}
public String getProfileName() {
return getProfileName(System.currentTimeMillis());
return getProfileName(System.currentTimeMillis(), true, false);
}
public String getProfileName(boolean customized) {
return getProfileName(System.currentTimeMillis(), customized);
return getProfileName(System.currentTimeMillis(), customized, false);
}
public String getProfileName(long time) {
return getProfileName(time, true);
public String getProfileNameWithDuration() {
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();
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time);
if (profileSwitch != null) {
if (profileSwitch.profileJson != null) {
return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
profileName = customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName;
} else {
ProfileStore profileStore = activeProfile.getProfile();
if (profileStore != null) {
Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName);
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) {
@ -176,7 +184,7 @@ public class ProfileFunctions {
profileSwitch = new ProfileSwitch();
profileSwitch.date = System.currentTimeMillis();
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.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
profileSwitch.durationInMinutes = duration;

View file

@ -58,7 +58,6 @@ import info.nightscout.androidaps.data.QuickWizardEntry;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
@ -77,7 +76,6 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
@ -1225,18 +1223,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
extendedBolusView.setVisibility(View.VISIBLE);
}
activeProfileView.setText(ProfileFunctions.getInstance().getProfileName());
activeProfileView.setText(ProfileFunctions.getInstance().getProfileNameWithDuration());
if (profile.getPercentage() != 100 || profile.getTimeshift() != 0) {
activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonWarning));
activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin();
ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(System.currentTimeMillis());
if (profileSwitch != null) {
if (profileSwitch.profileJson != null && profileSwitch.durationInMinutes != 0) {
activeProfileView.setText(ProfileFunctions.getInstance().getProfileName() + DateUtil.untilString(profileSwitch.originalEnd()));
}
}
} else {
activeProfileView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault));
activeProfileView.setTextColor(MainApp.gc(R.color.ribbonTextDefault));