Save changes for POP3

pull/194/head
M66B 4 years ago
parent 1400afb7ca
commit 796c002e78

@ -29,6 +29,7 @@ import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -108,7 +109,8 @@ public class FragmentPop extends FragmentBase {
private boolean saving = false; private boolean saving = false;
private static final int REQUEST_COLOR = 1; private static final int REQUEST_COLOR = 1;
private static final int REQUEST_DELETE = 2; private static final int REQUEST_SAVE = 2;
private static final int REQUEST_DELETE = 3;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -238,7 +240,20 @@ public class FragmentPop extends FragmentBase {
btnSave.setOnClickListener(new View.OnClickListener() { btnSave.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onSave(); onSave(false);
}
});
addKeyPressedListener(new ActivityBase.IKeyPressedListener() {
@Override
public boolean onKeyPressed(KeyEvent event) {
return false;
}
@Override
public boolean onBackPressed() {
onSave(true);
return true;
} }
}); });
@ -253,7 +268,7 @@ public class FragmentPop extends FragmentBase {
return view; return view;
} }
private void onSave() { private void onSave(boolean should) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -290,6 +305,8 @@ public class FragmentPop extends FragmentBase {
args.putLong("left", ((EntityFolder) spLeft.getSelectedItem()).id); args.putLong("left", ((EntityFolder) spLeft.getSelectedItem()).id);
args.putLong("right", ((EntityFolder) spRight.getSelectedItem()).id); args.putLong("right", ((EntityFolder) spRight.getSelectedItem()).id);
args.putBoolean("should", should);
new SimpleTask<Boolean>() { new SimpleTask<Boolean>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
@ -337,33 +354,87 @@ public class FragmentPop extends FragmentBase {
long right = args.getLong("right"); long right = args.getLong("right");
boolean pro = ActivityBilling.isPro(context); boolean pro = ActivityBilling.isPro(context);
boolean should = args.getBoolean("should");
if (host.contains(":")) { if (host.contains(":")) {
Uri h = Uri.parse(host); Uri h = Uri.parse(host);
host = h.getHost(); host = h.getHost();
} }
if (TextUtils.isEmpty(host)) if (TextUtils.isEmpty(host) && !should)
throw new IllegalArgumentException(context.getString(R.string.title_no_host)); throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port)) if (TextUtils.isEmpty(port))
port = (encryption == EmailService.ENCRYPTION_SSL ? "995" : "110"); port = (encryption == EmailService.ENCRYPTION_SSL ? "995" : "110");
if (TextUtils.isEmpty(user)) if (TextUtils.isEmpty(user) && !should)
throw new IllegalArgumentException(context.getString(R.string.title_no_user)); throw new IllegalArgumentException(context.getString(R.string.title_no_user));
if (synchronize && TextUtils.isEmpty(password) && !insecure) if (synchronize && TextUtils.isEmpty(password) && !insecure && !should)
throw new IllegalArgumentException(context.getString(R.string.title_no_password)); throw new IllegalArgumentException(context.getString(R.string.title_no_password));
if (TextUtils.isEmpty(interval)) if (TextUtils.isEmpty(interval))
interval = Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL); interval = Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL);
Integer max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max));
int poll_interval = Math.max(1, Integer.parseInt(interval));
if (TextUtils.isEmpty(name)) if (TextUtils.isEmpty(name))
name = user; name = user;
if (color == Color.TRANSPARENT || !pro) if (color == Color.TRANSPARENT || !pro)
color = null; color = null;
if (!pro)
notify = false;
long now = new Date().getTime(); long now = new Date().getTime();
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id); EntityAccount account = db.account().getAccount(id);
if (should) {
if (account == null)
return !TextUtils.isEmpty(host) && !TextUtils.isEmpty(user);
if (!Objects.equals(account.host, host))
return true;
if (!Objects.equals(account.encryption, encryption))
return true;
if (!Objects.equals(account.insecure, insecure))
return true;
if (!Objects.equals(account.port, Integer.parseInt(port)))
return true;
if (!Objects.equals(account.user, user))
return true;
if (!Objects.equals(account.password, password))
return true;
if (!Objects.equals(account.name, name))
return true;
if (!Objects.equals(account.color, color))
return true;
if (!Objects.equals(account.synchronize, synchronize))
return true;
if (!Objects.equals(account.ondemand, ondemand))
return true;
if (!Objects.equals(account.primary, account.synchronize && primary))
return true;
if (!Objects.equals(account.notify, notify))
return true;
if (!Objects.equals(account.auto_seen, auto_seen))
return true;
if (!Objects.equals(account.leave_on_server, leave_server))
return true;
if (!Objects.equals(account.leave_deleted, leave_deleted))
return true;
if (!Objects.equals(account.leave_on_device, leave_device))
return true;
if (!Objects.equals(account.max_messages, max_messages))
return true;
if (!Objects.equals(account.poll_interval, poll_interval))
return true;
if (!Objects.equals(account.swipe_left, left))
return true;
if (!Objects.equals(account.swipe_right, right))
return true;
return false;
}
boolean check = (synchronize && (account == null || boolean check = (synchronize && (account == null ||
!account.synchronize || !account.synchronize ||
account.error != null || account.error != null ||
@ -427,8 +498,8 @@ public class FragmentPop extends FragmentBase {
account.leave_on_server = leave_server; account.leave_on_server = leave_server;
account.leave_deleted = leave_deleted; account.leave_deleted = leave_deleted;
account.leave_on_device = leave_device; account.leave_on_device = leave_device;
account.max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max)); account.max_messages = max_messages;
account.poll_interval = Math.max(1, Integer.parseInt(interval)); account.poll_interval = poll_interval;
account.swipe_left = left; account.swipe_left = left;
account.swipe_right = right; account.swipe_right = right;
@ -542,6 +613,15 @@ public class FragmentPop extends FragmentBase {
@Override @Override
protected void onExecuted(Bundle args, Boolean dirty) { protected void onExecuted(Bundle args, Boolean dirty) {
if (dirty) {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_ask_save));
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);
fragment.setTargetFragment(FragmentPop.this, REQUEST_SAVE);
fragment.show(getParentFragmentManager(), "account:save");
} else {
Context context = getContext(); Context context = getContext();
if (context != null) if (context != null)
WidgetUnified.updateData(context); // Update color stripe WidgetUnified.updateData(context); // Update color stripe
@ -562,6 +642,7 @@ public class FragmentPop extends FragmentBase {
} }
} }
} }
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
@ -747,6 +828,18 @@ public class FragmentPop extends FragmentBase {
startActivity(new Intent(getContext(), ActivityBilling.class)); startActivity(new Intent(getContext(), ActivityBilling.class));
} }
break; break;
case REQUEST_SAVE:
if (resultCode == RESULT_OK) {
getMainHandler().post(new Runnable() {
@Override
public void run() {
scroll.smoothScrollTo(0, btnSave.getBottom());
}
});
onSave(false);
} else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getParentFragmentManager().popBackStack();
break;
case REQUEST_DELETE: case REQUEST_DELETE:
if (resultCode == RESULT_OK) if (resultCode == RESULT_OK)
onDelete(); onDelete();

Loading…
Cancel
Save