Refactoring

This commit is contained in:
M66B 2019-01-17 09:57:01 +00:00
parent bb1e697c41
commit 3b06c3d027
7 changed files with 2248 additions and 2192 deletions

View File

@ -150,140 +150,153 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
return;
final EntityAttachment attachment = filtered.get(pos);
if (view.getId() == R.id.ivDelete) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<Void>() {
@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");
} else if (view.getId() == R.id.ivSave) {
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));
} else {
if (attachment.available) {
// 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
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");
}
if (view.getId() == R.id.ivDelete)
onDelete(attachment);
else if (view.getId() == R.id.ivSave)
onSave(attachment);
else {
if (attachment.available)
onShare(attachment);
else {
if (attachment.progress == null)
onDownload(attachment);
}
}
}
private void onDelete(final EntityAttachment attachment) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<Void>() {
@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
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);
}
private void onDownload(EntityAttachment attachment) {
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");
}
private class NameResolveInfo {
Drawable icon;
String name;

File diff suppressed because it is too large Load Diff

View File

@ -126,140 +126,7 @@ public class FragmentFolder extends FragmentBase {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
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
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@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);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (reload)
ServiceSynchronize.reload(context, "save folder");
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
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentFolder.this, args, "folder:save");
onSave();
}
});
@ -272,6 +139,143 @@ public class FragmentFolder extends FragmentBase {
return view;
}
private void onSave() {
Bundle args = new Bundle();
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
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@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);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (reload)
ServiceSynchronize.reload(context, "save folder");
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
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(FragmentFolder.this, args, "folder:save");
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_folder, menu);

View File

@ -382,46 +382,7 @@ public class FragmentIdentity extends FragmentBase {
btnAutoConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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");
onAutoConfig();
}
});
@ -442,224 +403,7 @@ public class FragmentIdentity extends FragmentBase {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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");
onSave();
}
});
@ -683,6 +427,270 @@ public class FragmentIdentity extends FragmentBase {
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
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

File diff suppressed because it is too large Load Diff

View File

@ -135,250 +135,7 @@ public class FragmentQuickSetup extends FragmentBase {
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
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
protected void onPostExecute(Bundle args) {
etName.setEnabled(true);
etEmail.setEnabled(true);
tilPassword.setEnabled(true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
}
@Override
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) {
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
EntityFolder folder = new EntityFolder();
folder.name = ifolder.getFullName();
folder.type = type;
folder.level = EntityFolder.getLevel(separator, folder.name);
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)
throw new IllegalArgumentException(
context.getString(R.string.title_setup_no_settings, dparts[1]));
} finally {
if (istore != null)
istore.close();
}
}
{
Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Transport itransport = isession.getTransport(provider.smtp_starttls ? "smtp" : "smtps");
try {
itransport.connect(provider.smtp_host, provider.smtp_port, user, password);
} finally {
itransport.close();
}
}
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityAccount primary = db.account().getPrimaryAccount();
// Create account
EntityAccount account = new EntityAccount();
account.auth_type = auth_type;
account.host = provider.imap_host;
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);
}
// 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;
}
@Override
protected void onExecuted(Bundle args, Void data) {
etName.setText(null);
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();
}
@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");
onCheck();
}
});
@ -390,6 +147,253 @@ public class FragmentQuickSetup extends FragmentBase {
return view;
}
private void onCheck() {
Bundle args = new Bundle();
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
protected void onPostExecute(Bundle args) {
etName.setEnabled(true);
etEmail.setEnabled(true);
tilPassword.setEnabled(true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
}
@Override
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) {
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
EntityFolder folder = new EntityFolder();
folder.name = ifolder.getFullName();
folder.type = type;
folder.level = EntityFolder.getLevel(separator, folder.name);
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)
throw new IllegalArgumentException(
context.getString(R.string.title_setup_no_settings, dparts[1]));
} finally {
if (istore != null)
istore.close();
}
}
{
Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Transport itransport = isession.getTransport(provider.smtp_starttls ? "smtp" : "smtps");
try {
itransport.connect(provider.smtp_host, provider.smtp_port, user, password);
} finally {
itransport.close();
}
}
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityAccount primary = db.account().getPrimaryAccount();
// Create account
EntityAccount account = new EntityAccount();
account.auth_type = auth_type;
account.host = provider.imap_host;
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);
}
// 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;
}
@Override
protected void onExecuted(Bundle args, Void data) {
etName.setText(null);
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();
}
@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
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT)

View File

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