Refactoring

pull/147/head
M66B 6 years ago
parent bb1e697c41
commit 3b06c3d027

@ -150,138 +150,151 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
return; return;
final EntityAttachment attachment = filtered.get(pos); final EntityAttachment attachment = filtered.get(pos);
if (view.getId() == R.id.ivDelete) { if (view.getId() == R.id.ivDelete)
Bundle args = new Bundle(); onDelete(attachment);
args.putLong("id", attachment.id); else if (view.getId() == R.id.ivSave)
onSave(attachment);
else {
if (attachment.available)
onShare(attachment);
else {
if (attachment.progress == null)
onDownload(attachment);
}
}
}
new SimpleTask<Void>() { private void onDelete(final EntityAttachment attachment) {
@Override Bundle args = new Bundle();
protected Void onExecute(Context context, Bundle args) { args.putLong("id", attachment.id);
DB.getInstance(context).attachment().deleteAttachment(attachment.id);
EntityAttachment.getFile(context, attachment.id).delete(); new SimpleTask<Void>() {
return null; @Override
} protected Void onExecute(Context context, Bundle args) {
DB.getInstance(context).attachment().deleteAttachment(attachment.id);
EntityAttachment.getFile(context, attachment.id).delete();
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "attachment:delete");
}
private void onSave(EntityAttachment attachment) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_STORE_ATTACHMENT)
.putExtra("id", attachment.id)
.putExtra("name", attachment.name)
.putExtra("type", attachment.type));
}
private void onShare(EntityAttachment attachment) {
// Build file name
File file = EntityAttachment.getFile(context, attachment.id);
// https://developer.android.com/reference/android/support/v4/content/FileProvider
final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Log.i("uri=" + uri);
// Build intent
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, attachment.type);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!TextUtils.isEmpty(attachment.name))
intent.putExtra(Intent.EXTRA_TITLE, attachment.name);
Log.i("Sharing " + file + " type=" + attachment.type);
Log.i("Intent=" + intent);
// Get targets
PackageManager pm = context.getPackageManager();
List<NameResolveInfo> targets = new ArrayList<>();
List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo ri : ris) {
if ("com.adobe.reader".equals(ri.activityInfo.packageName))
Toast.makeText(context, R.string.title_no_adobe, Toast.LENGTH_LONG).show();
Log.i("Target=" + ri);
context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
targets.add(new NameResolveInfo(
pm.getApplicationIcon(ri.activityInfo.applicationInfo),
pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(),
ri));
}
// Check if viewer available
if (ris.size() == 0) {
Toast.makeText(context, context.getString(R.string.title_no_viewer, attachment.type), Toast.LENGTH_LONG).show();
return;
}
if (confirm) {
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null);
final AlertDialog dialog = new DialogBuilderLifecycle(context, owner)
.setView(dview)
.setNegativeButton(android.R.string.cancel, null)
.create();
TextView tvName = dview.findViewById(R.id.tvName);
TextView tvType = dview.findViewById(R.id.tvType);
ListView lvApp = dview.findViewById(R.id.lvApp);
tvName.setText(attachment.name);
tvType.setText(attachment.type);
lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
protected void onException(Bundle args, Throwable ex) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Helper.unexpectedError(context, owner, ex); NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position);
intent.setPackage(selected.info.activityInfo.packageName);
context.startActivity(intent);
dialog.dismiss();
} }
}.execute(context, owner, args, "attachment:delete"); });
} else if (view.getId() == R.id.ivSave) { dialog.show();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); } else
lbm.sendBroadcast( context.startActivity(intent);
new Intent(ActivityView.ACTION_STORE_ATTACHMENT) }
.putExtra("id", attachment.id)
.putExtra("name", attachment.name)
.putExtra("type", attachment.type));
} else { private void onDownload(EntityAttachment attachment) {
if (attachment.available) { Bundle args = new Bundle();
// Build file name args.putLong("id", attachment.id);
File file = EntityAttachment.getFile(context, attachment.id); args.putLong("message", attachment.message);
args.putInt("sequence", attachment.sequence);
// https://developer.android.com/reference/android/support/v4/content/FileProvider
final Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Log.i("uri=" + uri);
// Build intent
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, attachment.type);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!TextUtils.isEmpty(attachment.name))
intent.putExtra(Intent.EXTRA_TITLE, attachment.name);
Log.i("Sharing " + file + " type=" + attachment.type);
Log.i("Intent=" + intent);
// Get targets
PackageManager pm = context.getPackageManager();
List<NameResolveInfo> targets = new ArrayList<>();
List<ResolveInfo> ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo ri : ris) {
if ("com.adobe.reader".equals(ri.activityInfo.packageName))
Toast.makeText(context, R.string.title_no_adobe, Toast.LENGTH_LONG).show();
Log.i("Target=" + ri);
context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
targets.add(new NameResolveInfo(
pm.getApplicationIcon(ri.activityInfo.applicationInfo),
pm.getApplicationLabel(ri.activityInfo.applicationInfo).toString(),
ri));
}
// Check if viewer available new SimpleTask<Void>() {
if (ris.size() == 0) { @Override
Toast.makeText(context, context.getString(R.string.title_no_viewer, attachment.type), Toast.LENGTH_LONG).show(); protected Void onExecute(Context context, Bundle args) {
return; long id = args.getLong("id");
} long message = args.getLong("message");
long sequence = args.getInt("sequence");
if (confirm) { DB db = DB.getInstance(context);
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_attachment, null); try {
final AlertDialog dialog = new DialogBuilderLifecycle(context, owner) db.beginTransaction();
.setView(dview)
.setNegativeButton(android.R.string.cancel, null) db.attachment().setProgress(id, 0);
.create();
EntityMessage msg = db.message().getMessage(message);
TextView tvName = dview.findViewById(R.id.tvName); EntityOperation.queue(context, db, msg, EntityOperation.ATTACHMENT, sequence);
TextView tvType = dview.findViewById(R.id.tvType);
ListView lvApp = dview.findViewById(R.id.lvApp); db.setTransactionSuccessful();
} finally {
tvName.setText(attachment.name); db.endTransaction();
tvType.setText(attachment.type);
lvApp.setAdapter(new TargetAdapter(context, R.layout.item_target, targets));
lvApp.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
NameResolveInfo selected = (NameResolveInfo) parent.getItemAtPosition(position);
intent.setPackage(selected.info.activityInfo.packageName);
context.startActivity(intent);
dialog.dismiss();
}
});
dialog.show();
} else
context.startActivity(intent);
} else {
if (attachment.progress == null) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
args.putLong("message", attachment.message);
args.putInt("sequence", attachment.sequence);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
long message = args.getLong("message");
long sequence = args.getInt("sequence");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
db.attachment().setProgress(id, 0);
EntityMessage msg = db.message().getMessage(message);
EntityOperation.queue(context, db, msg, EntityOperation.ATTACHMENT, sequence);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "attachment:fetch");
} }
return null;
} }
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "attachment:fetch");
} }
private class NameResolveInfo { private class NameResolveInfo {

File diff suppressed because it is too large Load Diff

@ -126,150 +126,154 @@ public class FragmentFolder extends FragmentBase {
btnSave.setOnClickListener(new View.OnClickListener() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Bundle args = new Bundle(); onSave();
args.putLong("id", id); }
args.putLong("account", account); });
args.putString("name", etName.getText().toString());
args.putString("display", etDisplay.getText().toString());
args.putBoolean("hide", cbHide.isChecked());
args.putBoolean("unified", cbUnified.isChecked());
args.putBoolean("notify", cbNotify.getVisibility() == View.VISIBLE && cbNotify.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("poll", cbPoll.isChecked());
args.putBoolean("download", cbDownload.isChecked());
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked()
? Integer.toString(Integer.MAX_VALUE)
: etKeepDays.getText().toString());
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
}
@Override // Initialize
protected void onPostExecute(Bundle args) { Helper.setViewsEnabled(view, false);
Helper.setViewsEnabled(view, true); btnSave.setEnabled(false);
btnSave.setEnabled(true); pbSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE);
}
@Override return view;
protected Void onExecute(Context context, Bundle args) { }
long id = args.getLong("id");
long aid = args.getLong("account");
String name = args.getString("name");
String display = args.getString("display");
boolean hide = args.getBoolean("hide");
boolean unified = args.getBoolean("unified");
boolean notify = args.getBoolean("notify");
boolean synchronize = args.getBoolean("synchronize");
boolean poll = args.getBoolean("poll");
boolean download = args.getBoolean("download");
String sync = args.getString("sync");
String keep = args.getString("keep");
if (TextUtils.isEmpty(display) || display.equals(name))
display = null;
int sync_days = (TextUtils.isEmpty(sync) ? EntityFolder.DEFAULT_SYNC : Integer.parseInt(sync));
int keep_days = (TextUtils.isEmpty(keep) ? EntityFolder.DEFAULT_KEEP : Integer.parseInt(keep));
if (keep_days < sync_days)
keep_days = sync_days;
boolean reload;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityFolder folder = db.folder().getFolder(id);
if (folder == null) {
reload = true;
Log.i("Creating folder=" + name);
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(getString(R.string.title_folder_name_missing));
EntityFolder create = new EntityFolder();
create.account = aid;
create.name = name;
create.level = 0;
create.display = display;
create.hide = hide;
create.type = EntityFolder.USER;
create.unified = unified;
create.notify = notify;
create.synchronize = synchronize;
create.poll = poll;
create.download = download;
create.sync_days = sync_days;
create.keep_days = keep_days;
create.tbc = true;
db.folder().insertFolder(create);
} else {
reload = (!folder.synchronize.equals(synchronize) ||
!folder.poll.equals(poll));
Calendar cal_keep = Calendar.getInstance();
cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days);
cal_keep.set(Calendar.HOUR_OF_DAY, 12);
cal_keep.set(Calendar.MINUTE, 0);
cal_keep.set(Calendar.SECOND, 0);
cal_keep.set(Calendar.MILLISECOND, 0);
long keep_time = cal_keep.getTimeInMillis();
if (keep_time < 0)
keep_time = 0;
Log.i("Updating folder=" + name);
db.folder().setFolderProperties(id,
display, unified, notify, hide,
synchronize, poll, download,
sync_days, keep_days);
db.folder().setFolderError(id, null);
db.message().deleteMessagesBefore(id, keep_time, true);
EntityOperation.sync(db, folder.id);
}
db.setTransactionSuccessful(); private void onSave() {
} finally { Bundle args = new Bundle();
db.endTransaction(); args.putLong("id", id);
} args.putLong("account", account);
args.putString("name", etName.getText().toString());
args.putString("display", etDisplay.getText().toString());
args.putBoolean("hide", cbHide.isChecked());
args.putBoolean("unified", cbUnified.isChecked());
args.putBoolean("notify", cbNotify.getVisibility() == View.VISIBLE && cbNotify.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("poll", cbPoll.isChecked());
args.putBoolean("download", cbDownload.isChecked());
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked()
? Integer.toString(Integer.MAX_VALUE)
: etKeepDays.getText().toString());
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
}
if (reload) @Override
ServiceSynchronize.reload(context, "save folder"); protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
return null; @Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
long aid = args.getLong("account");
String name = args.getString("name");
String display = args.getString("display");
boolean hide = args.getBoolean("hide");
boolean unified = args.getBoolean("unified");
boolean notify = args.getBoolean("notify");
boolean synchronize = args.getBoolean("synchronize");
boolean poll = args.getBoolean("poll");
boolean download = args.getBoolean("download");
String sync = args.getString("sync");
String keep = args.getString("keep");
if (TextUtils.isEmpty(display) || display.equals(name))
display = null;
int sync_days = (TextUtils.isEmpty(sync) ? EntityFolder.DEFAULT_SYNC : Integer.parseInt(sync));
int keep_days = (TextUtils.isEmpty(keep) ? EntityFolder.DEFAULT_KEEP : Integer.parseInt(keep));
if (keep_days < sync_days)
keep_days = sync_days;
boolean reload;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityFolder folder = db.folder().getFolder(id);
if (folder == null) {
reload = true;
Log.i("Creating folder=" + name);
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(getString(R.string.title_folder_name_missing));
EntityFolder create = new EntityFolder();
create.account = aid;
create.name = name;
create.level = 0;
create.display = display;
create.hide = hide;
create.type = EntityFolder.USER;
create.unified = unified;
create.notify = notify;
create.synchronize = synchronize;
create.poll = poll;
create.download = download;
create.sync_days = sync_days;
create.keep_days = keep_days;
create.tbc = true;
db.folder().insertFolder(create);
} else {
reload = (!folder.synchronize.equals(synchronize) ||
!folder.poll.equals(poll));
Calendar cal_keep = Calendar.getInstance();
cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days);
cal_keep.set(Calendar.HOUR_OF_DAY, 12);
cal_keep.set(Calendar.MINUTE, 0);
cal_keep.set(Calendar.SECOND, 0);
cal_keep.set(Calendar.MILLISECOND, 0);
long keep_time = cal_keep.getTimeInMillis();
if (keep_time < 0)
keep_time = 0;
Log.i("Updating folder=" + name);
db.folder().setFolderProperties(id,
display, unified, notify, hide,
synchronize, poll, download,
sync_days, keep_days);
db.folder().setFolderError(id, null);
db.message().deleteMessagesBefore(id, keep_time, true);
EntityOperation.sync(db, folder.id);
} }
@Override db.setTransactionSuccessful();
protected void onExecuted(Bundle args, Void data) { } finally {
getFragmentManager().popBackStack(); db.endTransaction();
} }
@Override if (reload)
protected void onException(Bundle args, Throwable ex) { ServiceSynchronize.reload(context, "save folder");
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); return null;
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentFolder.this, args, "folder:save");
} }
});
// Initialize @Override
Helper.setViewsEnabled(view, false); protected void onExecuted(Bundle args, Void data) {
btnSave.setEnabled(false); getFragmentManager().popBackStack();
pbSave.setVisibility(View.GONE); }
pbWait.setVisibility(View.VISIBLE);
return view; @Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentFolder.this, args, "folder:save");
} }
@Override @Override

