Added folder setting to enable/disable notifications

This commit is contained in:
M66B 2018-12-09 09:38:23 +01:00
parent 0fd7f670d2
commit 4a42c7764e
15 changed files with 1319 additions and 14 deletions

File diff suppressed because it is too large Load Diff

View File

@ -69,6 +69,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private View vwColor;
private View vwLevel;
private ImageView ivState;
private ImageView ivNotify;
private TextView tvName;
private TextView tvMessages;
private ImageView ivUnified;
@ -90,6 +91,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
vwColor = itemView.findViewById(R.id.vwColor);
vwLevel = itemView.findViewById(R.id.vwLevel);
ivState = itemView.findViewById(R.id.ivState);
ivNotify = itemView.findViewById(R.id.ivNotify);
tvName = itemView.findViewById(R.id.tvName);
tvMessages = itemView.findViewById(R.id.tvMessages);
ivUnified = itemView.findViewById(R.id.ivUnified);
@ -148,6 +150,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
folder.synchronize || folder.state != null || folder.sync_state != null
? View.VISIBLE : View.INVISIBLE);
ivNotify.setVisibility(folder.notify ? View.VISIBLE : View.GONE);
String name = folder.getDisplayName(context);
if (folder.unseen > 0)
tvName.setText(context.getString(R.string.title_folder_unseen, name, folder.unseen));

View File

@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 19,
version = 20,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -276,6 +276,14 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `identity` ADD COLUMN `read_receipt` INTEGER NOT NULL DEFAULT 0");
}
})
.addMigrations(new Migration(19, 20) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `notify` INTEGER NOT NULL DEFAULT 0");
db.execSQL("UPDATE `folder` SET notify = unified");
}
})
.build();
}

View File

@ -159,13 +159,14 @@ public interface DaoFolder {
", hide = :hide" +
", synchronize = :synchronize" +
", poll = :poll" +
", notify = :notify" +
", `sync_days` = :sync_days" +
", `keep_days` = :keep_days" +
" WHERE id = :id")
int setFolderProperties(
long id,
String name, String display, boolean unified, boolean hide,
boolean synchronize, boolean poll,
boolean synchronize, boolean poll, boolean notify,
int sync_days, int keep_days);
@Query("UPDATE folder SET keywords = :keywords WHERE id = :id")

View File

@ -207,13 +207,13 @@ public interface DaoMessage {
" LEFT JOIN identity ON identity.id = message.identity" +
" JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" +
" AND folder.unified" +
" AND folder.notify" +
" AND (account.created IS NULL OR message.received > account.created)" +
" AND NOT message.ui_seen" +
" AND NOT message.ui_hide" +
" AND NOT message.ui_ignored" +
" ORDER BY message.received")
LiveData<List<TupleMessageEx>> liveUnseenUnified();
LiveData<List<TupleMessageEx>> liveUnseenNotify();
@Query("SELECT COUNT(message.id) FROM message" +
" JOIN account ON account.id = message.account" +

View File

@ -79,6 +79,8 @@ public class EntityFolder implements Serializable {
public Boolean hide = false;
@NonNull
public Boolean unified = false;
@NonNull
public Boolean notify = false;
public String[] keywords;
public Boolean tbd;
public String state;
@ -178,6 +180,7 @@ public class EntityFolder implements Serializable {
(this.display == null ? other.display == null : this.display.equals(other.display)) &&
this.hide == other.hide &&
this.unified == other.unified &&
this.notify == other.notify &&
Helper.equal(this.keywords, other.keywords) &&
(this.tbd == null ? other.tbd == null : this.tbd.equals(other.tbd)) &&
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
@ -204,6 +207,7 @@ public class EntityFolder implements Serializable {
json.put("display", display);
json.put("hide", hide);
json.put("unified", unified);
json.put("notify", notify);
return json;
}
@ -235,9 +239,15 @@ public class EntityFolder implements Serializable {
if (json.has("display"))
folder.display = json.getString("display");
if (json.has("hide"))
folder.hide = json.getBoolean("hide");
folder.unified = json.getBoolean("unified");
if (json.has("notify"))
folder.notify = json.getBoolean("notify");
return folder;
}

View File

@ -757,6 +757,7 @@ public class FragmentAccount extends FragmentEx {
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = EntityFolder.DEFAULT_INBOX_SYNC;
inbox.keep_days = inbox.sync_days;

View File

@ -48,9 +48,10 @@ public class FragmentFolder extends FragmentEx {
private EditText etName;
private EditText etDisplay;
private CheckBox cbHide;
private CheckBox cbUnified;
private CheckBox cbSynchronize;
private CheckBox cbPoll;
private CheckBox cbUnified;
private CheckBox cbNotify;
private EditText etSyncDays;
private EditText etKeepDays;
private Button btnSave;
@ -82,19 +83,29 @@ public class FragmentFolder extends FragmentEx {
etName = view.findViewById(R.id.etName);
etDisplay = view.findViewById(R.id.etDisplay);
cbHide = view.findViewById(R.id.cbHide);
cbUnified = view.findViewById(R.id.cbUnified);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPoll = view.findViewById(R.id.cbPoll);
cbUnified = view.findViewById(R.id.cbUnified);
cbNotify = view.findViewById(R.id.cbNotify);
etSyncDays = view.findViewById(R.id.etSyncDays);
etKeepDays = view.findViewById(R.id.etKeepDays);
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
pbWait = view.findViewById(R.id.pbWait);
cbUnified.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
cbNotify.setChecked(true);
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbPoll.setEnabled(isChecked);
cbNotify.setEnabled(isChecked);
}
});
@ -114,6 +125,7 @@ public class FragmentFolder extends FragmentEx {
args.putBoolean("unified", cbUnified.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("poll", cbPoll.isChecked());
args.putBoolean("notify", cbNotify.isChecked());
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", etKeepDays.getText().toString());
@ -128,6 +140,7 @@ public class FragmentFolder extends FragmentEx {
boolean unified = args.getBoolean("unified");
boolean synchronize = args.getBoolean("synchronize");
boolean poll = args.getBoolean("poll");
boolean notify = args.getBoolean("notify");
String sync = args.getString("sync");
String keep = args.getString("keep");
@ -159,6 +172,7 @@ public class FragmentFolder extends FragmentEx {
create.unified = unified;
create.synchronize = synchronize;
create.poll = poll;
create.notify = notify;
create.sync_days = sync_days;
create.keep_days = keep_days;
db.folder().insertFolder(create);
@ -179,7 +193,7 @@ public class FragmentFolder extends FragmentEx {
Log.i(Helper.TAG, "Updating folder=" + name);
db.folder().setFolderProperties(id,
name, display, unified, hide,
synchronize, poll,
synchronize, poll, notify,
sync_days, keep_days);
db.message().deleteMessagesBefore(id, keep_time, true);
@ -331,6 +345,7 @@ public class FragmentFolder extends FragmentEx {
cbUnified.setChecked(folder == null ? false : folder.unified);
cbSynchronize.setChecked(folder == null || folder.synchronize);
cbPoll.setChecked(folder == null ? false : folder.poll);
cbNotify.setChecked(folder == null ? false : folder.notify);
etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_USER_SYNC : folder.sync_days));
etKeepDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_USER_SYNC : folder.keep_days));
}

View File

@ -176,7 +176,7 @@ public class ServiceSynchronize extends LifecycleService {
}
});
db.message().liveUnseenUnified().observe(this, new Observer<List<TupleMessageEx>>() {
db.message().liveUnseenNotify().observe(this, new Observer<List<TupleMessageEx>>() {
private LongSparseArray<List<Integer>> notifying = new LongSparseArray<>();
@Override

View File

@ -65,7 +65,7 @@ public class ServiceTileUnseen extends TileService {
public void onStartListening() {
Log.i(Helper.TAG, "Start tile unseen");
liveMessages = DB.getInstance(this).message().liveUnseenUnified();
liveMessages = DB.getInstance(this).message().liveUnseenNotify();
liveMessages.observe(owner, new Observer<List<TupleMessageEx>>() {
@Override
public void onChanged(List<TupleMessageEx> messages) {

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
</vector>

View File

@ -89,6 +89,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox
android:id="@+id/cbNotify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_notify_folder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPoll" />
<!-- after -->
<TextView
@ -99,7 +108,7 @@
android:text="@string/title_sync_days"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPoll" />
app:layout_constraintTop_toBottomOf="@id/cbNotify" />
<EditText
android:id="@+id/etSyncDays"

View File

@ -28,6 +28,26 @@
app:layout_constraintStart_toEndOf="@id/ivInbox"
app:layout_constraintTop_toTopOf="@id/ivInbox" />
<ImageView
android:id="@+id/ivNotify"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="12dp"
android:src="@drawable/baseline_notifications_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ivInbox" />
<TextView
android:id="@+id/tvNotify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:text="@string/title_legend_notify"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toBottomOf="@id/ivNotify"
app:layout_constraintStart_toEndOf="@id/ivNotify"
app:layout_constraintTop_toTopOf="@id/ivNotify" />
<ImageView
android:id="@+id/ivUnified"
android:layout_width="24dp"
@ -35,7 +55,7 @@
android:layout_marginTop="12dp"
android:src="@drawable/baseline_folder_special_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ivInbox" />
app:layout_constraintTop_toBottomOf="@id/ivNotify" />
<TextView
android:id="@+id/tvUnified"

View File

@ -56,6 +56,17 @@
app:layout_constraintStart_toEndOf="@id/barrier0"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ivNotify"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:src="@drawable/baseline_notifications_24"
app:layout_constraintBottom_toTopOf="@+id/barrier1"
app:layout_constraintStart_toEndOf="@id/vwLevel"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
@ -70,7 +81,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toTopOf="@+id/barrier1"
app:layout_constraintEnd_toStartOf="@+id/tvMessages"
app:layout_constraintStart_toEndOf="@id/vwLevel"
app:layout_constraintStart_toEndOf="@id/ivNotify"
app:layout_constraintTop_toTopOf="parent" />
<TextView

View File

@ -178,12 +178,13 @@
<string name="title_folder_name">Folder name</string>
<string name="title_display_name">Display name</string>
<string name="title_hide_folder">Hide from list</string>
<string name="title_hide_folders">Hide hidden folders</string>
<string name="title_show_folders">Show hidden folders</string>
<string name="title_hide_folder">Hide from list</string>
<string name="title_unified_folder">Show in unified inbox</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>
<string name="title_poll_folder">Check periodically instead of continuous synchronize</string>
<string name="title_unified_folder">Show in unified inbox</string>
<string name="title_notify_folder">Notify new messages</string>
<string name="title_sync_days">Synchronize messages (days)</string>
<string name="title_keep_days">Keep messages (days)</string>
<string name="title_folder_exists">Folder %1$s exists</string>
@ -312,6 +313,7 @@
<string name="title_action_trash">Trash</string>
<string name="title_legend_inbox">Inbox</string>
<string name="title_legend_notify">Notify new messages</string>
<string name="title_legend_unified">Unified inbox</string>
<string name="title_legend_archive">Archive</string>
<string name="title_legend_trash">Trash</string>