mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
allow qr-account-creation from within configured app
This commit is contained in:
@@ -557,6 +557,7 @@
|
||||
<string name="qrshow_join_contact_no_connection_hint">QR code setup requires an internet connection. Please connect to a network before proceeding.</string>
|
||||
<string name="qrshow_join_contact_no_connection_toast">No internet connection, can\'t perform QR code setup.</string>
|
||||
<string name="qraccount_ask_create_and_login">Create new e-mail address on \"%1$s\" and log in there?</string>
|
||||
<string name="qraccount_ask_create_and_login_another">Create new e-mail address on \"%1$s\" and log in there?\n\nYour existing account will not be deleted. Use the \"Switch account\" item to switch between your accounts.</string>
|
||||
<string name="qraccount_success_enter_name">Login successful—your email address is %1$s\n\nIf you like, you can now enter a name and an avatar image that will be displayed to people you write to.</string>
|
||||
<string name="qraccount_qr_code_cannot_be_used">The scanned QR code cannot be used to set up a new account.</string>
|
||||
<string name="qraccount_use_on_new_install">The scanned QR code is for setting up a new account. You can scan the QR code when setting up a new Delta Chat installation.</string>
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.util.views.ProgressDialog;
|
||||
import java.io.File;
|
||||
|
||||
public class WelcomeActivity extends BaseActionBarActivity implements DcEventCenter.DcEventDelegate {
|
||||
public static final String QR_ACCOUNT_EXTRA = "qr_account_extra";
|
||||
|
||||
private boolean manualConfigure = true; // false: configure by QR account creation
|
||||
private ProgressDialog progressDialog = null;
|
||||
@@ -49,6 +50,16 @@ public class WelcomeActivity extends BaseActionBarActivity implements DcEventCen
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_IMEX_PROGRESS, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
String qrAccount = getIntent().getStringExtra(QR_ACCOUNT_EXTRA);
|
||||
if (qrAccount!=null) {
|
||||
manualConfigure = false;
|
||||
startQrAccountCreation(qrAccount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -158,7 +158,7 @@ public class AccountManager {
|
||||
|
||||
// add accounts
|
||||
|
||||
public void beginAccountCreation(Context context) {
|
||||
private void beginAccountCreation(Context context) {
|
||||
// pause the current account and let the user create a new one.
|
||||
// this function is not needed on the very first account creation.
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
@@ -184,14 +184,14 @@ public class AccountManager {
|
||||
|
||||
Account prevAccount = maybeGetAccount(new File(activity.getFilesDir(), prevDbName));
|
||||
if (prevAccount!=null) {
|
||||
new SwitchAccountAsyncTask(activity, R.string.switching_account, prevAccount, inCreationDbName).execute();
|
||||
new SwitchAccountAsyncTask(activity, R.string.switching_account, prevAccount, inCreationDbName, null).execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// delete account
|
||||
|
||||
public void deleteAccount(Context context, String dbName) {
|
||||
private void deleteAccount(Context context, String dbName) {
|
||||
try {
|
||||
File blobdir = new File(context.getFilesDir(), dbName+"-blobs");
|
||||
String [] blobfiles = blobdir.list();
|
||||
@@ -221,12 +221,14 @@ public class AccountManager {
|
||||
private final WeakReference<Activity> activityWeakReference;
|
||||
private final @Nullable Account destAccount; // null creates a new account
|
||||
private final @Nullable String deleteDbName;
|
||||
private final @Nullable String qrAccount;
|
||||
|
||||
public SwitchAccountAsyncTask(Activity activity, int title, @Nullable Account destAccount, @Nullable String deleteDbName) {
|
||||
public SwitchAccountAsyncTask(Activity activity, int title, @Nullable Account destAccount, @Nullable String deleteDbName, @Nullable String qrAccount) {
|
||||
super(activity, null, activity.getString(title));
|
||||
this.activityWeakReference = new WeakReference<>(activity);
|
||||
this.destAccount = destAccount;
|
||||
this.deleteDbName = deleteDbName;
|
||||
this.qrAccount = qrAccount;
|
||||
}
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
@@ -261,7 +263,11 @@ public class AccountManager {
|
||||
if (activity!=null) {
|
||||
activity.finishAffinity();
|
||||
if (destAccount==null) {
|
||||
activity.startActivity(new Intent(activity, WelcomeActivity.class));
|
||||
Intent intent = new Intent(activity, WelcomeActivity.class);
|
||||
if (qrAccount!=null) {
|
||||
intent.putExtra(WelcomeActivity.QR_ACCOUNT_EXTRA, qrAccount);
|
||||
}
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
activity.startActivity(new Intent(activity.getApplicationContext(), ConversationListActivity.class));
|
||||
}
|
||||
@@ -295,11 +301,11 @@ public class AccountManager {
|
||||
.setSingleChoiceItems(menu.toArray(new String[menu.size()]), presel, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
if (which==addAccount) {
|
||||
new SwitchAccountAsyncTask(activity, R.string.one_moment, null, null).execute();
|
||||
new SwitchAccountAsyncTask(activity, R.string.one_moment, null, null, null).execute();
|
||||
} else { // switch account
|
||||
Account account = accounts.get(which);
|
||||
if (!account.isCurrent()) {
|
||||
new SwitchAccountAsyncTask(activity, R.string.switching_account, account, null).execute();
|
||||
new SwitchAccountAsyncTask(activity, R.string.switching_account, account, null, null).execute();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -349,4 +355,7 @@ public class AccountManager {
|
||||
.show();
|
||||
}
|
||||
|
||||
public void addAccountFromQr(Activity activity, String qr) {
|
||||
new SwitchAccountAsyncTask(activity, R.string.one_moment, null, null, qr).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import org.thoughtcrime.securesms.ConversationActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.AccountManager;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.IntentUtils;
|
||||
@@ -69,8 +70,13 @@ public class QrCodeHandler implements DcEventCenter.DcEventDelegate {
|
||||
break;
|
||||
|
||||
case DcContext.DC_QR_ACCOUNT:
|
||||
builder.setMessage(R.string.qraccount_use_on_new_install);
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
String domain = qrParsed.getText1();
|
||||
builder.setMessage(activity.getString(R.string.qraccount_ask_create_and_login_another, domain));
|
||||
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||
AccountManager.getInstance().addAccountFromQr(activity, rawString);
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.setCancelable(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user