Rule UI improvements

This commit is contained in:
M66B
2019-01-17 21:25:22 +00:00
parent 5cacec0670
commit 699d1be7ec
8 changed files with 86 additions and 58 deletions

View File

@@ -55,7 +55,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
ViewHolder(View itemView) {
super(itemView);
this.itemView = itemView;
this.itemView = itemView.findViewById(R.id.clItem);
tvName = itemView.findViewById(R.id.tvName);
}
@@ -68,6 +68,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
}
private void bindTo(EntityRule rule) {
itemView.setActivated(!rule.enabled);
tvName.setText(rule.name);
}

View File

@@ -445,9 +445,9 @@ public abstract class DB extends RoomDatabase {
" `folder` INTEGER NOT NULL," +
" `name` TEXT NOT NULL," +
" `order` INTEGER NOT NULL," +
" `enabled` INTEGER NOT NULL," +
" `condition` TEXT NOT NULL," +
" `action` TEXT NOT NULL," +
" `enabled` INTEGER NOT NULL," +
" FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)");
db.execSQL("CREATE INDEX `index_rule_folder` ON `rule` (`folder`)");
db.execSQL("CREATE INDEX `index_rule_order` ON `rule` (`order`)");

View File

@@ -29,7 +29,9 @@ import androidx.room.Update;
@Dao
public interface DaoRule {
@Query("SELECT * FROM rule WHERE folder = :folder")
@Query("SELECT * FROM rule" +
" WHERE folder = :folder" +
" ORDER BY `order`")
List<EntityRule> getRules(long folder);
@Query("SELECT rule.*, folder.account FROM rule" +
@@ -37,7 +39,7 @@ public interface DaoRule {
" WHERE rule.id = :id")
TupleRuleEx getRule(long id);
@Query("SELECT * FROM rule")
@Query("SELECT * FROM rule ORDER BY `order`")
LiveData<List<EntityRule>> liveRules();
@Insert

View File

@@ -57,11 +57,11 @@ public class EntityRule {
@NonNull
public int order;
@NonNull
public boolean enabled;
@NonNull
public String condition;
@NonNull
public String action;
@NonNull
public boolean enabled;
static final int TYPE_SEEN = 1;
static final int TYPE_UNSEEN = 2;
@@ -135,9 +135,10 @@ public class EntityRule {
EntityRule other = (EntityRule) obj;
return this.folder.equals(other.folder) &&
this.name.equals(other.name) &&
this.order == other.order &&
this.enabled == other.enabled &&
this.condition.equals(other.condition) &&
this.action.equals(other.action) &&
this.enabled == other.enabled;
this.action.equals(other.action);
} else
return false;
}

View File

@@ -50,9 +50,10 @@ import androidx.lifecycle.Lifecycle;
public class FragmentRule extends FragmentBase {
private ViewGroup view;
private EditText etName;
private EditText etOrder;
private CheckBox cbEnabled;
private Spinner spAccount;
private Spinner spFolder;
private EditText etOrder;
private EditText etSender;
private EditText etSubject;
private EditText etText;
@@ -86,9 +87,10 @@ public class FragmentRule extends FragmentBase {
// Get controls
etName = view.findViewById(R.id.etName);
etOrder = view.findViewById(R.id.etOrder);
cbEnabled = view.findViewById(R.id.cbEnabled);
spAccount = view.findViewById(R.id.spAccount);
spFolder = view.findViewById(R.id.spFolder);
etOrder = view.findViewById(R.id.etOrder);
etSender = view.findViewById(R.id.etSender);
etSubject = view.findViewById(R.id.etSubject);
etText = view.findViewById(R.id.etText);
@@ -199,6 +201,7 @@ public class FragmentRule extends FragmentBase {
etName.setText(rule == null ? null : rule.name);
etOrder.setText(rule == null ? null : Integer.toString(rule.order));
cbEnabled.setChecked(rule == null ? true : rule.enabled);
etSender.setText(jcondition.optString("sender"));
etSubject.setText(jcondition.optString("subject"));
etText.setText(jcondition.optString("text"));
@@ -357,6 +360,7 @@ public class FragmentRule extends FragmentBase {
args.putLong("folder", folder == null ? -1 : folder.id);
args.putString("name", etName.getText().toString());
args.putString("order", etOrder.getText().toString());
args.putBoolean("enabled", cbEnabled.isChecked());
args.putString("condition", jcondition.toString());
args.putString("action", jaction.toString());
@@ -377,6 +381,7 @@ public class FragmentRule extends FragmentBase {
long folder = args.getLong("folder");
String name = args.getString("name");
String order = args.getString("order");
boolean enabled = args.getBoolean("enabled");
String condition = args.getString("condition");
String action = args.getString("action");
@@ -392,6 +397,7 @@ public class FragmentRule extends FragmentBase {
rule.folder = folder;
rule.name = name;
rule.order = Integer.parseInt(order);
rule.enabled = enabled;
rule.condition = condition;
rule.action = action;
rule.id = db.rule().insertRule(rule);
@@ -400,6 +406,7 @@ public class FragmentRule extends FragmentBase {
rule.folder = folder;
rule.name = name;
rule.order = Integer.parseInt(order);
rule.enabled = enabled;
rule.condition = condition;
rule.action = action;
db.rule().updateRule(rule);