@ -382,46 +382,7 @@ public class FragmentIdentity extends FragmentBase {
btnAutoConfig.setOnClickListener(new View.OnClickListener() { btnAutoConfig.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
etDomain.setEnabled(false); onAutoConfig();
btnAutoConfig.setEnabled(false);
Bundle args = new Bundle();
args.putString("domain", etDomain.getText().toString());
new SimpleTask<EmailProvider>() {
@Override
protected void onPreExecute(Bundle args) {
etDomain.setEnabled(false);
btnAutoConfig.setEnabled(false);
}
@Override
protected void onPostExecute(Bundle args) {
etDomain.setEnabled(true);
btnAutoConfig.setEnabled(true);
}
@Override
protected EmailProvider onExecute(Context context, Bundle args) throws Throwable {
String domain = args.getString("domain");
return EmailProvider.fromDomain(context, domain);
}
@Override
protected void onExecuted(Bundle args, EmailProvider provider) {
etHost.setText(provider.smtp_host);
etPort.setText(Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.smtp_starttls);
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentIdentity.this, args, "identity:config");
} }
}); });
@ -442,224 +403,7 @@ public class FragmentIdentity extends FragmentBase {
btnSave.setOnClickListener(new View.OnClickListener() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
EntityAccount account = (EntityAccount) spAccount.getSelectedItem(); onSave();
String name = etName.getText().toString();
if (TextUtils.isEmpty(name)) {
CharSequence hint = etName.getHint();
if (!TextUtils.isEmpty(hint))
name = hint.toString();
}
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", name);
args.putString("email", etEmail.getText().toString().trim());
args.putString("display", etDisplay.getText().toString());
args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked());
args.putBoolean("read_receipt", cbReadReceipt.isChecked());
args.putLong("account", account == null ? -1 : account.id);
args.putInt("auth_type", account == null || account.auth_type == null ? Helper.AUTH_TYPE_PASSWORD : account.auth_type);
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putString("realm", etRealm.getText().toString());
args.putInt("color", color);
args.putString("signature", Html.toHtml(etSignature.getText()));
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putSerializable("sent", (EntityFolder) spSent.getSelectedItem());
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
tvError.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
String name = args.getString("name");
String email = args.getString("email");
long account = args.getLong("account");
String display = args.getString("display");
Integer color = args.getInt("color");
String signature = args.getString("signature");
int auth_type = args.getInt("auth_type");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
String realm = args.getString("realm");
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
String replyto = args.getString("replyto");
String bcc = args.getString("bcc");
boolean delivery_receipt = args.getBoolean("delivery_receipt");
boolean read_receipt = args.getBoolean("read_receipt");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(context.getString(R.string.title_no_email));
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid));
if (TextUtils.isEmpty(host))
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
port = (starttls ? "587" : "465");
if (TextUtils.isEmpty(user))
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
if (synchronize && TextUtils.isEmpty(password) && !insecure)
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
email = email.toLowerCase();
if (TextUtils.isEmpty(display))
display = null;
if (TextUtils.isEmpty(realm))
realm = null;
if (TextUtils.isEmpty(replyto))
replyto = null;
else
replyto = replyto.toLowerCase();
if (TextUtils.isEmpty(bcc))
bcc = null;
else
bcc = bcc.toLowerCase();
if (Color.TRANSPARENT == color)
color = null;
DB db = DB.getInstance(context);
EntityIdentity identity = db.identity().getIdentity(id);
String identityRealm = (identity == null ? null : identity.realm);
boolean check = (synchronize && (identity == null ||
!host.equals(identity.host) || Integer.parseInt(port) != identity.port ||
!user.equals(identity.user) || !password.equals(identity.password) ||
realm == null ? identityRealm != null : !realm.equals(identityRealm)));
boolean reload = (identity == null || identity.synchronize != synchronize || check);
// Check SMTP server
if (check) {
String transportType = (starttls ? "smtp" : "smtps");
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Transport itransport = isession.getTransport(transportType);
try {
try {
itransport.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
itransport.connect(host, Integer.parseInt(port), user, password);
} else
throw ex;
}
} finally {
itransport.close();
}
}
try {
db.beginTransaction();
boolean update = (identity != null);
if (identity == null)
identity = new EntityIdentity();
identity.name = name;
identity.email = email;
identity.account = account;
identity.display = display;
identity.color = color;
identity.signature = signature;
identity.auth_type = auth_type;
identity.host = host;
identity.starttls = starttls;
identity.insecure = insecure;
identity.port = Integer.parseInt(port);
identity.user = user;
identity.password = password;
identity.realm = realm;
identity.synchronize = synchronize;
identity.primary = (identity.synchronize && primary);
identity.replyto = replyto;
identity.bcc = bcc;
identity.delivery_receipt = delivery_receipt;
identity.read_receipt = read_receipt;
identity.store_sent = false;
identity.sent_folder = (sent == null ? null : sent.id);
identity.error = null;
if (identity.primary)
db.identity().resetPrimary(account);
if (update)
db.identity().updateIdentity(identity);
else
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (reload)
ServiceSynchronize.reload(context, "save identity");
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else {
tvError.setText(Helper.formatThrowable(ex));
tvError.setVisibility(View.VISIBLE);
new Handler().post(new Runnable() {
@Override
public void run() {
((ScrollView) view).smoothScrollTo(0, tvError.getBottom());
}
});
}
}
}.execute(FragmentIdentity.this, args, "identity:save");
} }
}); });
@ -683,6 +427,270 @@ public class FragmentIdentity extends FragmentBase {
return view; return view;
} }
private void onAutoConfig() {
etDomain.setEnabled(false);
btnAutoConfig.setEnabled(false);
Bundle args = new Bundle();
args.putString("domain", etDomain.getText().toString());
new SimpleTask<EmailProvider>() {
@Override
protected void onPreExecute(Bundle args) {
etDomain.setEnabled(false);
btnAutoConfig.setEnabled(false);
}
@Override
protected void onPostExecute(Bundle args) {
etDomain.setEnabled(true);
btnAutoConfig.setEnabled(true);
}
@Override
protected EmailProvider onExecute(Context context, Bundle args) throws Throwable {
String domain = args.getString("domain");
return EmailProvider.fromDomain(context, domain);
}
@Override
protected void onExecuted(Bundle args, EmailProvider provider) {
etHost.setText(provider.smtp_host);
etPort.setText(Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.smtp_starttls);
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentIdentity.this, args, "identity:config");
}
private void onSave() {
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
String name = etName.getText().toString();
if (TextUtils.isEmpty(name)) {
CharSequence hint = etName.getHint();
if (!TextUtils.isEmpty(hint))
name = hint.toString();
}
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", name);
args.putString("email", etEmail.getText().toString().trim());
args.putString("display", etDisplay.getText().toString());
args.putString("replyto", etReplyTo.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putBoolean("delivery_receipt", cbDeliveryReceipt.isChecked());
args.putBoolean("read_receipt", cbReadReceipt.isChecked());
args.putLong("account", account == null ? -1 : account.id);
args.putInt("auth_type", account == null || account.auth_type == null ? Helper.AUTH_TYPE_PASSWORD : account.auth_type);
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putString("realm", etRealm.getText().toString());
args.putInt("color", color);
args.putString("signature", Html.toHtml(etSignature.getText()));
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putSerializable("sent", (EntityFolder) spSent.getSelectedItem());
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
tvError.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
String name = args.getString("name");
String email = args.getString("email");
long account = args.getLong("account");
String display = args.getString("display");
Integer color = args.getInt("color");
String signature = args.getString("signature");
int auth_type = args.getInt("auth_type");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
String realm = args.getString("realm");
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
String replyto = args.getString("replyto");
String bcc = args.getString("bcc");
boolean delivery_receipt = args.getBoolean("delivery_receipt");
boolean read_receipt = args.getBoolean("read_receipt");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(context.getString(R.string.title_no_email));
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid));
if (TextUtils.isEmpty(host))
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
port = (starttls ? "587" : "465");
if (TextUtils.isEmpty(user))
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
if (synchronize && TextUtils.isEmpty(password) && !insecure)
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
email = email.toLowerCase();
if (TextUtils.isEmpty(display))
display = null;
if (TextUtils.isEmpty(realm))
realm = null;
if (TextUtils.isEmpty(replyto))
replyto = null;
else
replyto = replyto.toLowerCase();
if (TextUtils.isEmpty(bcc))
bcc = null;
else
bcc = bcc.toLowerCase();
if (Color.TRANSPARENT == color)
color = null;
DB db = DB.getInstance(context);
EntityIdentity identity = db.identity().getIdentity(id);
String identityRealm = (identity == null ? null : identity.realm);
boolean check = (synchronize && (identity == null ||
!host.equals(identity.host) || Integer.parseInt(port) != identity.port ||
!user.equals(identity.user) || !password.equals(identity.password) ||
realm == null ? identityRealm != null : !realm.equals(identityRealm)));
boolean reload = (identity == null || identity.synchronize != synchronize || check);
// Check SMTP server
if (check) {
String transportType = (starttls ? "smtp" : "smtps");
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Transport itransport = isession.getTransport(transportType);
try {
try {
itransport.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
itransport.connect(host, Integer.parseInt(port), user, password);
} else
throw ex;
}
} finally {
itransport.close();
}
}
try {
db.beginTransaction();
boolean update = (identity != null);
if (identity == null)
identity = new EntityIdentity();
identity.name = name;
identity.email = email;
identity.account = account;
identity.display = display;
identity.color = color;
identity.signature = signature;
identity.auth_type = auth_type;
identity.host = host;
identity.starttls = starttls;
identity.insecure = insecure;
identity.port = Integer.parseInt(port);
identity.user = user;
identity.password = password;
identity.realm = realm;
identity.synchronize = synchronize;
identity.primary = (identity.synchronize && primary);
identity.replyto = replyto;
identity.bcc = bcc;
identity.delivery_receipt = delivery_receipt;
identity.read_receipt = read_receipt;
identity.store_sent = false;
identity.sent_folder = (sent == null ? null : sent.id);
identity.error = null;
if (identity.primary)
db.identity().resetPrimary(account);
if (update)
db.identity().updateIdentity(identity);
else
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (reload)
ServiceSynchronize.reload(context, "save identity");
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else {
tvError.setText(Helper.formatThrowable(ex));
tvError.setVisibility(View.VISIBLE);
new Handler().post(new Runnable() {
@Override
public void run() {
((ScrollView) view).smoothScrollTo(0, tvError.getBottom());
}
});
}
}
}.execute(FragmentIdentity.this, args, "identity:save");
}
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);

