mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 11:28:41 +01:00
Added folder setting to enable/disable notifications
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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" +
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user