Added option for signatures

Fixes #58
This commit is contained in:
M66B
2018-09-07 08:44:48 +00:00
parent 5382b0c022
commit f5e67369ee
9 changed files with 1017 additions and 20 deletions

View File

@@ -34,7 +34,7 @@ import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
public class ActivitySetup extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
public class ActivitySetup extends ActivityBilling implements FragmentManager.OnBackStackChangedListener {
private boolean hasAccount;
static final int REQUEST_PERMISSION = 1;

View File

@@ -45,7 +45,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 10,
version = 11,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -184,6 +184,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("UPDATE `folder` SET unified = 1 WHERE type = '" + EntityFolder.INBOX + "'");
}
})
.addMigrations(new Migration(10, 11) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `signature` TEXT");
}
})
.build();
}

View File

@@ -34,6 +34,7 @@ public class EntityAccount {
@PrimaryKey(autoGenerate = true)
public Long id;
public String name;
public String signature;
@NonNull
public String host; // IMAP
@NonNull

View File

@@ -29,6 +29,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -49,6 +50,7 @@ import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
@@ -73,6 +75,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import static android.accounts.AccountManager.newChooseAccountIntent;
@@ -87,6 +90,8 @@ public class FragmentAccount extends FragmentEx {
private TextInputLayout tilPassword;
private Button btnAdvanced;
private EditText etName;
private TextView tvSignaturePro;
private EditText etSignature;
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private Button btnCheck;
@@ -135,6 +140,8 @@ public class FragmentAccount extends FragmentEx {
btnAdvanced = view.findViewById(R.id.btnAdvanced);
etName = view.findViewById(R.id.etName);
tvSignaturePro = view.findViewById(R.id.tvSignaturePro);
etSignature = view.findViewById(R.id.etSignature);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
@@ -241,6 +248,16 @@ public class FragmentAccount extends FragmentEx {
}
});
tvSignaturePro.setPaintFlags(tvSignaturePro.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvSignaturePro.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
fragmentTransaction.commit();
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -465,13 +482,14 @@ public class FragmentAccount extends FragmentEx {
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.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putString("name", etName.getText().toString());
args.putString("signature", etSignature.getText().toString());
args.putBoolean("primary", cbPrimary.isChecked());
args.putParcelable("drafts", drafts);
args.putParcelable("sent", sent);
@@ -482,12 +500,13 @@ public class FragmentAccount extends FragmentEx {
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
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");
int auth_type = args.getInt("auth_type");
String name = args.getString("name");
String signature = args.getString("signature");
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
EntityFolder drafts = args.getParcelable("drafts");
@@ -536,6 +555,7 @@ public class FragmentAccount extends FragmentEx {
if (account == null)
account = new EntityAccount();
account.name = name;
account.signature = signature;
account.host = host;
account.port = Integer.parseInt(port);
account.user = user;
@@ -748,6 +768,7 @@ public class FragmentAccount extends FragmentEx {
tilPassword.getEditText().setText(account == null ? null : account.password);
etName.setText(account == null ? null : account.name);
etSignature.setText(account == null ? null : account.signature);
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);

View File

@@ -27,6 +27,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.OpenableColumns;
import android.text.Html;
@@ -605,11 +606,11 @@ public class FragmentCompose extends FragmentEx {
protected EntityMessage onLoad(Context context, Bundle args) throws IOException {
String action = args.getString("action");
long id = args.getLong("id", -1);
long account = args.getLong("account", -1);
long reference = args.getLong("reference", -1);
long answer = args.getLong("answer", -1);
boolean pro = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("pro", false);
Log.i(Helper.TAG, "Load draft action=" + action + " id=" + id + " account=" + account + " reference=" + reference);
Log.i(Helper.TAG, "Load draft action=" + action + " id=" + id + " reference=" + reference);
EntityMessage draft;
@@ -624,16 +625,18 @@ public class FragmentCompose extends FragmentEx {
} else
return draft;
EntityAccount account;
EntityMessage ref = db.message().getMessage(reference);
if (ref == null) {
if (account < 0) {
EntityAccount a = db.account().getPrimaryAccount();
if (a == null)
long aid = args.getLong("account", -1);
if (aid < 0) {
account = db.account().getPrimaryAccount();
if (account == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_account));
account = a.id;
}
} else
account = db.account().getAccount(aid);
} else {
account = ref.account;
account = db.account().getAccount(ref.account);
// Reply to recipient, not to known self
if (ref.from != null && ref.from.length > 0) {
@@ -654,7 +657,7 @@ public class FragmentCompose extends FragmentEx {
}
EntityFolder drafts;
drafts = db.folder().getFolderByType(account, EntityFolder.DRAFTS);
drafts = db.folder().getFolderByType(account.id, EntityFolder.DRAFTS);
if (drafts == null)
drafts = db.folder().getPrimaryDrafts();
if (drafts == null)
@@ -663,7 +666,7 @@ public class FragmentCompose extends FragmentEx {
String body = "";
draft = new EntityMessage();
draft.account = account;
draft.account = account.id;
draft.folder = drafts.id;
draft.msgid = EntityMessage.generateMessageId(); // for multiple appends
@@ -691,8 +694,13 @@ public class FragmentCompose extends FragmentEx {
draft.subject = args.getString("subject");
body = args.getString("body");
if (!TextUtils.isEmpty(body))
body = "<pre>" + body.replaceAll("\\r?\\n", "<br />") + "</pre>";
if (body == null)
body = "";
else
body = body.replaceAll("\\r?\\n", "<br />");
if (pro && !TextUtils.isEmpty(account.signature))
body = "<br>" + account.signature + "<br>" + body;
} else {
draft.thread = ref.thread;
@@ -742,6 +750,9 @@ public class FragmentCompose extends FragmentEx {
Html.escapeHtml(MessageHelper.getFormattedAddresses(ref.from, true)),
HtmlHelper.sanitize(context, ref.read(context), true));
}
if (pro && !TextUtils.isEmpty(account.signature))
body = "<br>" + account.signature + "<br>" + body;
}
draft.received = new Date().getTime();