Introduce LayoutBuilder
This commit is contained in:
parent
ba0625b03f
commit
e1523ee82d
6 changed files with 33 additions and 9 deletions
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputBg;
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
||||||
|
@ -50,10 +51,11 @@ public class ActionStartTempTarget extends Action {
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout root) {
|
public void generateDialog(LinearLayout root) {
|
||||||
int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol;
|
int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol;
|
||||||
Label labelBg = new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value);
|
|
||||||
labelBg.generateDialog(root);
|
new LayoutBuilder()
|
||||||
Label labelDuration = new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration);
|
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value))
|
||||||
labelDuration.generateDialog(root);
|
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration))
|
||||||
|
.build(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.plugins.general.automation.elements;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
public class Element {
|
public class Element {
|
||||||
public void generateDialog(LinearLayout root) { }
|
public void addToLayout(LinearLayout root) { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class InputBg extends Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout root) {
|
public void addToLayout(LinearLayout root) {
|
||||||
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
||||||
numberPicker.setParams(0d, minValue, maxValue, step, decimalFormat, false, textWatcher);
|
numberPicker.setParams(0d, minValue, maxValue, step, decimalFormat, false, textWatcher);
|
||||||
numberPicker.setValue(value);
|
numberPicker.setValue(value);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class InputDuration extends Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout root) {
|
public void addToLayout(LinearLayout root) {
|
||||||
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
||||||
if (unit.equals(TimeUnit.MINUTES)) {
|
if (unit.equals(TimeUnit.MINUTES)) {
|
||||||
// Minutes
|
// Minutes
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class Label extends Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout root) {
|
public void addToLayout(LinearLayout root) {
|
||||||
// container layout
|
// container layout
|
||||||
LinearLayout layout = new LinearLayout(root.getContext());
|
LinearLayout layout = new LinearLayout(root.getContext());
|
||||||
layout.setOrientation(LinearLayout.HORIZONTAL);
|
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
@ -38,7 +38,7 @@ public class Label extends Element {
|
||||||
layout.addView(textViewPre);
|
layout.addView(textViewPre);
|
||||||
|
|
||||||
// add element to layout
|
// add element to layout
|
||||||
element.generateDialog(layout);
|
element.addToLayout(layout);
|
||||||
|
|
||||||
// text view post element
|
// text view post element
|
||||||
if (textPost != null) {
|
if (textPost != null) {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.elements;
|
||||||
|
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class LayoutBuilder {
|
||||||
|
private ArrayList<Element> mElements = new ArrayList<>();
|
||||||
|
|
||||||
|
public LayoutBuilder add(Element element) {
|
||||||
|
mElements.add(element);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void build(LinearLayout layout) {
|
||||||
|
layout.removeAllViews();
|
||||||
|
for(Element e : mElements) {
|
||||||
|
e.addToLayout(layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue