diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java index 420b62dd30..5e2df9642d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation; import android.app.Activity; import android.content.Context; import android.os.Bundle; +import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.v4.app.FragmentManager; import android.support.v7.widget.LinearLayoutManager; @@ -13,10 +14,13 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; +import java.util.HashSet; import java.util.List; import butterknife.BindView; @@ -88,16 +92,48 @@ public class AutomationFragment extends SubscriberFragment { @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.automation_event_item, parent, false); - return new ViewHolder(v); + return new ViewHolder(v, parent.getContext()); + } + + private void addImage(@DrawableRes int res, Context context, LinearLayout layout) { + ImageView iv = new ImageView(context); + iv.setImageResource(res); + iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24))); + layout.addView(iv); } @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final AutomationEvent event = mEventList.get(position); holder.eventTitle.setText(event.getTitle()); + holder.iconLayout.removeAllViews(); + + // trigger icons + HashSet triggerIcons = new HashSet<>(); + TriggerConnector.fillIconSet((TriggerConnector)event.getTrigger(), triggerIcons); + for(int res : triggerIcons) { + addImage(res, holder.context, holder.iconLayout); + } + + // arrow icon + ImageView iv = new ImageView(holder.context); + iv.setImageResource(R.drawable.ic_arrow_forward_white_24dp); + iv.setLayoutParams(new LinearLayout.LayoutParams(MainApp.dpToPx(24),MainApp.dpToPx(24))); + iv.setPadding(MainApp.dpToPx(4), 0, MainApp.dpToPx(4), 0); + holder.iconLayout.addView(iv); + + // action icons + HashSet actionIcons = new HashSet<>(); + for(Action action : event.getActions()) { + if (action.icon().isPresent()) + actionIcons.add(action.icon().get()); + } + for(int res : actionIcons) { + addImage(res, holder.context, holder.iconLayout); + } // TODO: check null - holder.eventDescription.setText(event.getTrigger().friendlyDescription()); + //holder.eventDescription.setText(event.getTrigger().friendlyDescription()); } @Override @@ -106,13 +142,17 @@ public class AutomationFragment extends SubscriberFragment { } static class ViewHolder extends RecyclerView.ViewHolder { - TextView eventTitle; - TextView eventDescription; + final RelativeLayout rootLayout; + final LinearLayout iconLayout; + final TextView eventTitle; + final Context context; - public ViewHolder(View view) { + public ViewHolder(View view, Context context) { super(view); + this.context = context; eventTitle = view.findViewById(R.id.viewEventTitle); - eventDescription = view.findViewById(R.id.viewEventDescription); + rootLayout = view.findViewById(R.id.rootLayout); + iconLayout = view.findViewById(R.id.iconLayout); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java index 7f709c8863..d1522640f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/Action.java @@ -1,10 +1,9 @@ package info.nightscout.androidaps.plugins.general.automation.actions; -import android.content.Context; -import android.support.v4.app.FragmentManager; -import android.view.View; import android.widget.LinearLayout; +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; @@ -30,6 +29,8 @@ public abstract class Action { return o.toString(); } + public abstract Optional icon(); + public void copy(Action action) { } /*package*/ Action fromJSON(String data) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java index 4c50b251fa..8ac6162cf6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopDisable.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; @@ -33,4 +35,9 @@ public class ActionLoopDisable extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadydisabled)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_stop_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java index 425a31ec6b..f11b9dcaea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopEnable.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; @@ -28,4 +30,9 @@ public class ActionLoopEnable extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadyenabled)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_play_circle_outline_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java index 895782ebd0..9a9b1f31e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResume.java @@ -1,10 +1,11 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventRefreshOverview; -import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; @@ -30,4 +31,9 @@ public class ActionLoopResume extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.notsuspended)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_replay_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java index 1aef9efb36..2678ffb71b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopSuspend.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.actions; +import com.google.common.base.Optional; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.PumpEnactResult; @@ -27,4 +29,9 @@ public class ActionLoopSuspend extends Action { callback.result(new PumpEnactResult().success(true).comment(R.string.alreadysuspended)).run(); } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_pause_circle_outline_24dp); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java index a7df2bafab..2b689606b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java @@ -1,15 +1,15 @@ package info.nightscout.androidaps.plugins.general.automation.actions; -import android.support.annotation.StringRes; import android.widget.LinearLayout; +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; @@ -102,4 +102,9 @@ public class ActionStartTempTarget extends Action { this.reason = src.reason; } } + + @Override + public Optional icon() { + return Optional.of(R.drawable.icon_cp_cgm_target); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java index a976f31957..de7b0e4dfd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/Element.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.general.automation.elements; -import android.content.Context; -import android.view.View; import android.widget.LinearLayout; public class Element { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java index 74c4566559..174e40b0d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java @@ -1,9 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; -import android.content.Context; import android.text.Editable; import android.text.TextWatcher; -import android.view.View; import android.widget.LinearLayout; import java.text.DecimalFormat; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java index 4cd1150189..ff4cddbc4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.general.automation.elements; -import android.content.Context; -import android.view.View; import android.widget.LinearLayout; import java.text.DecimalFormat; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java index efe8a66e71..2f766a14c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/Trigger.java @@ -8,6 +8,8 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; @@ -95,6 +97,8 @@ public abstract class Trigger { public abstract String friendlyDescription(); + public abstract Optional icon(); + void notifyAboutRun(long time) { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java index 51a8bd9b70..9fda5b2402 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java @@ -13,6 +13,8 @@ import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; +import com.google.common.base.Optional; + import org.json.JSONException; import org.json.JSONObject; @@ -124,6 +126,11 @@ public class TriggerBg extends Trigger { return MainApp.gs(R.string.glucosecompared, MainApp.gs(comparator.getStringRes()), threshold, units); } + @Override + public Optional icon() { + return Optional.of(R.drawable.icon_cp_bgcheck); + } + @Override public Trigger duplicate() { return new TriggerBg(this); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java index 70cfc2752b..7f29a6975a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.java @@ -7,11 +7,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; +import com.google.common.base.Optional; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import info.nightscout.androidaps.MainApp; @@ -59,6 +62,19 @@ public class TriggerConnector extends Trigger { } } + public static void fillIconSet(TriggerConnector connector, HashSet set) { + for(Trigger t : connector.list) { + if (t instanceof TriggerConnector) { + fillIconSet((TriggerConnector) t, set); + } else { + Optional icon = t.icon(); + if (icon.isPresent()) { + set.add(icon.get()); + } + } + } + } + protected List list = new ArrayList<>(); private Type connectorType; @@ -170,6 +186,11 @@ public class TriggerConnector extends Trigger { return result.toString(); } + @Override + public Optional icon() { + return Optional.absent(); + } + @Override public Trigger duplicate() { return null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java index 1abd9de4eb..9fc06e6f9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTime.java @@ -8,6 +8,7 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import com.dpro.widgets.WeekdaysPicker; +import com.google.common.base.Optional; import org.json.JSONException; import org.json.JSONObject; @@ -230,6 +231,11 @@ public class TriggerTime extends Trigger { } } + @Override + public Optional icon() { + return Optional.of(R.drawable.ic_access_alarm_24dp); + } + @Override void notifyAboutRun(long time) { lastRun = time; diff --git a/app/src/main/res/drawable/ic_access_alarm_24dp.xml b/app/src/main/res/drawable/ic_access_alarm_24dp.xml new file mode 100644 index 0000000000..3e1d84e037 --- /dev/null +++ b/app/src/main/res/drawable/ic_access_alarm_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml new file mode 100644 index 0000000000..5304b93e18 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_forward_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml b/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml new file mode 100644 index 0000000000..4a469646bd --- /dev/null +++ b/app/src/main/res/drawable/ic_pause_circle_outline_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml b/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml new file mode 100644 index 0000000000..9997bf2034 --- /dev/null +++ b/app/src/main/res/drawable/ic_play_circle_outline_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_replay_24dp.xml b/app/src/main/res/drawable/ic_replay_24dp.xml new file mode 100644 index 0000000000..32942990ac --- /dev/null +++ b/app/src/main/res/drawable/ic_replay_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_stop_24dp.xml b/app/src/main/res/drawable/ic_stop_24dp.xml new file mode 100644 index 0000000000..88299804a8 --- /dev/null +++ b/app/src/main/res/drawable/ic_stop_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/automation_event_item.xml b/app/src/main/res/layout/automation_event_item.xml index dc80aeaf15..a481c39755 100644 --- a/app/src/main/res/layout/automation_event_item.xml +++ b/app/src/main/res/layout/automation_event_item.xml @@ -1,26 +1,32 @@ - + android:layout_marginTop="8dp" + android:padding="8dp" + android:background="@color/ribbonDefault"> + + - - \ No newline at end of file + \ No newline at end of file