|
|
|
@ -39,9 +39,11 @@ import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
@ -90,6 +92,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
private TextView tvSmtpFingerprint;
|
|
|
|
|
private TextView tvSmtpDnsNames;
|
|
|
|
|
|
|
|
|
|
private CheckBox cbUpdate;
|
|
|
|
|
private Button btnSave;
|
|
|
|
|
private ContentLoadingProgressBar pbSave;
|
|
|
|
|
|
|
|
|
@ -97,6 +100,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
private Group grpCertificate;
|
|
|
|
|
private Group grpError;
|
|
|
|
|
|
|
|
|
|
private boolean update;
|
|
|
|
|
private EmailProvider bestProvider = null;
|
|
|
|
|
private Bundle bestArgs = null;
|
|
|
|
|
|
|
|
|
@ -109,6 +113,14 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
outState.putParcelable("fair:args", bestArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
|
update = args.getBoolean("update");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Nullable
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
@ -143,6 +155,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
tvSmtpFingerprint = view.findViewById(R.id.tvSmtpFingerprint);
|
|
|
|
|
tvSmtpDnsNames = view.findViewById(R.id.tvSmtpDnsNames);
|
|
|
|
|
|
|
|
|
|
cbUpdate = view.findViewById(R.id.cbUpdate);
|
|
|
|
|
btnSave = view.findViewById(R.id.btnSave);
|
|
|
|
|
pbSave = view.findViewById(R.id.pbSave);
|
|
|
|
|
|
|
|
|
@ -234,6 +247,8 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
tvInstructions.setVisibility(View.GONE);
|
|
|
|
|
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
|
btnHelp.setVisibility(View.GONE);
|
|
|
|
|
cbUpdate.setChecked(update);
|
|
|
|
|
cbUpdate.setVisibility(View.GONE);
|
|
|
|
|
btnSave.setVisibility(View.GONE);
|
|
|
|
|
grpSetup.setVisibility(View.GONE);
|
|
|
|
|
grpCertificate.setVisibility(View.GONE);
|
|
|
|
@ -254,6 +269,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
args.putString("name", etName.getText().toString().trim());
|
|
|
|
|
args.putString("email", etEmail.getText().toString().trim());
|
|
|
|
|
args.putString("password", tilPassword.getEditText().getText().toString());
|
|
|
|
|
args.putBoolean("update", cbUpdate.isChecked());
|
|
|
|
|
args.putBoolean("check", check);
|
|
|
|
|
args.putParcelable("best", bestProvider);
|
|
|
|
|
|
|
|
|
@ -269,6 +285,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
grpError.setVisibility(View.GONE);
|
|
|
|
|
tvInstructions.setVisibility(View.GONE);
|
|
|
|
|
btnHelp.setVisibility(View.GONE);
|
|
|
|
|
cbUpdate.setVisibility(check ? View.GONE : View.VISIBLE);
|
|
|
|
|
btnSave.setVisibility(check ? View.GONE : View.VISIBLE);
|
|
|
|
|
grpSetup.setVisibility(check ? View.GONE : View.VISIBLE);
|
|
|
|
|
if (check)
|
|
|
|
@ -431,12 +448,28 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
return provider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntityAccount update = null;
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
try {
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
EntityAccount primary = db.account().getPrimaryAccount();
|
|
|
|
|
|
|
|
|
|
if (args.getBoolean("update")) {
|
|
|
|
|
List<EntityAccount> accounts =
|
|
|
|
|
db.account().getAccounts(user, new int[]{AUTH_TYPE_PASSWORD});
|
|
|
|
|
if (accounts != null)
|
|
|
|
|
for (EntityAccount existing : accounts)
|
|
|
|
|
if (existing.protocol == EntityAccount.TYPE_IMAP)
|
|
|
|
|
if (update == null)
|
|
|
|
|
update = existing;
|
|
|
|
|
else {
|
|
|
|
|
update = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update == null) {
|
|
|
|
|
// Create account
|
|
|
|
|
EntityAccount account = new EntityAccount();
|
|
|
|
|
|
|
|
|
@ -507,13 +540,28 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
|
|
|
|
|
identity.id = db.identity().insertIdentity(identity);
|
|
|
|
|
EntityLog.log(context, "Quick added identity=" + identity.name + " email=" + identity.email);
|
|
|
|
|
} else {
|
|
|
|
|
args.putLong("account", update.id);
|
|
|
|
|
EntityLog.log(context, "Quick setup update account=" + update.name);
|
|
|
|
|
db.account().setAccountSynchronize(update.id, true);
|
|
|
|
|
db.account().setAccountPassword(update.id, password, AUTH_TYPE_PASSWORD);
|
|
|
|
|
db.account().setAccountFingerprint(update.id, imap_fingerprint);
|
|
|
|
|
db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type, AUTH_TYPE_PASSWORD);
|
|
|
|
|
db.identity().setIdentityFingerprint(update.id, smtp_fingerprint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
} finally {
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update == null)
|
|
|
|
|
ServiceSynchronize.eval(context, "quick setup");
|
|
|
|
|
else {
|
|
|
|
|
args.putBoolean("updated", true);
|
|
|
|
|
ServiceSynchronize.reload(context, update.id, true, "quick setup");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return provider;
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.w(ex);
|
|
|
|
@ -536,6 +584,11 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
bestProvider = result;
|
|
|
|
|
bestArgs = args;
|
|
|
|
|
showResult(bestProvider, bestArgs);
|
|
|
|
|
} else {
|
|
|
|
|
boolean updated = args.getBoolean("updated");
|
|
|
|
|
if (updated) {
|
|
|
|
|
finish();
|
|
|
|
|
ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show();
|
|
|
|
|
} else {
|
|
|
|
|
FragmentDialogAccount fragment = new FragmentDialogAccount();
|
|
|
|
|
fragment.setArguments(args);
|
|
|
|
@ -543,6 +596,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
fragment.show(getParentFragmentManager(), "quick:review");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onException(final Bundle args, Throwable ex) {
|
|
|
|
@ -663,6 +717,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
|
|
|
|
imap_certificate == null && smtp_certificate == null
|
|
|
|
|
? View.GONE : View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
cbUpdate.setVisibility(provider == null ? View.GONE : View.VISIBLE);
|
|
|
|
|
btnSave.setVisibility(provider == null ? View.GONE : View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|