From 7307bc80c736f79b21940e3b249c849beb55efcb Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 21 Aug 2018 16:32:10 +0000 Subject: [PATCH] Move store sent option to account, added advanced option to use WebView --- app/schemas/eu.faircode.email.DB/1.json | 12 +++-- .../java/eu/faircode/email/EntityAccount.java | 2 + .../eu/faircode/email/FragmentAccount.java | 9 +++- .../eu/faircode/email/FragmentMessage.java | 23 +++++---- .../eu/faircode/email/FragmentOptions.java | 16 +++++-- .../eu/faircode/email/ServiceSynchronize.java | 48 ++++++++++--------- app/src/main/res/layout/fragment_account.xml | 13 ++++- app/src/main/res/layout/fragment_options.xml | 20 ++++++-- app/src/main/res/values/strings.xml | 4 +- 9 files changed, 98 insertions(+), 49 deletions(-) diff --git a/app/schemas/eu.faircode.email.DB/1.json b/app/schemas/eu.faircode.email.DB/1.json index 9a486f83..3b605476 100644 --- a/app/schemas/eu.faircode.email.DB/1.json +++ b/app/schemas/eu.faircode.email.DB/1.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "cd3cf378d6f71c13ba8beb38a8bf58cf", + "identityHash": "1d725017559c0a36b02ce447ecba45b9", "entities": [ { "tableName": "identity", @@ -125,7 +125,7 @@ }, { "tableName": "account", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `user` TEXT NOT NULL, `password` TEXT NOT NULL, `primary` INTEGER NOT NULL, `synchronize` INTEGER NOT NULL, `seen_until` INTEGER, `state` TEXT, `error` TEXT)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `user` TEXT NOT NULL, `password` TEXT NOT NULL, `primary` INTEGER NOT NULL, `synchronize` INTEGER NOT NULL, `store_sent` INTEGER NOT NULL, `seen_until` INTEGER, `state` TEXT, `error` TEXT)", "fields": [ { "fieldPath": "id", @@ -175,6 +175,12 @@ "affinity": "INTEGER", "notNull": true }, + { + "fieldPath": "store_sent", + "columnName": "store_sent", + "affinity": "INTEGER", + "notNull": true + }, { "fieldPath": "seen_until", "columnName": "seen_until", @@ -776,7 +782,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, \"cd3cf378d6f71c13ba8beb38a8bf58cf\")" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"1d725017559c0a36b02ce447ecba45b9\")" ] } } \ No newline at end of file diff --git a/app/src/main/java/eu/faircode/email/EntityAccount.java b/app/src/main/java/eu/faircode/email/EntityAccount.java index f8511959..d7c8b0cb 100644 --- a/app/src/main/java/eu/faircode/email/EntityAccount.java +++ b/app/src/main/java/eu/faircode/email/EntityAccount.java @@ -46,6 +46,8 @@ public class EntityAccount { public Boolean primary; @NonNull public Boolean synchronize; + @NonNull + public Boolean store_sent; public Long seen_until; public String state; public String error; diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 0e60d65a..dbe3bce2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -71,6 +71,7 @@ public class FragmentAccount extends FragmentEx { private TextInputLayout tilPassword; private CheckBox cbSynchronize; private CheckBox cbPrimary; + private CheckBox cbStoreSent; private Button btnCheck; private ProgressBar pbCheck; private Spinner spDrafts; @@ -104,6 +105,7 @@ public class FragmentAccount extends FragmentEx { tilPassword = view.findViewById(R.id.tilPassword); cbSynchronize = view.findViewById(R.id.cbSynchronize); cbPrimary = view.findViewById(R.id.cbPrimary); + cbStoreSent = view.findViewById(R.id.cbStoreSent); btnCheck = view.findViewById(R.id.btnCheck); pbCheck = view.findViewById(R.id.pbCheck); spDrafts = view.findViewById(R.id.spDrafts); @@ -365,6 +367,7 @@ public class FragmentAccount extends FragmentEx { args.putString("password", tilPassword.getEditText().getText().toString()); args.putBoolean("synchronize", cbSynchronize.isChecked()); args.putBoolean("primary", cbPrimary.isChecked()); + args.putBoolean("store_sent", cbStoreSent.isChecked()); args.putParcelable("drafts", drafts); args.putParcelable("sent", sent); args.putParcelable("all", all); @@ -380,6 +383,8 @@ public class FragmentAccount extends FragmentEx { String user = args.getString("user"); String password = args.getString("password"); boolean synchronize = args.getBoolean("synchronize"); + boolean primary = args.getBoolean("primary"); + boolean store_sent = args.getBoolean("store_sent"); EntityFolder drafts = args.getParcelable("drafts"); EntityFolder sent = args.getParcelable("sent"); EntityFolder all = args.getParcelable("all"); @@ -433,7 +438,8 @@ public class FragmentAccount extends FragmentEx { account.user = user; account.password = password; account.synchronize = synchronize; - account.primary = (account.synchronize && args.getBoolean("primary")); + account.primary = (account.synchronize && primary); + account.store_sent = store_sent; if (!synchronize) account.error = null; @@ -620,6 +626,7 @@ public class FragmentAccount extends FragmentEx { tilPassword.getEditText().setText(account == null ? null : account.password); cbSynchronize.setChecked(account == null ? true : account.synchronize); cbPrimary.setChecked(account == null ? true : account.primary); + cbStoreSent.setChecked(account == null ? true : account.store_sent); } else { int provider = savedInstanceState.getInt("provider"); spProvider.setTag(provider); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 05a3d7aa..4fd6d34b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -22,6 +22,7 @@ package eu.faircode.email; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Typeface; import android.net.Uri; import android.os.Bundle; @@ -105,7 +106,9 @@ public class FragmentMessage extends FragmentEx { // Get arguments Bundle args = getArguments(); final long id = (args == null ? -1 : args.getLong("id")); - debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false); + + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + debug = prefs.getBoolean("debug", false); // Get controls tvFrom = view.findViewById(R.id.tvFrom); @@ -152,14 +155,7 @@ public class FragmentMessage extends FragmentEx { if (link.length != 0) { String url = link[0].getURL(); - if (true) { - // https://developer.chrome.com/multidevice/android/customtabs - CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); - builder.setToolbarColor(Helper.resolveColor(getContext(), R.attr.colorPrimary)); - - CustomTabsIntent customTabsIntent = builder.build(); - customTabsIntent.launchUrl(getContext(), Uri.parse(url)); - } else { + if (prefs.getBoolean("webview", false)) { Bundle args = new Bundle(); args.putString("link", url); @@ -169,6 +165,13 @@ public class FragmentMessage extends FragmentEx { FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("webview"); fragmentTransaction.commit(); + } else { + // https://developer.chrome.com/multidevice/android/customtabs + CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); + builder.setToolbarColor(Helper.resolveColor(getContext(), R.attr.colorPrimary)); + + CustomTabsIntent customTabsIntent = builder.build(); + customTabsIntent.launchUrl(getContext(), Uri.parse(url)); } } return true; @@ -812,7 +815,7 @@ public class FragmentMessage extends FragmentEx { long id = args.getLong("id"); long target = args.getLong("target"); - boolean close = false; + boolean close; DB db = DB.getInstance(context); try { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 8cbaae5c..9df10cf9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -22,17 +22,20 @@ package eu.faircode.email; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.CompoundButton; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; public class FragmentOptions extends FragmentEx { - private CheckBox cbStoreSent; + private CheckBox cbWebView; + private TextView tvCustomTabs; private CheckBox cbDebug; @Override @@ -43,18 +46,19 @@ public class FragmentOptions extends FragmentEx { View view = inflater.inflate(R.layout.fragment_options, container, false); // Get controls - cbStoreSent = view.findViewById(R.id.cbStoreSent); + cbWebView = view.findViewById(R.id.cbWebView); + tvCustomTabs = view.findViewById(R.id.tvCustomTabs); cbDebug = view.findViewById(R.id.cbDebug); // Wire controls final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - cbStoreSent.setChecked(prefs.getBoolean("store_sent", false)); - cbStoreSent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + cbWebView.setChecked(prefs.getBoolean("webview", false)); + cbWebView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("store_sent", checked).apply(); + prefs.edit().putBoolean("webview", checked).apply(); } }); @@ -66,6 +70,8 @@ public class FragmentOptions extends FragmentEx { } }); + tvCustomTabs.setMovementMethod(LinkMovementMethod.getInstance()); + return view; } } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index ff5f4c7b..63e52b8a 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -28,7 +28,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; -import android.content.SharedPreferences; import android.media.RingtoneManager; import android.net.ConnectivityManager; import android.net.Network; @@ -329,6 +328,8 @@ public class ServiceSynchronize extends LifecycleService { // - "This operation is not allowed on a closed folder" // - can happen when syncing message + // MailConnectException + if (!(ex instanceof FolderClosedException) && !(ex instanceof IllegalStateException)) { String action = account + "/" + folder; NotificationManager nm = getSystemService(NotificationManager.class); @@ -918,6 +919,7 @@ public class ServiceSynchronize extends LifecycleService { private void doSend(Session isession, EntityMessage message, DB db) throws MessagingException, IOException { // Send message + EntityAccount account = db.account().getAccount(message.account); EntityIdentity ident = db.identity().getIdentity(message.identity); EntityMessage reply = (message.replying == null ? null : db.message().getMessage(message.replying)); List attachments = db.attachment().getAttachments(message.id); @@ -962,12 +964,12 @@ public class ServiceSynchronize extends LifecycleService { message.ui_seen = true; db.message().updateMessage(message); - // TODO: store sent setting per account - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (prefs.getBoolean("store_sent", false)) { + if (account.store_sent) { EntityFolder sent = db.folder().getFolderByType(ident.account, EntityFolder.SENT); if (sent != null) { - // TODO: how to handle thread? + message.folder = sent.id; + message.uid = null; + db.message().updateMessage(message); Log.i(Helper.TAG, "Appending sent msgid=" + message.msgid); EntityOperation.queue(db, message, EntityOperation.ADD); // Could already exist } @@ -1184,24 +1186,26 @@ public class ServiceSynchronize extends LifecycleService { } // Cleanup files - File messages = new File(getFilesDir(), "messages"); - for (File file : messages.listFiles()) - if (file.isFile()) { - long id = Long.parseLong(file.getName()); - if (db.message().countMessage(id) == 0) { - Log.i(Helper.TAG, "Cleanup message id=" + id); - file.delete(); + File[] messages = new File(getFilesDir(), "messages").listFiles(); + if (messages != null) + for (File file : messages) + if (file.isFile()) { + long id = Long.parseLong(file.getName()); + if (db.message().countMessage(id) == 0) { + Log.i(Helper.TAG, "Cleanup message id=" + id); + file.delete(); + } } - } - File attachments = new File(getFilesDir(), "attachments"); - for (File file : attachments.listFiles()) - if (file.isFile()) { - long id = Long.parseLong(file.getName()); - if (db.attachment().countAttachment(id) == 0) { - Log.i(Helper.TAG, "Cleanup attachment id=" + id); - file.delete(); + File[] attachments = new File(getFilesDir(), "attachments").listFiles(); + if (attachments != null) + for (File file : attachments) + if (file.isFile()) { + long id = Long.parseLong(file.getName()); + if (db.attachment().countAttachment(id) == 0) { + Log.i(Helper.TAG, "Cleanup attachment id=" + id); + file.delete(); + } } - } Log.w(Helper.TAG, folder.name + " statistics added=" + added + " updated=" + updated + " unchanged=" + unchanged); } finally { @@ -1256,7 +1260,7 @@ public class ServiceSynchronize extends LifecycleService { Log.i(Helper.TAG, folder.name + " found as id=" + dup.id + " uid=" + dup.uid + " msgid=" + msgid); dup.folder = folder.id; dup.uid = uid; - if (outbox) // only now the uid is known + if (TextUtils.isEmpty(dup.thread)) // outbox: only now the uid is known dup.thread = helper.getThreadId(uid); db.message().updateMessage(dup); message = dup; diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index e230b0c6..517c870e 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -176,6 +176,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbSynchronize" /> + +