Added system folders selection

pull/30/head
M66B 6 years ago
parent 7376362d21
commit 0a7ec026b1

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "ff81778e939ac6480ab8ec93435db96a",
"identityHash": "959322c3e61ed9307a830e355bb2b8ab",
"entities": [
{
"tableName": "identity",
@ -674,6 +674,14 @@
"autoGenerate": true
},
"indices": [
{
"name": "index_operation_message",
"unique": false,
"columnNames": [
"message"
],
"createSql": "CREATE INDEX `index_operation_message` ON `${TABLE_NAME}` (`message`)"
},
{
"name": "index_operation_message",
"unique": false,
@ -711,7 +719,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"ff81778e939ac6480ab8ec93435db96a\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"959322c3e61ed9307a830e355bb2b8ab\")"
]
}
}

@ -62,16 +62,17 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
static final int LOADER_ACCOUNT_PUT = 1;
static final int LOADER_IDENTITY_PUT = 2;
static final int LOADER_FOLDER_PUT = 3;
static final int LOADER_MESSAGE_SEEN = 4;
static final int LOADER_MESSAGE_EDIT = 5;
static final int LOADER_MESSAGE_SPAM = 6;
static final int LOADER_MESSAGE_TRASH = 7;
static final int LOADER_MESSAGE_MOVE = 8;
static final int LOADER_MESSAGE_ARCHIVE = 9;
static final int LOADER_SEEN_UNTIL = 10;
static final int LOADER_ACCOUNT_CHECK = 1;
static final int LOADER_ACCOUNT_PUT = 2;
static final int LOADER_IDENTITY_PUT = 3;
static final int LOADER_FOLDER_PUT = 4;
static final int LOADER_MESSAGE_SEEN = 5;
static final int LOADER_MESSAGE_EDIT = 6;
static final int LOADER_MESSAGE_SPAM = 7;
static final int LOADER_MESSAGE_TRASH = 8;
static final int LOADER_MESSAGE_MOVE = 9;
static final int LOADER_MESSAGE_ARCHIVE = 10;
static final int LOADER_SEEN_UNTIL = 11;
static final int REQUEST_VIEW = 1;
static final int REQUEST_UNSEEN = 2;

