Introduce LayoutBuilder
This commit is contained in:
parent
ba0625b03f
commit
e1523ee82d
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
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.general.automation.elements.InputBg;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
||||
|
@ -50,10 +51,11 @@ public class ActionStartTempTarget extends Action {
|
|||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
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);
|
||||
Label labelDuration = new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration);
|
||||
labelDuration.generateDialog(root);
|
||||
|
||||
new LayoutBuilder()
|
||||
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value))
|
||||
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration))
|
||||
.build(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,5 +3,5 @@ package info.nightscout.androidaps.plugins.general.automation.elements;
|
|||
import android.widget.LinearLayout;
|
||||
|
||||
public class Element {
|
||||
public void generateDialog(LinearLayout root) { }
|
||||
public void addToLayout(LinearLayout root) { }
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class InputBg extends Element {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
public void addToLayout(LinearLayout root) {
|
||||
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
||||
numberPicker.setParams(0d, minValue, maxValue, step, decimalFormat, false, textWatcher);
|
||||
numberPicker.setValue(value);
|
||||
|
|
|
@ -21,7 +21,7 @@ public class InputDuration extends Element {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
public void addToLayout(LinearLayout root) {
|
||||
NumberPicker numberPicker = new NumberPicker(root.getContext(), null);
|
||||
if (unit.equals(TimeUnit.MINUTES)) {
|
||||
// Minutes
|
||||
|
|
|
@ -19,7 +19,7 @@ public class Label extends Element {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
public void addToLayout(LinearLayout root) {
|
||||
// container layout
|
||||
LinearLayout layout = new LinearLayout(root.getContext());
|
||||
layout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
|
@ -38,7 +38,7 @@ public class Label extends Element {
|
|||
layout.addView(textViewPre);
|
||||
|
||||
// add element to layout
|
||||
element.generateDialog(layout);
|
||||
element.addToLayout(layout);
|
||||
|
||||
// text view post element
|
||||
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