|
|
@ -41,6 +41,7 @@ import android.text.TextUtils;
|
|
|
|
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.widget.CheckBox;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
@ -114,6 +115,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
|
|
|
|
|
|
|
|
private boolean hasAccount;
|
|
|
|
private boolean hasAccount;
|
|
|
|
private String password;
|
|
|
|
private String password;
|
|
|
|
|
|
|
|
private boolean import_accounts;
|
|
|
|
|
|
|
|
private boolean import_answers;
|
|
|
|
|
|
|
|
private boolean import_settings;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int KEY_ITERATIONS = 65536;
|
|
|
|
private static final int KEY_ITERATIONS = 65536;
|
|
|
|
private static final int KEY_LENGTH = 256;
|
|
|
|
private static final int KEY_LENGTH = 256;
|
|
|
@ -309,6 +313,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
|
|
|
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("fair:toggle"));
|
|
|
|
password = savedInstanceState.getString("fair:password");
|
|
|
|
password = savedInstanceState.getString("fair:password");
|
|
|
|
|
|
|
|
import_accounts = savedInstanceState.getBoolean("fair:import_accounts");
|
|
|
|
|
|
|
|
import_answers = savedInstanceState.getBoolean("fair:import_answers");
|
|
|
|
|
|
|
|
import_settings = savedInstanceState.getBoolean("fair:import_settings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(this);
|
|
|
|
DB db = DB.getInstance(this);
|
|
|
@ -325,6 +332,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putBoolean("fair:toggle", drawerToggle.isDrawerIndicatorEnabled());
|
|
|
|
outState.putBoolean("fair:toggle", drawerToggle.isDrawerIndicatorEnabled());
|
|
|
|
outState.putString("fair:password", password);
|
|
|
|
outState.putString("fair:password", password);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_accounts", import_accounts);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_answers", import_answers);
|
|
|
|
|
|
|
|
outState.putBoolean("fair:import_settings", import_settings);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -415,11 +425,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
switch (requestCode) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_EXPORT:
|
|
|
|
case REQUEST_EXPORT:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
handleExport(data, this.password);
|
|
|
|
handleExport(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_IMPORT:
|
|
|
|
case REQUEST_IMPORT:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
handleImport(data, this.password);
|
|
|
|
handleImport(data);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REQUEST_IMPORT_CERTIFICATE:
|
|
|
|
case REQUEST_IMPORT_CERTIFICATE:
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
|
if (resultCode == RESULT_OK && data != null)
|
|
|
@ -538,10 +548,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void handleExport(Intent data, String password) {
|
|
|
|
private void handleExport(Intent data) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putString("password", password);
|
|
|
|
args.putString("password", this.password);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -730,10 +740,13 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
}.execute(this, args, "setup:export");
|
|
|
|
}.execute(this, args, "setup:export");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void handleImport(Intent data, String password) {
|
|
|
|
private void handleImport(Intent data) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putParcelable("uri", data.getData());
|
|
|
|
args.putString("password", password);
|
|
|
|
args.putString("password", this.password);
|
|
|
|
|
|
|
|
args.putBoolean("import_accounts", this.import_accounts);
|
|
|
|
|
|
|
|
args.putBoolean("import_answers", this.import_answers);
|
|
|
|
|
|
|
|
args.putBoolean("import_settings", this.import_settings);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -745,6 +758,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
Uri uri = args.getParcelable("uri");
|
|
|
|
Uri uri = args.getParcelable("uri");
|
|
|
|
String password = args.getString("password");
|
|
|
|
String password = args.getString("password");
|
|
|
|
|
|
|
|
boolean import_accounts = args.getBoolean("import_accounts");
|
|
|
|
|
|
|
|
boolean import_answers = args.getBoolean("import_answers");
|
|
|
|
|
|
|
|
boolean import_settings = args.getBoolean("import_settings");
|
|
|
|
|
|
|
|
|
|
|
|
if (!"content".equals(uri.getScheme()) &&
|
|
|
|
if (!"content".equals(uri.getScheme()) &&
|
|
|
|
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
|
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
|
|
@ -801,6 +817,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
Map<Long, Long> xFolder = new HashMap<>();
|
|
|
|
Map<Long, Long> xFolder = new HashMap<>();
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
List<EntityRule> rules = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (import_answers) {
|
|
|
|
// 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++) {
|
|
|
@ -814,7 +831,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Imported answer=" + answer.name + " id=" + answer.id + " (" + id + ")");
|
|
|
|
Log.i("Imported answer=" + answer.name + " id=" + answer.id + " (" + id + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (import_accounts) {
|
|
|
|
EntityAccount primary = db.account().getPrimaryAccount();
|
|
|
|
EntityAccount primary = db.account().getPrimaryAccount();
|
|
|
|
|
|
|
|
|
|
|
|
// Accounts
|
|
|
|
// Accounts
|
|
|
@ -975,7 +994,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
|
|
|
|
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
db.rule().insertRule(rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (import_settings) {
|
|
|
|
|
|
|
|
// Certificates
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
if (jimport.has("certificates")) {
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
|
JSONArray jcertificates = jimport.getJSONArray("certificates");
|
|
|
|
for (int c = 0; c < jcertificates.length(); c++) {
|
|
|
|
for (int c = 0; c < jcertificates.length(); c++) {
|
|
|
@ -1068,7 +1090,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.apply();
|
|
|
|
editor.apply();
|
|
|
|
ApplicationEx.upgrade(context);
|
|
|
|
ApplicationEx.upgrade(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (import_accounts) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
|
if (jimport.has("channels")) {
|
|
|
|
if (jimport.has("channels")) {
|
|
|
|
JSONArray jchannels = jimport.getJSONArray("channels");
|
|
|
|
JSONArray jchannels = jimport.getJSONArray("channels");
|
|
|
@ -1084,6 +1108,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -1376,6 +1401,9 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
Context context = getContext();
|
|
|
|
Context context = getContext();
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_import, null);
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_import, null);
|
|
|
|
etPassword1 = dview.findViewById(R.id.tilPassword1);
|
|
|
|
etPassword1 = dview.findViewById(R.id.tilPassword1);
|
|
|
|
|
|
|
|
CheckBox cbAccounts = dview.findViewById(R.id.cbAccounts);
|
|
|
|
|
|
|
|
CheckBox cbAnswers = dview.findViewById(R.id.cbAnswers);
|
|
|
|
|
|
|
|
CheckBox cbSettings = dview.findViewById(R.id.cbSettings);
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
|
|
|
|
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
|
|
|
@ -1390,7 +1418,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|
|
|
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
|
|
|
|
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
|
|
|
|
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
|
|
|
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
((ActivitySetup) getActivity()).password = password1;
|
|
|
|
ActivitySetup activity = (ActivitySetup) getActivity();
|
|
|
|
|
|
|
|
activity.password = password1;
|
|
|
|
|
|
|
|
activity.import_accounts = cbAccounts.isChecked();
|
|
|
|
|
|
|
|
activity.import_answers = cbAnswers.isChecked();
|
|
|
|
|
|
|
|
activity.import_settings = cbSettings.isChecked();
|
|
|
|
getActivity().startActivityForResult(
|
|
|
|
getActivity().startActivityForResult(
|
|
|
|
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
|
|
|
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|