@ -44,7 +44,7 @@ public class ApplicationEx extends Application {
DB db = null;
try {
db = DB.getBlockingInstance(ApplicationEx.this);
EntityFolder drafts = EntityFolder.getDrafts(ApplicationEx.this, db, -1);
EntityFolder drafts = db.folder().getPrimaryDrafts();
if (drafts != null) {
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");

@ -71,8 +71,11 @@ public interface DaoFolder {
" WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String type);
@Query("SELECT * FROM folder WHERE account IS NULL AND type = '" + EntityFolder.DRAFTS + "'")
EntityFolder getLocalDrafts();
// For debug/crash info
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
EntityFolder getPrimaryDrafts();
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'")
EntityFolder getOutbox();
@ -85,4 +88,10 @@ public interface DaoFolder {
@Query("DELETE FROM folder WHERE account= :account AND name = :name")
void deleteFolder(Long account, String name);
@Query("DELETE FROM folder" +
" WHERE account= :account" +
" AND type <> '" + EntityFolder.INBOX + "'" +
" AND type <> '" + EntityFolder.USER + "'")
int deleteSystemFolders(Long account);
}

@ -80,7 +80,7 @@ public interface DaoMessage {
@Query("SELECT * FROM message WHERE folder = :folder AND uid = :uid")
EntityMessage getMessage(long folder, long uid);
@Query("SELECT * FROM message" +
@Query("SELECT message.* FROM message" +
" JOIN folder on folder.id = message.folder" +
" WHERE thread = :thread AND folder.type= '" + EntityFolder.ARCHIVE + "'")
EntityMessage getArchivedMessage(String thread);

@ -19,8 +19,7 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
@ -44,7 +43,7 @@ import static androidx.room.ForeignKey.CASCADE;
@Index(value = {"type"})
}
)
public class EntityFolder {
public class EntityFolder implements Serializable {
static final String TABLE_NAME = "folder";
static final String INBOX = "Inbox";
@ -105,21 +104,6 @@ public class EntityFolder {
@NonNull
public Integer after; // days
static EntityFolder getDrafts(Context context, DB db, long account) {
EntityFolder drafts = db.folder().getFolderByType(account, EntityFolder.DRAFTS);
if (drafts == null)
drafts = db.folder().getLocalDrafts();
if (drafts == null) {
drafts = new EntityFolder();
drafts.name = context.getString(R.string.title_folder_local_drafts);
drafts.type = EntityFolder.DRAFTS;
drafts.synchronize = false;
drafts.after = 0;
drafts.id = db.folder().insertFolder(drafts);
}
return drafts;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityFolder) {
@ -132,4 +116,9 @@ public class EntityFolder {
} else
return false;
}
@Override
public String toString() {
return name;
}
}

@ -44,6 +44,7 @@ import static androidx.room.ForeignKey.CASCADE;
@ForeignKey(childColumns = "message", entity = EntityMessage.class, parentColumns = "id", onDelete = CASCADE)
},
indices = {
@Index(value = {"folder"}),
@Index(value = {"message"})
}
)

@ -61,7 +61,7 @@ public class FragmentAbout extends FragmentEx {
public void run() {
try {
DB db = DB.getInstance(getContext());
EntityFolder drafts = EntityFolder.getDrafts(getContext(), db, -1);
EntityFolder drafts = db.folder().getPrimaryDrafts();
if (drafts != null) {
StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n");

@ -42,9 +42,13 @@ import com.google.android.material.textfield.TextInputLayout;
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPStore;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -55,6 +59,7 @@ import javax.mail.Session;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Observer;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.AsyncTaskLoader;
@ -71,9 +76,17 @@ public class FragmentAccount extends FragmentEx {
private TextInputLayout tilPassword;
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private Button btnSave;
private Button btnCheck;
private ProgressBar pbCheck;
private Spinner spDrafts;
private Spinner spSent;
private Spinner spAll;
private Spinner spTrash;
private Spinner spJunk;
private Button btnSave;
private ProgressBar pbSave;
private ImageButton ibDelete;
private Group grpFolders;
// TODO: loading spinner
private ExecutorService executor = Executors.newCachedThreadPool();
@ -102,9 +115,17 @@ public class FragmentAccount extends FragmentEx {
tilPassword = view.findViewById(R.id.tilPassword);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
btnSave = view.findViewById(R.id.btnSave);
btnCheck = view.findViewById(R.id.btnCheck);
pbCheck = view.findViewById(R.id.pbCheck);
spDrafts = view.findViewById(R.id.spDrafts);
spSent = view.findViewById(R.id.spSent);
spAll = view.findViewById(R.id.spAll);
spTrash = view.findViewById(R.id.spTrash);
spJunk = view.findViewById(R.id.spJunk);
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
ibDelete = view.findViewById(R.id.ibDelete);
grpFolders = view.findViewById(R.id.grpFolders);
// Wire controls
@ -135,11 +156,49 @@ public class FragmentAccount extends FragmentEx {
}
});
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", etName.getText().toString());
args.putString("host", etHost.getText().toString());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
LoaderManager.getInstance(FragmentAccount.this)
.restartLoader(ActivityView.LOADER_ACCOUNT_CHECK, args, checkLoaderCallbacks).forceLoad();
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnSave.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
pbSave.setVisibility(View.VISIBLE);
EntityFolder drafts = (EntityFolder) spDrafts.getSelectedItem();
EntityFolder sent = (EntityFolder) spSent.getSelectedItem();
EntityFolder all = (EntityFolder) spAll.getSelectedItem();
EntityFolder trash = (EntityFolder) spTrash.getSelectedItem();
EntityFolder junk = (EntityFolder) spJunk.getSelectedItem();
if (drafts.type == null)
drafts = null;
if (sent.type == null)
sent = null;
if (all.type == null)
all = null;
if (trash.type == null)
trash = null;
if (junk.type == null)
junk = null;
Bundle args = new Bundle();
args.putLong("id", id);
@ -150,6 +209,11 @@ public class FragmentAccount extends FragmentEx {
args.putString("password", tilPassword.getEditText().getText().toString());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putSerializable("drafts", drafts);
args.putSerializable("sent", sent);
args.putSerializable("all", all);
args.putSerializable("trash", trash);
args.putSerializable("junk", junk);
LoaderManager.getInstance(FragmentAccount.this)
.restartLoader(ActivityView.LOADER_ACCOUNT_PUT, args, putLoaderCallbacks).forceLoad();
@ -189,6 +253,9 @@ public class FragmentAccount extends FragmentEx {
// Initialize
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
pbCheck.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
return view;
@ -202,8 +269,10 @@ public class FragmentAccount extends FragmentEx {
Bundle args = getArguments();
long id = (args == null ? -1 : args.getLong("id", -1));
final DB db = DB.getInstance(getContext());
// Observe
DB.getInstance(getContext()).account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
db.account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
@Override
public void onChanged(@Nullable EntityAccount account) {
etName.setText(account == null ? null : account.name);
@ -218,10 +287,15 @@ public class FragmentAccount extends FragmentEx {
});
}
private static class PutLoader extends AsyncTaskLoader<Throwable> {
private static class CheckData {
Throwable ex;
List<EntityFolder> folders;
}
private static class CheckLoader extends AsyncTaskLoader<CheckData> {
private Bundle args;
PutLoader(Context context) {
CheckLoader(Context context) {
super(context);
}
@ -230,14 +304,14 @@ public class FragmentAccount extends FragmentEx {
}
@Override
public Throwable loadInBackground() {
public CheckData loadInBackground() {
CheckData result = new CheckData();
try {
String name = args.getString("name");
long id = args.getLong("id");
String host = args.getString("host");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
boolean synchronize = args.getBoolean("synchronize");
if (TextUtils.isEmpty(host))
throw new Throwable(getContext().getString(R.string.title_no_host));
@ -248,46 +322,27 @@ public class FragmentAccount extends FragmentEx {
if (TextUtils.isEmpty(password))
throw new Throwable(getContext().getString(R.string.title_no_password));
if (TextUtils.isEmpty(name))
name = host + "/" + user;
// Check IMAP server / get folders
DB db = DB.getInstance(getContext());
EntityAccount account = db.account().getAccount(args.getLong("id"));
boolean update = (account != null);
if (account == null)
account = new EntityAccount();
account.name = name;
account.host = host;
account.port = Integer.parseInt(port);
account.user = user;
account.password = password;
account.synchronize = synchronize;
account.primary = (account.synchronize && args.getBoolean("primary"));
// On disabling synchronization mark message seen until now
if (!account.synchronize && account.synchronize != synchronize)
account.seen_until = new Date().getTime();
// Check IMAP server
List<EntityFolder> folders = new ArrayList<>();
if (account.synchronize) {
Session isession = Session.getInstance(MessageHelper.getSessionProperties(), null);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore("imaps");
istore.connect(account.host, account.port, account.user, account.password);
istore.connect(host, Integer.parseInt(port), user, password);
if (!istore.hasCapability("IDLE"))
throw new MessagingException(getContext().getString(R.string.title_no_idle));
// Find system folders
boolean drafts = false;
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String type = null;
// First check folder attributes
boolean selectable = true;
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
for (String attr : attrs) {
if ("\\Noselect".equals(attr))
selectable = false;
if (attr.startsWith("\\")) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
if (index >= 0) {
@ -297,6 +352,7 @@ public class FragmentAccount extends FragmentEx {
}
}
if (selectable) {
// Next check folder full name
if (type == null) {
String fullname = ifolder.getFullName();
@ -308,59 +364,238 @@ public class FragmentAccount extends FragmentEx {
}
}
if (type != null) {
EntityFolder folder = new EntityFolder();
// Create entry
EntityFolder folder = db.folder().getFolderByName(id, ifolder.getFullName());
if (folder == null) {
folder = new EntityFolder();
folder.name = ifolder.getFullName();
folder.type = type;
folder.synchronize = EntityFolder.SYSTEM_FOLDER_SYNC.contains(folder.type);
folder.after = EntityFolder.DEFAULT_SYSTEM_SYNC;
folder.type = (type == null ? EntityFolder.USER : type);
folder.synchronize = (type != null && EntityFolder.SYSTEM_FOLDER_SYNC.contains(type));
folder.after = (type == null ? EntityFolder.DEFAULT_USER_SYNC : EntityFolder.DEFAULT_SYSTEM_SYNC);
}
folders.add(folder);
Log.i(Helper.TAG, account.name +
" system=" + folder.name +
Log.i(Helper.TAG, folder.name + " id=" + folder.id +
" type=" + folder.type + " attr=" + TextUtils.join(",", attrs));
}
}
if (EntityFolder.DRAFTS.equals(folder.type))
drafts = true;
} finally {
if (istore != null)
istore.close();
}
result.folders = folders;
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
result.ex = ex;
}
if (!drafts) {
EntityFolder folder = new EntityFolder();
folder.name = getContext().getString(R.string.title_folder_local_drafts);
folder.type = EntityFolder.DRAFTS;
folder.synchronize = false;
folder.after = 0;
folders.add(folder);
return result;
}
}
private LoaderManager.LoaderCallbacks checkLoaderCallbacks = new LoaderManager.LoaderCallbacks<CheckData>() {
@NonNull
@Override
public Loader<CheckData> onCreateLoader(int id, Bundle args) {
CheckLoader loader = new CheckLoader(getContext());
loader.setArgs(args);
return loader;
}
@Override
public void onLoadFinished(@NonNull Loader<CheckData> loader, CheckData data) {
LoaderManager.getInstance(FragmentAccount.this).destroyLoader(loader.getId());
btnCheck.setEnabled(true);
pbCheck.setVisibility(View.GONE);
if (data.ex == null) {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(data.folders, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = ((Integer) EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type))
.compareTo(EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
int c = -f1.synchronize.compareTo(f2.synchronize);
if (c != 0)
return c;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
EntityFolder none = new EntityFolder();
none.name = "";
data.folders.add(0, none);
ArrayAdapter<EntityFolder> adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item, data.folders);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spDrafts.setAdapter(adapter);
spSent.setAdapter(adapter);
spAll.setAdapter(adapter);
spTrash.setAdapter(adapter);
spJunk.setAdapter(adapter);
for (int pos = 0; pos < data.folders.size(); pos++) {
if (EntityFolder.DRAFTS.equals(data.folders.get(pos).type))
spDrafts.setSelection(pos);
else if (EntityFolder.SENT.equals(data.folders.get(pos).type))
spSent.setSelection(pos);
else if (EntityFolder.ARCHIVE.equals(data.folders.get(pos).type))
spAll.setSelection(pos);
else if (EntityFolder.TRASH.equals(data.folders.get(pos).type))
spTrash.setSelection(pos);
else if (EntityFolder.JUNK.equals(data.folders.get(pos).type))
spJunk.setSelection(pos);
}
grpFolders.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.VISIBLE);
} else {
Log.w(Helper.TAG, data.ex + "\n" + Log.getStackTraceString(data.ex));
Toast.makeText(getContext(), Helper.formatThrowable(data.ex), Toast.LENGTH_LONG).show();
}
}
@Override
public void onLoaderReset(@NonNull Loader<CheckData> loader) {
}
};
private static class PutLoader extends AsyncTaskLoader<Throwable> {
private Bundle args;
PutLoader(Context context) {
super(context);
}
void setArgs(Bundle args) {
this.args = args;
}
@Override
public Throwable loadInBackground() {
try {
String name = args.getString("name");
String host = args.getString("host");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
boolean synchronize = args.getBoolean("synchronize");
EntityFolder drafts = (EntityFolder) args.getSerializable("drafts");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
EntityFolder all = (EntityFolder) args.getSerializable("all");
EntityFolder trash = (EntityFolder) args.getSerializable("trash");
EntityFolder junk = (EntityFolder) args.getSerializable("junk");
if (TextUtils.isEmpty(host))
throw new Throwable(getContext().getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
throw new Throwable(getContext().getString(R.string.title_no_port));
if (TextUtils.isEmpty(user))
throw new Throwable(getContext().getString(R.string.title_no_user));
if (TextUtils.isEmpty(password))
throw new Throwable(getContext().getString(R.string.title_no_password));
if (drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_drafts));
// Check IMAP server
Session isession = Session.getInstance(MessageHelper.getSessionProperties(), null);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore("imaps");
istore.connect(host, Integer.parseInt(port), user, password);
if (!istore.hasCapability("IDLE"))
throw new MessagingException(getContext().getString(R.string.title_no_idle));
} finally {
if (istore != null)
istore.close();
}
}
if (account.primary)
db.account().resetPrimary();
if (TextUtils.isEmpty(name))
name = host + "/" + user;
DB db = DB.getInstance(getContext());
EntityAccount account = db.account().getAccount(args.getLong("id"));
boolean update = (account != null);
if (account == null)
account = new EntityAccount();
account.name = name;
account.host = host;
account.port = Integer.parseInt(port);
account.user = user;
account.password = password;
account.synchronize = synchronize;
account.primary = (account.synchronize && args.getBoolean("primary"));
// On disabling synchronization mark message seen until now
if (!account.synchronize && account.synchronize != synchronize)
account.seen_until = new Date().getTime();
try {
db.beginTransaction();
if (account.primary)
db.account().resetPrimary();
if (update)
db.account().updateAccount(account);
else
account.id = db.account().insertAccount(account);
List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.after = EntityFolder.DEFAULT_INBOX_SYNC;
folders.add(0, inbox);
for (EntityFolder folder : folders)
if (db.folder().getFolderByName(account.id, folder.name) == null) {
folders.add(inbox);
if (drafts != null) {
drafts.type = EntityFolder.DRAFTS;
folders.add(drafts);
}
if (sent != null) {
sent.type = EntityFolder.SENT;
folders.add(sent);
}
if (all != null) {
all.type = EntityFolder.ARCHIVE;
folders.add(all);
}
if (trash != null) {
trash.type = EntityFolder.TRASH;
folders.add(trash);
}
if (junk != null) {
junk.type = EntityFolder.JUNK;
folders.add(junk);
}
int count = db.folder().deleteSystemFolders(account.id);
Log.w(Helper.TAG, "Deleted system folders count=" + count);
for (EntityFolder folder : folders) {
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
folder.account = account.id;
Log.i(Helper.TAG, "Creating folder=" + folder.name + " (" + folder.type + ")");
folder.id = db.folder().insertFolder(folder);
} else {
existing.type = folder.type;
db.folder().updateFolder(existing);
}
}
db.setTransactionSuccessful();
@ -392,7 +627,7 @@ public class FragmentAccount extends FragmentEx {
LoaderManager.getInstance(FragmentAccount.this).destroyLoader(loader.getId());
btnSave.setEnabled(true);
pbCheck.setVisibility(View.GONE);
btnCheck.setVisibility(View.GONE);
if (ex == null)
getFragmentManager().popBackStack();

@ -517,7 +517,7 @@ public class FragmentCompose extends FragmentEx {
if (ident == null)
throw new IllegalArgumentException(getContext().getString(R.string.title_from_missing));
EntityFolder drafts = EntityFolder.getDrafts(getContext(), db, ident.account);
EntityFolder drafts = db.folder().getFolderByType(ident.account, EntityFolder.DRAFTS);
long rid = args.getLong("rid", -1);
String thread = args.getString("thread");
@ -623,12 +623,9 @@ public class FragmentCompose extends FragmentEx {
}
private LoaderManager.LoaderCallbacks putLoaderCallbacks = new LoaderManager.LoaderCallbacks<Throwable>() {
private Bundle args;
@NonNull
@Override
public Loader<Throwable> onCreateLoader(int id, Bundle args) {
this.args = args;
PutLoader loader = new PutLoader(getContext());
loader.setArgs(args);
return loader;
@ -638,6 +635,7 @@ public class FragmentCompose extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
LoaderManager.getInstance(FragmentCompose.this).destroyLoader(loader.getId());
Bundle args = ((PutLoader) loader).args;
String action = args.getString("action");
Log.i(Helper.TAG, "Put finished action=" + action + " ex=" + ex);

@ -366,6 +366,9 @@ public class FragmentIdentity extends FragmentEx {
}
}
try {
db.beginTransaction();
if (identity.primary)
db.identity().resetPrimary();
@ -374,6 +377,11 @@ public class FragmentIdentity extends FragmentEx {
else
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));

@ -444,7 +444,7 @@ public class FragmentMessage extends FragmentEx {
long id = args.getLong("id");
DB db = DB.getInstance(getContext());
EntityMessage draft = db.message().getMessage(id);
EntityFolder drafts = EntityFolder.getDrafts(getContext(), db, draft.account);
EntityFolder drafts = db.folder().getFolderByType(draft.account, EntityFolder.DRAFTS);
draft.id = null;
draft.folder = drafts.id;
draft.uid = null;
@ -757,19 +757,16 @@ public class FragmentMessage extends FragmentEx {
}
private LoaderManager.LoaderCallbacks moveLoaderCallbacks = new LoaderManager.LoaderCallbacks<List<EntityFolder>>() {
Bundle args;
@NonNull
@Override
public Loader<List<EntityFolder>> onCreateLoader(int id, Bundle args) {
this.args = args;
MoveLoader loader = new MoveLoader(getContext());
loader.setArgs(args);
return loader;
}
@Override
public void onLoadFinished(@NonNull Loader<List<EntityFolder>> loader, List<EntityFolder> folders) {
public void onLoadFinished(@NonNull final Loader<List<EntityFolder>> loader, List<EntityFolder> folders) {
LoaderManager.getInstance(FragmentMessage.this).destroyLoader(loader.getId());
View anchor = bottom_navigation.findViewById(R.id.action_move);
@ -788,6 +785,7 @@ public class FragmentMessage extends FragmentEx {
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = ((MoveLoader) loader).args;
args.putLong("target", target.getItemId());
new SimpleLoader() {

@ -986,19 +986,20 @@ public class ServiceSynchronize extends LifecycleService {
for (Folder ifolder : ifolders) {
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
boolean candidate = true;
boolean selectable = true;
for (String attr : attrs) {
if ("\\Noselect".equals(attr)) { // TODO: is this attribute correct?
candidate = false;
selectable = false;
break;
}
if (attr.startsWith("\\"))
if (EntityFolder.SYSTEM_FOLDER_ATTR.contains(attr.substring(1))) {
candidate = false;
selectable = false;
break;
}
}
if (candidate) {
if (selectable) {
Log.i(Helper.TAG, ifolder.getFullName() + " candidate attr=" + TextUtils.join(",", attrs));
EntityFolder folder = dao.getFolderByName(account.id, ifolder.getFullName());
if (folder == null) {

@ -176,12 +176,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<!-- check -->
<Button
android:id="@+id/btnSave"
android:id="@+id/btnCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_save"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
@ -192,6 +194,119 @@
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="@id/btnCheck"
app:layout_constraintStart_toEndOf="@id/btnCheck"
app:layout_constraintTop_toTopOf="@id/btnCheck" />
<TextView
android:id="@+id/tvDrafts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:text="@string/title_folder_drafts"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/spDrafts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spDrafts" />
<Spinner
android:id="@+id/spDrafts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintStart_toEndOf="@id/tvDrafts"
app:layout_constraintTop_toBottomOf="@id/btnCheck" />
<TextView
android:id="@+id/tvSent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:text="@string/title_folder_sent"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/spSent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spSent" />
<Spinner
android:id="@+id/spSent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/tvSent"
app:layout_constraintTop_toBottomOf="@id/spDrafts" />
<TextView
android:id="@+id/tvAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:text="@string/title_folder_all"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/spAll"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spAll" />
<Spinner
android:id="@+id/spAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/tvAll"
app:layout_constraintTop_toBottomOf="@id/spSent" />
<TextView
android:id="@+id/tvTrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:text="@string/title_folder_trash"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/spTrash"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spTrash" />
<Spinner
android:id="@+id/spTrash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/tvTrash"
app:layout_constraintTop_toBottomOf="@id/spAll" />
<TextView
android:id="@+id/tvJunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:text="@string/title_folder_junk"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/spJunk"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/spJunk" />
<Spinner
android:id="@+id/spJunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/tvJunk"
app:layout_constraintTop_toBottomOf="@id/spTrash" />
<!-- save -->
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spJunk" />
<ProgressBar
android:id="@+id/pbSave"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="@id/btnSave"
app:layout_constraintStart_toEndOf="@id/btnSave"
app:layout_constraintTop_toTopOf="@id/btnSave" />
@ -208,6 +323,12 @@
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="spProvider,etName,etHost,etPort,etUser,tilPassword,cbPrimary,cbSynchronize,btnSave" />
app:constraint_referenced_ids="spProvider,etName,etHost,etPort,etUser,tilPassword,cbPrimary,cbSynchronize,btnCheck" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvDrafts,spDrafts,tvSent,spSent,tvAll,spAll,tvTrash,spTrash,tvJunk,spJunk" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -72,6 +72,7 @@
<string name="title_synchronize_identity">Synchronize (send messages)</string>
<string name="title_primary_account">Primary (used to store drafts)</string>
<string name="title_primary_identity">Primary (default identity)</string>
<string name="title_check">Check</string>
<string name="title_no_name">Name missing</string>
<string name="title_no_email">Email address missing</string>
<string name="title_no_account">Account missing</string>
@ -79,6 +80,7 @@
<string name="title_no_port">Port number missing</string>
<string name="title_no_user">User name missing</string>
<string name="title_no_password">Password missing</string>
<string name="title_no_drafts">Drafts folder missing</string>
<string name="title_no_idle">IDLE not supported</string>
<string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string>
@ -96,7 +98,6 @@
<string name="title_folder_junk">Spam</string>
<string name="title_folder_sent">Sent</string>
<string name="title_folder_user">User</string>
<string name="title_folder_local_drafts">Local drafts</string>
<string name="title_folder_thread">Message thread</string>
<string name="title_no_messages">No messages</string>

Loading…
Cancel
Save