List rule action type

pull/156/head
M66B 6 years ago
parent b017bc897d
commit eb85e8eab7

@ -34,6 +34,8 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
@ -49,6 +51,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
private TextView tvName;
private TextView tvOrder;
private ImageView ivStop;
private TextView tvAction;
ViewHolder(View itemView) {
super(itemView);
@ -57,6 +60,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
tvName = itemView.findViewById(R.id.tvName);
tvOrder = itemView.findViewById(R.id.tvOrder);
ivStop = itemView.findViewById(R.id.ivStop);
tvAction = itemView.findViewById(R.id.tvAction);
}
private void wire() {
@ -72,6 +76,32 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
tvName.setText(rule.name);
tvOrder.setText(Integer.toString(rule.order));
ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE);
try {
JSONObject jaction = new JSONObject(rule.action);
int type = jaction.getInt("type");
switch (type) {
case EntityRule.TYPE_SEEN:
tvAction.setText(R.string.title_seen);
break;
case EntityRule.TYPE_UNSEEN:
tvAction.setText(R.string.title_unseen);
break;
case EntityRule.TYPE_MOVE:
tvAction.setText(R.string.title_move);
break;
case EntityRule.TYPE_ANSWER:
tvAction.setText(R.string.title_answer_reply);
break;
case EntityRule.TYPE_AUTOMATION:
tvAction.setText(R.string.title_rule_automation);
break;
default:
throw new IllegalArgumentException("Unknown action type=" + type);
}
} catch (Throwable ex) {
tvAction.setText(ex.getMessage());
}
}
@Override

@ -46,5 +46,15 @@
android:src="@drawable/baseline_stop_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Loading…
Cancel
Save