Allow editing sender address

This commit is contained in:
M66B
2018-11-09 07:22:44 +00:00
parent 5da84fe63e
commit 2f93775420
11 changed files with 1181 additions and 6 deletions

View File

@@ -45,7 +45,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 25,
version = 26,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -298,6 +298,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `account` ADD COLUMN `created` INTEGER");
}
})
.addMigrations(new Migration(25, 26) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `extra` TEXT");
}
})
.build();
}

View File

@@ -76,6 +76,7 @@ public class EntityMessage implements Serializable {
@NonNull
public Long folder;
public Long identity;
public String extra; // plus
public Long replying;
public Long uid; // compose = null
public String msgid;

View File

@@ -34,6 +34,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.OpenableColumns;
import android.text.Html;
@@ -53,6 +54,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
@@ -110,6 +112,9 @@ public class FragmentCompose extends FragmentEx {
private ViewGroup view;
private Spinner spFrom;
private ImageView ivIdentityAdd;
private TextView tvExtraPrefix;
private EditText etExtra;
private TextView tvExtraSuffix;
private MultiAutoCompleteTextView etTo;
private ImageView ivToAdd;
private MultiAutoCompleteTextView etCc;
@@ -123,6 +128,7 @@ public class FragmentCompose extends FragmentEx {
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait;
private Group grpHeader;
private Group grpExtra;
private Group grpAddresses;
private Group grpAttachments;
@@ -141,6 +147,9 @@ public class FragmentCompose extends FragmentEx {
// Get controls
spFrom = view.findViewById(R.id.spFrom);
ivIdentityAdd = view.findViewById(R.id.ivIdentityAdd);
tvExtraPrefix = view.findViewById(R.id.tvExtraPrefix);
etExtra = view.findViewById(R.id.etExtra);
tvExtraSuffix = view.findViewById(R.id.tvExtraSuffix);
etTo = view.findViewById(R.id.etTo);
ivToAdd = view.findViewById(R.id.ivToAdd);
etCc = view.findViewById(R.id.etCc);
@@ -154,10 +163,26 @@ public class FragmentCompose extends FragmentEx {
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpHeader = view.findViewById(R.id.grpHeader);
grpExtra = view.findViewById(R.id.grpExtra);
grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments);
// Wire controls
spFrom.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
EntityIdentity identity = (EntityIdentity) parent.getAdapter().getItem(position);
int at = (identity == null ? -1 : identity.email.indexOf('@'));
tvExtraPrefix.setText(at < 0 ? null : identity.email.substring(0, at) + "+");
tvExtraSuffix.setText(at < 0 ? null : identity.email.substring(at));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
tvExtraPrefix.setText(null);
tvExtraSuffix.setText(null);
}
});
ivIdentityAdd.setOnClickListener(new View.OnClickListener() {
@Override
@@ -247,7 +272,11 @@ public class FragmentCompose extends FragmentEx {
setHasOptionsMenu(true);
// Initialize
tvExtraPrefix.setText(null);
tvExtraSuffix.setText(null);
grpHeader.setVisibility(View.GONE);
grpExtra.setVisibility(View.GONE);
grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
etBody.setVisibility(View.GONE);
@@ -858,6 +887,7 @@ public class FragmentCompose extends FragmentEx {
args.putLong("id", working);
args.putInt("action", action);
args.putLong("identity", identity == null ? -1 : identity.id);
args.putString("extra", etExtra.getText().toString());
args.putString("to", etTo.getText().toString());
args.putString("cc", etCc.getText().toString());
args.putString("bcc", etBcc.getText().toString());
@@ -1221,6 +1251,7 @@ public class FragmentCompose extends FragmentEx {
setSubtitle(getString(R.string.title_compose, result.account.name));
etExtra.setText(result.draft.extra);
etTo.setText(MessageHelper.getFormattedAddresses(result.draft.to, true));
etCc.setText(MessageHelper.getFormattedAddresses(result.draft.cc, true));
etBcc.setText(MessageHelper.getFormattedAddresses(result.draft.bcc, true));
@@ -1256,8 +1287,11 @@ public class FragmentCompose extends FragmentEx {
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
boolean sender = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("sender", false);
pbWait.setVisibility(View.GONE);
grpHeader.setVisibility(View.VISIBLE);
grpExtra.setVisibility(sender ? View.VISIBLE : View.GONE);
grpAddresses.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
etBody.setVisibility(View.VISIBLE);
edit_bar.setVisibility(View.VISIBLE);
@@ -1361,6 +1395,7 @@ public class FragmentCompose extends FragmentEx {
long id = args.getLong("id");
int action = args.getInt("action");
long iid = args.getLong("identity");
String extra = args.getString("extra");
String to = args.getString("to");
String cc = args.getString("cc");
String bcc = args.getString("bcc");
@@ -1389,8 +1424,12 @@ public class FragmentCompose extends FragmentEx {
InternetAddress acc[] = (TextUtils.isEmpty(cc) ? null : InternetAddress.parse(cc));
InternetAddress abcc[] = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parse(bcc));
if (TextUtils.isEmpty(extra))
extra = null;
// Update draft
draft.identity = (identity == null ? null : identity.id);
draft.extra = extra;
draft.from = afrom;
draft.to = ato;
draft.cc = acc;

View File

@@ -50,6 +50,7 @@ public class FragmentOptions extends FragmentEx {
private SwitchCompat swBrowse;
private SwitchCompat swSwipe;
private SwitchCompat swNav;
private SwitchCompat swSender;
private SwitchCompat swInsecure;
private Spinner spDownload;
private SwitchCompat swDebug;
@@ -71,6 +72,7 @@ public class FragmentOptions extends FragmentEx {
swBrowse = view.findViewById(R.id.swBrowse);
swSwipe = view.findViewById(R.id.swSwipe);
swNav = view.findViewById(R.id.swNav);
swSender = view.findViewById(R.id.swSender);
swInsecure = view.findViewById(R.id.swInsecure);
spDownload = view.findViewById(R.id.spDownload);
swDebug = view.findViewById(R.id.swDebug);
@@ -185,6 +187,14 @@ public class FragmentOptions extends FragmentEx {
}
});
swSender.setChecked(prefs.getBoolean("sender", true));
swSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sender", checked).apply();
}
});
swInsecure.setChecked(prefs.getBoolean("insecure", false));
swInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

View File

@@ -114,6 +114,7 @@ public class FragmentSetup extends FragmentEx {
"browse",
"swipe",
"navigation",
"sender",
"insecure",
"sort"
);

View File

@@ -183,8 +183,16 @@ public class MessageHelper {
imessage.setFlag(Flags.Flag.SEEN, message.seen);
if (message.from != null && message.from.length > 0)
imessage.setFrom(message.from[0]);
if (message.from != null && message.from.length > 0) {
String email = ((InternetAddress) message.from[0]).getAddress();
String name = ((InternetAddress) message.from[0]).getPersonal();
if (email != null && !TextUtils.isEmpty(message.extra)) {
int at = email.indexOf('@');
email = email.substring(0, at) + "+" + message.extra + email.substring(at);
Log.i(Helper.TAG, "extra=" + email);
}
imessage.setFrom(new InternetAddress(email, name));
}
if (message.to != null && message.to.length > 0)
imessage.setRecipients(Message.RecipientType.TO, message.to);