|
|
@ -35,18 +35,23 @@ import android.content.IntentFilter;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.text.style.StyleSpan;
|
|
|
|
import android.util.Pair;
|
|
|
|
import android.util.Pair;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
@ -777,6 +782,18 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
Log.w(ex);
|
|
|
|
Log.w(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
View dview = LayoutInflater.from(this).inflate(R.layout.dialog_import_progress, null);
|
|
|
|
|
|
|
|
TextView tvLog = dview.findViewById(R.id.tvLog);
|
|
|
|
|
|
|
|
tvLog.setText(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
|
|
|
|
|
|
|
.setView(dview)
|
|
|
|
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
|
|
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Button ok = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
|
|
|
|
|
|
|
ok.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("uri", uri);
|
|
|
|
args.putParcelable("uri", uri);
|
|
|
|
args.putString("password", this.password);
|
|
|
|
args.putString("password", this.password);
|
|
|
@ -787,9 +804,17 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
args.putBoolean("import_settings", this.import_settings);
|
|
|
|
args.putBoolean("import_settings", this.import_settings);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
|
|
|
private SpannableStringBuilder ssb = new SpannableStringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute(Bundle args) {
|
|
|
|
protected void onProgress(CharSequence status, Bundle data) {
|
|
|
|
ToastEx.makeText(ActivitySetup.this, R.string.title_executing, Toast.LENGTH_LONG).show();
|
|
|
|
ssb.append(status).append("\n");
|
|
|
|
|
|
|
|
tvLog.setText(ssb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onPostExecute(Bundle args) {
|
|
|
|
|
|
|
|
ok.setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -867,6 +892,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
if (import_answers) {
|
|
|
|
if (import_answers) {
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_setup_import_answers), null);
|
|
|
|
|
|
|
|
|
|
|
|
// Answers
|
|
|
|
// Answers
|
|
|
|
JSONArray janswers = jimport.getJSONArray("answers");
|
|
|
|
JSONArray janswers = jimport.getJSONArray("answers");
|
|
|
|
for (int a = 0; a < janswers.length(); a++) {
|
|
|
|
for (int a = 0; a < janswers.length(); a++) {
|
|
|
@ -890,19 +917,28 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
for (int a = 0; a < jaccounts.length(); a++) {
|
|
|
|
for (int a = 0; a < jaccounts.length(); a++) {
|
|
|
|
JSONObject jaccount = (JSONObject) jaccounts.get(a);
|
|
|
|
JSONObject jaccount = (JSONObject) jaccounts.get(a);
|
|
|
|
EntityAccount account = EntityAccount.fromJSON(jaccount);
|
|
|
|
EntityAccount account = EntityAccount.fromJSON(jaccount);
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_importing_account, account.name));
|
|
|
|
|
|
|
|
|
|
|
|
EntityAccount existing = db.account().getAccountByUUID(account.uuid);
|
|
|
|
EntityAccount existing = db.account().getAccountByUUID(account.uuid);
|
|
|
|
if (existing != null) {
|
|
|
|
if (existing != null) {
|
|
|
|
|
|
|
|
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
|
|
|
|
|
|
|
ssb.append(context.getString(R.string.title_importing_exists));
|
|
|
|
|
|
|
|
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
|
|
|
|
|
|
|
|
postProgress(ssb);
|
|
|
|
EntityLog.log(context, "Existing account=" + account.name +
|
|
|
|
EntityLog.log(context, "Existing account=" + account.name +
|
|
|
|
"id=" + account.id);
|
|
|
|
"id=" + account.id);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (account.auth_type == AUTH_TYPE_GMAIL) {
|
|
|
|
if (account.auth_type == AUTH_TYPE_GMAIL &&
|
|
|
|
if (GmailState.getAccount(context, account.user) == null) {
|
|
|
|
GmailState.getAccount(context, account.user) == null) {
|
|
|
|
Log.i("Google account not found user=" + account.user);
|
|
|
|
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
|
|
|
continue;
|
|
|
|
ssb.append(context.getString(R.string.title_importing_wizard));
|
|
|
|
}
|
|
|
|
ssb.setSpan(new StyleSpan(Typeface.BOLD), 0, ssb.length(), 0);
|
|
|
|
|
|
|
|
postProgress(ssb);
|
|
|
|
|
|
|
|
EntityLog.log(context, "Run wizard account=" + account.name +
|
|
|
|
|
|
|
|
"id=" + account.id);
|
|
|
|
|
|
|
|
account.synchronize = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Long aid = account.id;
|
|
|
|
Long aid = account.id;
|
|
|
@ -948,6 +984,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
for (int i = 0; i < jidentities.length(); i++) {
|
|
|
|
for (int i = 0; i < jidentities.length(); i++) {
|
|
|
|
JSONObject jidentity = (JSONObject) jidentities.get(i);
|
|
|
|
JSONObject jidentity = (JSONObject) jidentities.get(i);
|
|
|
|
EntityIdentity identity = EntityIdentity.fromJSON(jidentity);
|
|
|
|
EntityIdentity identity = EntityIdentity.fromJSON(jidentity);
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_importing_identity, identity.email));
|
|
|
|
|
|
|
|
|
|
|
|
long id = identity.id;
|
|
|
|
long id = identity.id;
|
|
|
|
identity.id = null;
|
|
|
|
identity.id = null;
|
|
|
|
|
|
|
|
|
|
|
@ -1008,6 +1046,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
if (import_contacts) {
|
|
|
|
if (import_contacts) {
|
|
|
|
// Contacts
|
|
|
|
// Contacts
|
|
|
|
if (jaccount.has("contacts")) {
|
|
|
|
if (jaccount.has("contacts")) {
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_setup_import_contacts), null);
|
|
|
|
|
|
|
|
|
|
|
|
JSONArray jcontacts = jaccount.getJSONArray("contacts");
|
|
|
|
JSONArray jcontacts = jaccount.getJSONArray("contacts");
|
|
|
|
for (int c = 0; c < jcontacts.length(); c++) {
|
|
|
|
for (int c = 0; c < jcontacts.length(); c++) {
|
|
|
|
JSONObject jcontact = (JSONObject) jcontacts.get(c);
|
|
|
|
JSONObject jcontact = (JSONObject) jcontacts.get(c);
|
|
|
@ -1024,7 +1064,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (import_rules)
|
|
|
|
if (import_rules) {
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_setup_import_rules), null);
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
for (EntityRule rule : rules) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
|
JSONObject jaction = new JSONObject(rule.action);
|
|
|
@ -1055,8 +1096,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (import_settings) {
|
|
|
|
if (import_settings) {
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_setup_import_settings), null);
|
|
|
|
|
|
|
|
|
|
|
|
// Certificates
|
|
|
|
// Certificates
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
@ -1180,28 +1224,26 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
ServiceSynchronize.eval(context, "import");
|
|
|
|
ServiceSynchronize.eval(context, "import");
|
|
|
|
Log.i("Imported data");
|
|
|
|
Log.i("Imported data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postProgress(context.getString(R.string.title_setup_imported), null);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
|
|
|
|
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_imported, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
if (ex.getCause() instanceof BadPaddingException)
|
|
|
|
if (ex.getCause() instanceof BadPaddingException) {
|
|
|
|
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_password_invalid, Toast.LENGTH_LONG).show();
|
|
|
|
onProgress(getString(R.string.title_setup_password_invalid), null);
|
|
|
|
else if (ex instanceof IOException && ex.getCause() instanceof IllegalBlockSizeException)
|
|
|
|
onProgress("\n" + ex.toString(), null);
|
|
|
|
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_import_invalid, Toast.LENGTH_LONG).show();
|
|
|
|
} else if (ex instanceof IOException && ex.getCause() instanceof IllegalBlockSizeException) {
|
|
|
|
else {
|
|
|
|
onProgress(getString(R.string.title_setup_import_invalid), null);
|
|
|
|
boolean expected =
|
|
|
|
onProgress("\n" + ex.toString(), null);
|
|
|
|
(ex instanceof IllegalArgumentException ||
|
|
|
|
} else if (ex instanceof IllegalArgumentException ||
|
|
|
|
ex instanceof IOException ||
|
|
|
|
ex instanceof IOException ||
|
|
|
|
ex instanceof FileNotFoundException ||
|
|
|
|
|
|
|
|
ex instanceof JSONException ||
|
|
|
|
ex instanceof JSONException ||
|
|
|
|
ex instanceof SecurityException);
|
|
|
|
ex instanceof SecurityException) {
|
|
|
|
Log.unexpectedError(getSupportFragmentManager(), ex, !expected);
|
|
|
|
onProgress(ex.toString(), null);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
|
|
|
Log.unexpectedError(getSupportFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute(this, args, "setup:import");
|
|
|
|
}.execute(this, args, "setup:import");
|
|
|
|