tabs in local profile

This commit is contained in:
Milos Kozak 2019-11-28 21:58:07 +01:00
parent a000611f11
commit 8a75d4f6b9
10 changed files with 265 additions and 33 deletions

View file

@ -52,7 +52,7 @@ public class InsulinFragment extends Fragment {
private void updateGUI() {
insulinName.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getFriendlyName());
insulinComment.setText(ConfigBuilderPlugin.getPlugin().getActiveInsulin().getComment());
insulinDia.setText(MainApp.gs(R.string.dia) + " " + ConfigBuilderPlugin.getPlugin().getActiveInsulin().getDia() + "h");
insulinDia.setText(MainApp.gs(R.string.dia) + ": " + ConfigBuilderPlugin.getPlugin().getActiveInsulin().getDia() + "h");
insulinGraph.show(ConfigBuilderPlugin.getPlugin().getActiveInsulin());
}

View file

@ -60,6 +60,30 @@ class LocalProfileFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
build()
// activate DIA tab
processVisibilityOnClick(dia_tab)
localprofile_dia_placeholder.visibility = View.VISIBLE
// setup listeners
dia_tab.setOnClickListener {
processVisibilityOnClick(it)
localprofile_dia_placeholder.visibility = View.VISIBLE
}
ic_tab.setOnClickListener {
processVisibilityOnClick(it)
localprofile_ic.visibility = View.VISIBLE
}
isf_tab.setOnClickListener {
processVisibilityOnClick(it)
localprofile_isf.visibility = View.VISIBLE
}
basal_tab.setOnClickListener {
processVisibilityOnClick(it)
localprofile_basal.visibility = View.VISIBLE
}
target_tab.setOnClickListener {
processVisibilityOnClick(it)
localprofile_target.visibility = View.VISIBLE
}
}
fun build() {
@ -68,14 +92,14 @@ class LocalProfileFragment : Fragment() {
localprofile_name.setText(LocalProfilePlugin.currentProfile().name)
localprofile_dia.setParams(LocalProfilePlugin.currentProfile().dia, HardLimits.MINDIA, HardLimits.MAXDIA, 0.1, DecimalFormat("0.0"), false, localprofile_save, textWatch)
TimeListEdit(context, view, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.currentProfile().ic, null, HardLimits.MINIC, HardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save)
TimeListEdit(context, view, R.id.localprofile_ic, MainApp.gs(R.string.nsprofileview_ic_label), LocalProfilePlugin.currentProfile().ic, null, HardLimits.MINIC, HardLimits.MAXIC, 0.1, DecimalFormat("0.0"), save)
basalView = TimeListEdit(context, view, R.id.localprofile_basal, MainApp.gs(R.string.nsprofileview_basal_label) + ": " + sumLabel(), LocalProfilePlugin.currentProfile().basal, null, pumpDescription.basalMinimumRate, 10.0, 0.01, DecimalFormat("0.00"), save)
if (units == Constants.MGDL) {
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.currentProfile().isf, null, HardLimits.MINISF, HardLimits.MAXISF, 1.0, DecimalFormat("0"), save)
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save)
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label), LocalProfilePlugin.currentProfile().isf, null, HardLimits.MINISF, HardLimits.MAXISF, 1.0, DecimalFormat("0"), save)
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label), LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), 1.0, DecimalFormat("0"), save)
} else {
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(HardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
TimeListEdit(context, view, R.id.localprofile_isf, MainApp.gs(R.string.nsprofileview_isf_label), LocalProfilePlugin.currentProfile().isf, null, Profile.fromMgdlToUnits(HardLimits.MINISF, Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.MAXISF, Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
TimeListEdit(context, view, R.id.localprofile_target, MainApp.gs(R.string.nsprofileview_target_label), LocalProfilePlugin.currentProfile().targetLow, LocalProfilePlugin.currentProfile().targetHigh, Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[0].toDouble(), Constants.MMOL), Profile.fromMgdlToUnits(HardLimits.VERY_HARD_LIMIT_TARGET_BG[1].toDouble(), Constants.MMOL), 0.1, DecimalFormat("0.0"), save)
}
// Spinner
@ -183,11 +207,11 @@ class LocalProfileFragment : Fragment() {
}
fun updateGUI() {
if (invalidprofile == null) return
if (localprofile_profileswitch == null) return
val isValid = LocalProfilePlugin.isValidEditState()
val isEdited = LocalProfilePlugin.isEdited
if (isValid) {
invalidprofile.visibility = View.GONE //show invalid profile
this.view?.setBackgroundColor(MainApp.gc(R.color.ok_background))
if (isEdited) {
//edited profile -> save first
@ -198,7 +222,7 @@ class LocalProfileFragment : Fragment() {
localprofile_save.visibility = View.GONE
}
} else {
invalidprofile.visibility = View.VISIBLE
this.view?.setBackgroundColor(MainApp.gc(R.color.error_background))
localprofile_profileswitch.visibility = View.GONE
localprofile_save.visibility = View.GONE //don't save an invalid profile
}
@ -210,4 +234,19 @@ class LocalProfileFragment : Fragment() {
localprofile_reset.visibility = View.GONE
}
}
private fun processVisibilityOnClick(selected: View) {
dia_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
ic_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
isf_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
basal_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
target_tab.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
selected.setBackgroundColor(MainApp.gc(R.color.tabBgColorSelected))
localprofile_dia_placeholder.visibility = View.GONE
localprofile_ic.visibility = View.GONE
localprofile_isf.visibility = View.GONE
localprofile_basal.visibility = View.GONE
localprofile_target.visibility = View.GONE
}
}

View file

@ -94,9 +94,13 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
this.initialize(context);
}
protected void inflate(Context context) {
LayoutInflater.from(context).inflate(R.layout.number_picker_layout, this, true);
}
private void initialize(Context context) {
// set layout view
LayoutInflater.from(context).inflate(R.layout.number_picker_layout, this, true);
inflate(context);
// init ui components
minusButton = findViewById(R.id.decrement);

View file

@ -0,0 +1,46 @@
package info.nightscout.androidaps.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.NumberFormat;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/**
* Created by mike on 28.06.2016.
*/
public class NumberPickerVertical extends NumberPicker {
private static Logger log = LoggerFactory.getLogger(NumberPickerVertical.class);
public NumberPickerVertical(Context context) {
super(context);
}
public NumberPickerVertical(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void inflate(Context context) {
LayoutInflater.from(context).inflate(R.layout.number_picker_layout_vertical, this, true);
}
}

View file

@ -84,11 +84,11 @@ public class TimeListEdit {
textlabel = new TextView(context);
textlabel.setText(label);
textlabel.setGravity(Gravity.START);
textlabel.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
llp.setMargins(0, 5, 0, 5);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
//textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
layout.addView(textlabel);
@ -119,7 +119,8 @@ public class TimeListEdit {
private void inflateRow(final int position) {
LayoutInflater inflater = LayoutInflater.from(context);
View childView = intervals[position] = inflater.inflate(R.layout.timelistedit_element, layout, false);
int resource = data2 == null ? R.layout.timelistedit_element : R.layout.timelistedit_element_vertical;
View childView = intervals[position] = inflater.inflate(resource, layout, false);
spinners[position] = new SpinnerHelper(childView.findViewById(R.id.timelistedit_time));
numberPickers1[position] = childView.findViewById(R.id.timelistedit_edit1);
numberPickers2[position] = childView.findViewById(R.id.timelistedit_edit2);

View file

@ -9,16 +9,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/invalidprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/invalidprofile"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_light"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -126,8 +116,71 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView
android:id="@+id/dia_tab"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/dia_short"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/ic_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/ic_short"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/isf_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/isf_short"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/basal_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/basal_short"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/target_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="@string/target_short"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/localprofile_dia_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
@ -135,15 +188,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="@string/dia"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<info.nightscout.androidaps.utils.NumberPicker
android:id="@+id/localprofile_dia"
android:layout_width="130dp"
@ -156,7 +204,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/hours"
android:textAppearance="?android:attr/textAppearanceSmall"/>
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

View file

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="60dp"
android:layout_height="100dp"
android:background="@drawable/background_darkgray"
android:orientation="vertical">
<Button
android:id="@+id/increment"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@null"
android:padding="0dp"
android:text="+"
android:textColor="@color/mdtp_white"
android:textSize="25sp" />
<EditText
android:id="@+id/display"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/border_gray"
android:gravity="center"
android:imeOptions="actionDone"
android:inputType="number"
android:text="1"
android:textColor="@android:color/black" />
<Button
android:id="@+id/decrement"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@null"
android:padding="0dp"
android:text="—"
android:textColor="@color/mdtp_white"
android:textStyle="bold" />
</LinearLayout>

View file

@ -0,0 +1,49 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<Spinner
android:id="@+id/timelistedit_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:minWidth="80dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<info.nightscout.androidaps.utils.NumberPickerVertical
android:id="@+id/timelistedit_edit1"
android:layout_width="60dp"
android:layout_height="100dp"
android:layout_marginRight="5dp" />
<info.nightscout.androidaps.utils.NumberPickerVertical
android:id="@+id/timelistedit_edit2"
android:layout_width="60dp"
android:layout_height="100dp" />
</LinearLayout>
<ImageView
android:id="@+id/timelistedit_add"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:src="@drawable/add" />
<ImageView
android:id="@+id/timelistedit_remove"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:src="@drawable/remove" />
</LinearLayout>

View file

@ -28,6 +28,8 @@
<color name="graphgrid">#757575</color>
<color name="colorLightGray">#d8d8d8</color>
<color name="warning">#ff1a1a</color>
<color name="error_background">#66FC0000</color>
<color name="ok_background">#323232</color>
<color name="defaultbackground">#424242</color>
<color name="defaulttext">#BBBBBB</color>

View file

@ -414,7 +414,7 @@
<string name="units">Units</string>
<string name="mgdl">mg/dl</string>
<string name="mmol">mmol/l</string>
<string name="dia">DIA:</string>
<string name="dia">DIA</string>
<string name="target_range">Target range:</string>
<string name="prefs_range_title">Range for Visualization</string>
<string name="prefs_range_summary">High and low mark for the charts in Overview and Smartwatch</string>
@ -1645,5 +1645,9 @@
<string name="key_high_mark" translatable="false">high_mark</string>
<string name="key_wear_detailediob" translatable="false">wear_detailediob</string>
<string name="key_wear_showbgi" translatable="false">wear_showbgi</string>
<string name="dia_short">DIA</string>
<string name="ic_short">IC</string>
<string name="isf_short">ISF</string>
<string name="target_short">TARG</string>
</resources>