Merge pull request #372 from MilosKozak/profile-switch-viewer

Show profile on tap in Treatments->ProfileSwitch
This commit is contained in:
Milos Kozak 2017-08-17 21:20:06 +02:00 committed by GitHub
commit a850e3c31c
4 changed files with 178 additions and 1 deletions

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -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" />
<TextView
@ -60,6 +60,55 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter"
android:id="@+id/profileview_datedelimiter"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/profileview_datelayout"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/date"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/profileview_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"

View file

@ -699,6 +699,7 @@
<string name="ultrarapid_oref">Ultra-Rapid Oref</string>
<string name="dia_too_short" formatted="false">"DIA of %s too short - using %s instead!"</string>
<string name="activate_profile">ACTIVATE PROFILE</string>
<string name="date">Date</string>
</resources>