mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 03:19:24 +01:00
Move store sent option to account, added advanced option to use WebView
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EntityAttachment> 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;
|
||||
|
||||
Reference in New Issue
Block a user