Bugfixes. Add remove icon for actions.

This commit is contained in:
Nico Schmitz 2019-03-26 23:28:46 +01:00
parent c6766c972c
commit 236349a063
4 changed files with 52 additions and 24 deletions

View file

@ -63,6 +63,7 @@ public class AutomationEvent {
trigger = Trigger.instantiate(d.getString("trigger")); trigger = Trigger.instantiate(d.getString("trigger"));
// actions // actions
JSONArray array = d.getJSONArray("actions"); JSONArray array = d.getJSONArray("actions");
actions.clear();
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
actions.add(Action.instantiate(new JSONObject(array.getString(i)))); actions.add(Action.instantiate(new JSONObject(array.getString(i))));
} }

View file

@ -131,13 +131,13 @@ public class AutomationFragment extends SubscriberFragment {
addImage(res, holder.context, holder.iconLayout); addImage(res, holder.context, holder.iconLayout);
} }
// action: remove // remove event
holder.iconTrash.setOnClickListener(v -> { holder.iconTrash.setOnClickListener(v -> {
mEventList.remove(event); mEventList.remove(event);
notifyDataSetChanged(); notifyDataSetChanged();
}); });
// action: edit // edit event
holder.rootLayout.setOnClickListener(v -> { holder.rootLayout.setOnClickListener(v -> {
EditEventDialog dialog = EditEventDialog.newInstance(event, false); EditEventDialog dialog = EditEventDialog.newInstance(event, false);
dialog.show(mFragmentManager, "EditEventDialog"); dialog.show(mFragmentManager, "EditEventDialog");
@ -168,7 +168,7 @@ public class AutomationFragment extends SubscriberFragment {
} }
/** /**
* RecyclerViewAdapter to display event lists. * RecyclerViewAdapter to display action lists.
*/ */
public static class ActionListAdapter extends RecyclerView.Adapter<ActionListAdapter.ViewHolder> { public static class ActionListAdapter extends RecyclerView.Adapter<ActionListAdapter.ViewHolder> {
private final List<Action> mActionList; private final List<Action> mActionList;
@ -190,12 +190,16 @@ public class AutomationFragment extends SubscriberFragment {
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
final Action action = mActionList.get(position); final Action action = mActionList.get(position);
holder.actionTitle.setText(action.friendlyName()); holder.actionTitle.setText(action.friendlyName());
holder.itemRoot.setOnClickListener(v -> { holder.layoutText.setOnClickListener(v -> {
if (action.hasDialog()) { if (action.hasDialog()) {
EditActionDialog dialog = EditActionDialog.newInstance(action); EditActionDialog dialog = EditActionDialog.newInstance(action);
dialog.show(mFragmentManager, "EditActionDialog"); dialog.show(mFragmentManager, "EditActionDialog");
} }
}); });
holder.iconTrash.setOnClickListener(v -> {
mActionList.remove(action);
notifyDataSetChanged();
});
} }
@Override @Override
@ -206,13 +210,15 @@ public class AutomationFragment extends SubscriberFragment {
static class ViewHolder extends RecyclerView.ViewHolder { static class ViewHolder extends RecyclerView.ViewHolder {
TextView actionTitle; TextView actionTitle;
TextView actionDescription; TextView actionDescription;
LinearLayout itemRoot; LinearLayout layoutText;
ImageView iconTrash;
public ViewHolder(View view) { public ViewHolder(View view) {
super(view); super(view);
itemRoot = view.findViewById(R.id.itemRoot); layoutText = view.findViewById(R.id.layoutText);
actionTitle = view.findViewById(R.id.viewActionTitle); actionTitle = view.findViewById(R.id.viewActionTitle);
actionDescription = view.findViewById(R.id.viewActionDescription); actionDescription = view.findViewById(R.id.viewActionDescription);
iconTrash = view.findViewById(R.id.iconTrash);
} }
} }
} }

View file

@ -160,6 +160,7 @@ public class TriggerConnector extends Trigger {
JSONObject d = new JSONObject(data); JSONObject d = new JSONObject(data);
connectorType = Type.valueOf(JsonHelper.safeGetString(d, "connectorType")); connectorType = Type.valueOf(JsonHelper.safeGetString(d, "connectorType"));
JSONArray array = d.getJSONArray("triggerList"); JSONArray array = d.getJSONArray("triggerList");
list.clear();
for (int i = 0; i < array.length(); i++) { for (int i = 0; i < array.length(); i++) {
Trigger newItem = instantiate(new JSONObject(array.getString(i))); Trigger newItem = instantiate(new JSONObject(array.getString(i)));
add(newItem); add(newItem);

View file

@ -1,32 +1,52 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/itemRoot"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/ribbonDefault"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:paddingLeft="4dp" android:paddingLeft="4dp"
android:paddingRight="4dp" android:paddingRight="4dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp">
android:orientation="vertical"
android:background="@color/ribbonDefault">
<TextView <ImageView
android:id="@+id/viewActionTitle" android:id="@+id/iconTrash"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" app:srcCompat="@drawable/ic_trash_outline"
app:layout_constraintStart_toStartOf="parent" android:layout_alignParentRight="true"
app:layout_constraintTop_toTopOf="parent" /> android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"/>
<TextView <LinearLayout
android:id="@+id/viewActionDescription" android:id="@+id/layoutText"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent" android:layout_alignParentTop="true"
app:layout_constraintTop_toTopOf="parent" android:layout_alignParentBottom="true"
android:visibility="gone"/> android:layout_toLeftOf="@id/iconTrash"
</LinearLayout> android:layout_alignParentLeft="true">
<TextView
android:id="@+id/viewActionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/viewActionDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>