From 92077dcb6a38933172309a0d2f968d309d14f3cb Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 17 Aug 2017 17:03:08 +0200 Subject: [PATCH] Show profile on tap in Treatments->ProfileSwitch --- .../fragments/ProfileViewerDialog.java | 113 ++++++++++++++++++ .../TreatmentsProfileSwitchFragment.java | 14 +++ .../res/layout/nsprofileviewer_fragment.xml | 51 +++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java new file mode 100644 index 0000000000..0572bc936f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -0,0 +1,113 @@ +package info.nightscout.androidaps.plugins.Treatments.fragments; + +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; +import info.nightscout.utils.DateUtil; +import info.nightscout.utils.DecimalFormatter; + +/** + * Created by adrian on 17/08/17. + */ + +public class ProfileViewerDialog extends DialogFragment { + + private long time; + + private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class); + + private static TextView noProfile; + private static TextView units; + private static TextView dia; + private static TextView activeProfile; + private static TextView ic; + private static TextView isf; + private static TextView basal; + private static TextView target; + private static View dateDelimiter; + private static LinearLayout dateLayout; + private static TextView dateTextView; + private static Button refreshButton; + + static ProfileViewerDialog newInstance(long time) { + ProfileViewerDialog dialog = new ProfileViewerDialog(); + + Bundle args = new Bundle(); + args.putLong("time", time); + dialog.setArguments(args); + + return dialog; + } + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + time = getArguments().getLong("time"); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View layout = inflater.inflate(R.layout.nsprofileviewer_fragment, container, false); + + noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile); + units = (TextView) layout.findViewById(R.id.profileview_units); + dia = (TextView) layout.findViewById(R.id.profileview_dia); + activeProfile = (TextView) layout.findViewById(R.id.profileview_activeprofile); + ic = (TextView) layout.findViewById(R.id.profileview_ic); + isf = (TextView) layout.findViewById(R.id.profileview_isf); + basal = (TextView) layout.findViewById(R.id.profileview_basal); + target = (TextView) layout.findViewById(R.id.profileview_target); + refreshButton = (Button) layout.findViewById(R.id.profileview_reload); + refreshButton.setVisibility(View.GONE); + dateDelimiter = layout.findViewById(R.id.profileview_datedelimiter); + dateDelimiter.setVisibility(View.VISIBLE); + dateLayout = (LinearLayout) layout.findViewById(R.id.profileview_datelayout); + dateLayout.setVisibility(View.VISIBLE); + dateTextView = (TextView) layout.findViewById(R.id.profileview_date); + + setContent(); + return layout; + } + + private void setContent() { + Profile profile = null; + ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time); + if(profileSwitch!=null){ + profile = profileSwitch.getProfileObject(); + } + if (profile != null) { + noProfile.setVisibility(View.GONE); + units.setText(profile.getUnits()); + dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h"); + activeProfile.setText(profileSwitch.profileName); + dateTextView.setText(DateUtil.dateAndTimeString(profileSwitch.date)); + ic.setText(profile.getIcList()); + isf.setText(profile.getIsfList()); + basal.setText(profile.getBasalList()); + target.setText(profile.getTargetList()); + } else { + noProfile.setVisibility(View.VISIBLE); + } + } + + + + + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java index e5c1134787..15fd3513e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -7,6 +7,7 @@ import android.content.Intent; import android.graphics.Paint; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; @@ -84,6 +85,9 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen else holder.date.setTextColor(holder.duration.getCurrentTextColor()); holder.remove.setTag(profileSwitch); + holder.name.setTag(profileSwitch); + holder.date.setTag(profileSwitch); + } @Override @@ -116,6 +120,9 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen remove = (TextView) itemView.findViewById(R.id.profileswitch_remove); remove.setOnClickListener(this); remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + name.setOnClickListener(this); + date.setOnClickListener(this); + } @Override @@ -134,6 +141,13 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen } }); break; + case R.id.profileswitch_date: + case R.id.profileswitch_name: + long time = ((ProfileSwitch)v.getTag()).date; + ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(time); + FragmentManager manager = getFragmentManager(); + pvd.show(manager, "ProfileViewDialog"); + break; } } } diff --git a/app/src/main/res/layout/nsprofileviewer_fragment.xml b/app/src/main/res/layout/nsprofileviewer_fragment.xml index e2c48fb79f..f0e385e86b 100644 --- a/app/src/main/res/layout/nsprofileviewer_fragment.xml +++ b/app/src/main/res/layout/nsprofileviewer_fragment.xml @@ -35,7 +35,7 @@ android:layout_weight="2" android:gravity="end" android:paddingRight="5dp" - android:text="@string/nsprofileview_activeprofile_label" + android:text="@string/careportal_newnstreatment_profile_label" android:textSize="14sp" /> + + + + + + + + + + + + Ultra-Rapid Oref "DIA of %s too short - using %s instead!" ACTIVATE PROFILE + Date