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);

View File

@ -37,6 +37,36 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
<TextView
android:id="@+id/tvOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_order"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<EditText
android:id="@+id/etOrder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="1"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOrder" />
<CheckBox
android:id="@+id/cbEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_enabled"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etOrder" />
<!-- account -->
<TextView
@ -47,7 +77,7 @@
android:text="@string/title_rule_account"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
app:layout_constraintTop_toBottomOf="@id/cbEnabled" />
<Spinner
android:id="@+id/spAccount"
@ -87,27 +117,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spFolder" />
<TextView
android:id="@+id/tvOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_order"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFolderRemark" />
<EditText
android:id="@+id/etOrder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="1"
android:inputType="number"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOrder" />
<!-- condition -->
<TextView
@ -118,7 +127,7 @@
android:text="@string/title_rule_sender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etOrder" />
app:layout_constraintTop_toBottomOf="@id/tvFolderRemark" />
<EditText
android:id="@+id/etSender"

View File

@ -1,31 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vSeparator"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clItem"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="wrap_content"
android:background="?attr/drawableItemBackground">
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/vSeparator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View File

@ -386,6 +386,7 @@
<string name="title_rule_folder">Folder</string>
<string name="title_rule_folder_remark">The texts of messages in the selected folder will always be downloaded</string>
<string name="title_rule_order">Order</string>
<string name="title_rule_enabled">Enabled</string>
<string name="title_rule_sender">Sender</string>
<string name="title_rule_subject">Subject</string>
<string name="title_rule_text">Text</string>