File diff suppressed because it is too large Load Diff

@ -135,259 +135,263 @@ public class FragmentQuickSetup extends FragmentBase {
btnCheck.setOnClickListener(new View.OnClickListener() { btnCheck.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Bundle args = new Bundle(); onCheck();
args.putString("name", etName.getText().toString()); }
args.putString("email", etEmail.getText().toString().trim()); });
args.putString("password", tilPassword.getEditText().getText().toString());
args.putInt("auth_type", auth_type);
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
etName.setEnabled(false);
etEmail.setEnabled(false);
tilPassword.setEnabled(false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
tvError.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE);
}
@Override // Initialize
protected void onPostExecute(Bundle args) { tvError.setVisibility(View.GONE);
etName.setEnabled(true); tvInstructions.setVisibility(View.GONE);
etEmail.setEnabled(true); tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
tilPassword.setEnabled(true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
}
@Override return view;
protected Void onExecute(Context context, Bundle args) throws Throwable { }
String name = args.getString("name");
String email = args.getString("email");
String password = args.getString("password");
int auth_type = args.getInt("auth_type");
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(context.getString(R.string.title_no_email));
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid));
String[] dparts = email.split("@");
EmailProvider provider = EmailProvider.fromDomain(context, dparts[1]);
if (provider.documentation != null)
args.putString("documentation", provider.documentation.toString());
String user = (provider.user == EmailProvider.UserType.EMAIL ? email : dparts[0]);
Character separator;
long now = new Date().getTime();
List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.level = 0;
inbox.synchronize = true;
inbox.unified = true;
inbox.notify = true;
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(inbox);
{
Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore(provider.imap_starttls ? "imap" : "imaps");
istore.connect(provider.imap_host, provider.imap_port, user, password);
separator = istore.getDefaultFolder().getSeparator();
boolean drafts = false;
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String type = null;
boolean selectable = true;
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(ifolder.getFullName() + " attrs=" + TextUtils.join(" ", attrs));
for (String attr : attrs) {
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
selectable = false;
if (attr.startsWith("\\")) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
if (index >= 0) {
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
break;
}
}
}
if (selectable && type != null) { private void onCheck() {
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type); Bundle args = new Bundle();
EntityFolder folder = new EntityFolder(); args.putString("name", etName.getText().toString());
folder.name = ifolder.getFullName(); args.putString("email", etEmail.getText().toString().trim());
folder.type = type; args.putString("password", tilPassword.getEditText().getText().toString());
folder.level = EntityFolder.getLevel(separator, folder.name); args.putInt("auth_type", auth_type);
folder.synchronize = (sync >= 0);
folder.download = (sync < 0 ? true : EntityFolder.SYSTEM_FOLDER_DOWNLOAD.get(sync));
folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(folder);
if (EntityFolder.DRAFTS.equals(type))
drafts = true;
}
}
if (!drafts) new SimpleTask<Void>() {
throw new IllegalArgumentException( @Override
context.getString(R.string.title_setup_no_settings, dparts[1])); protected void onPreExecute(Bundle args) {
} finally { etName.setEnabled(false);
if (istore != null) etEmail.setEnabled(false);
istore.close(); tilPassword.setEnabled(false);
} btnAuthorize.setEnabled(false);
} btnCheck.setEnabled(false);
tvError.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE);
}
{ @Override
Properties props = MessageHelper.getSessionProperties(auth_type, null, false); protected void onPostExecute(Bundle args) {
Session isession = Session.getInstance(props, null); etName.setEnabled(true);
isession.setDebug(true); etEmail.setEnabled(true);
Transport itransport = isession.getTransport(provider.smtp_starttls ? "smtp" : "smtps"); tilPassword.setEnabled(true);
try { btnAuthorize.setEnabled(true);
itransport.connect(provider.smtp_host, provider.smtp_port, user, password); btnCheck.setEnabled(true);
} finally { }
itransport.close();
}
}
DB db = DB.getInstance(context); @Override
try { protected Void onExecute(Context context, Bundle args) throws Throwable {
db.beginTransaction(); String name = args.getString("name");
EntityAccount primary = db.account().getPrimaryAccount(); String email = args.getString("email");
String password = args.getString("password");
// Create account int auth_type = args.getInt("auth_type");
EntityAccount account = new EntityAccount();
if (TextUtils.isEmpty(name))
account.auth_type = auth_type; throw new IllegalArgumentException(context.getString(R.string.title_no_name));
account.host = provider.imap_host; if (TextUtils.isEmpty(email))
account.starttls = provider.imap_starttls; throw new IllegalArgumentException(context.getString(R.string.title_no_email));
account.insecure = false; if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
account.port = provider.imap_port; throw new IllegalArgumentException(context.getString(R.string.title_email_invalid));
account.user = user;
account.password = password; String[] dparts = email.split("@");
EmailProvider provider = EmailProvider.fromDomain(context, dparts[1]);
account.name = provider.name;
account.color = null; if (provider.documentation != null)
args.putString("documentation", provider.documentation.toString());
account.synchronize = true;
account.primary = (primary == null); String user = (provider.user == EmailProvider.UserType.EMAIL ? email : dparts[0]);
account.notify = false;
account.browse = true; Character separator;
account.poll_interval = 19; long now = new Date().getTime();
account.prefix = provider.prefix;
List<EntityFolder> folders = new ArrayList<>();
account.created = now;
account.error = null; EntityFolder inbox = new EntityFolder();
account.last_connected = now; inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
account.id = db.account().insertAccount(account); inbox.level = 0;
inbox.synchronize = true;
// Create folders inbox.unified = true;
for (EntityFolder folder : folders) { inbox.notify = true;
folder.account = account.id; inbox.sync_days = EntityFolder.DEFAULT_SYNC;
folder.id = db.folder().insertFolder(folder); inbox.keep_days = EntityFolder.DEFAULT_KEEP;
folders.add(inbox);
{
Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore(provider.imap_starttls ? "imap" : "imaps");
istore.connect(provider.imap_host, provider.imap_port, user, password);
separator = istore.getDefaultFolder().getSeparator();
boolean drafts = false;
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String type = null;
boolean selectable = true;
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(ifolder.getFullName() + " attrs=" + TextUtils.join(" ", attrs));
for (String attr : attrs) {
if ("\\Noselect".equals(attr) || "\\NonExistent".equals(attr))
selectable = false;
if (attr.startsWith("\\")) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
if (index >= 0) {
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
break;
}
}
} }
// Create identity if (selectable && type != null) {
EntityIdentity identity = new EntityIdentity(); int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
identity.name = name; EntityFolder folder = new EntityFolder();
identity.email = email; folder.name = ifolder.getFullName();
identity.account = account.id; folder.type = type;
folder.level = EntityFolder.getLevel(separator, folder.name);
identity.display = null; folder.synchronize = (sync >= 0);
identity.color = null; folder.download = (sync < 0 ? true : EntityFolder.SYSTEM_FOLDER_DOWNLOAD.get(sync));
identity.signature = null; folder.sync_days = EntityFolder.DEFAULT_SYNC;
folder.keep_days = EntityFolder.DEFAULT_KEEP;
identity.auth_type = auth_type; folders.add(folder);
identity.host = provider.smtp_host;
identity.starttls = provider.smtp_starttls; if (EntityFolder.DRAFTS.equals(type))
identity.insecure = false; drafts = true;
identity.port = provider.smtp_port; }
identity.user = user;
identity.password = password;
identity.synchronize = true;
identity.primary = true;
identity.replyto = null;
identity.bcc = null;
identity.delivery_receipt = false;
identity.read_receipt = false;
identity.store_sent = false;
identity.sent_folder = null;
identity.error = null;
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
} }
ServiceSynchronize.reload(context, "quick setup"); if (!drafts)
throw new IllegalArgumentException(
return null; context.getString(R.string.title_setup_no_settings, dparts[1]));
} finally {
if (istore != null)
istore.close();
} }
}
@Override
protected void onExecuted(Bundle args, Void data) { {
etName.setText(null); Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
etEmail.setText(null); Session isession = Session.getInstance(props, null);
tilPassword.getEditText().setText(null); isession.setDebug(true);
Transport itransport = isession.getTransport(provider.smtp_starttls ? "smtp" : "smtps");
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) try {
.setMessage(R.string.title_setup_quick_success) itransport.connect(provider.smtp_host, provider.smtp_port, user, password);
.setPositiveButton(android.R.string.ok, null) } finally {
.setOnDismissListener(new DialogInterface.OnDismissListener() { itransport.close();
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
})
.create()
.show();
} }
}
@Override
protected void onException(Bundle args, Throwable ex) { DB db = DB.getInstance(context);
if (args.containsKey("documentation")) { try {
tvInstructions.setText(Html.fromHtml(args.getString("documentation"))); db.beginTransaction();
tvInstructions.setVisibility(View.VISIBLE); EntityAccount primary = db.account().getPrimaryAccount();
}
// Create account
if (ex instanceof IllegalArgumentException) EntityAccount account = new EntityAccount();
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else { account.auth_type = auth_type;
tvError.setText(Helper.formatThrowable(ex)); account.host = provider.imap_host;
tvError.setVisibility(View.VISIBLE); account.starttls = provider.imap_starttls;
} account.insecure = false;
account.port = provider.imap_port;
account.user = user;
account.password = password;
account.name = provider.name;
account.color = null;
account.synchronize = true;
account.primary = (primary == null);
account.notify = false;
account.browse = true;
account.poll_interval = 19;
account.prefix = provider.prefix;
account.created = now;
account.error = null;
account.last_connected = now;
account.id = db.account().insertAccount(account);
// Create folders
for (EntityFolder folder : folders) {
folder.account = account.id;
folder.id = db.folder().insertFolder(folder);
} }
}.execute(FragmentQuickSetup.this, args, "setup:quick");
// Create identity
EntityIdentity identity = new EntityIdentity();
identity.name = name;
identity.email = email;
identity.account = account.id;
identity.display = null;
identity.color = null;
identity.signature = null;
identity.auth_type = auth_type;
identity.host = provider.smtp_host;
identity.starttls = provider.smtp_starttls;
identity.insecure = false;
identity.port = provider.smtp_port;
identity.user = user;
identity.password = password;
identity.synchronize = true;
identity.primary = true;
identity.replyto = null;
identity.bcc = null;
identity.delivery_receipt = false;
identity.read_receipt = false;
identity.store_sent = false;
identity.sent_folder = null;
identity.error = null;
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.reload(context, "quick setup");
return null;
} }
});
// Initialize @Override
tvError.setVisibility(View.GONE); protected void onExecuted(Bundle args, Void data) {
tvInstructions.setVisibility(View.GONE); etName.setText(null);
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance()); etEmail.setText(null);
tilPassword.getEditText().setText(null);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_setup_quick_success)
.setPositiveButton(android.R.string.ok, null)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
})
.create()
.show();
}
return view; @Override
protected void onException(Bundle args, Throwable ex) {
if (args.containsKey("documentation")) {
tvInstructions.setText(Html.fromHtml(args.getString("documentation")));
tvInstructions.setVisibility(View.VISIBLE);
}
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else {
tvError.setText(Helper.formatThrowable(ex));
tvError.setVisibility(View.VISIBLE);
}
}
}.execute(FragmentQuickSetup.this, args, "setup:quick");
} }
@Override @Override

@ -122,6 +122,14 @@ public class FragmentWebView extends FragmentBase {
registerForContextMenu(webview); registerForContextMenu(webview);
onLoad();
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
return view;
}
private void onLoad() {
Bundle args = getArguments(); Bundle args = getArguments();
if (args.containsKey("url")) { if (args.containsKey("url")) {
String url = args.getString("url"); String url = args.getString("url");
@ -188,10 +196,6 @@ public class FragmentWebView extends FragmentBase {
} }
}.execute(this, args, "webview:format"); }.execute(this, args, "webview:format");
} }
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
return view;
} }
@Override @Override

Loading…
Cancel
Save