Merge pull request #1405 from deltachat/qr-multi-account

qr multi account
This commit is contained in:
bjoern
2020-06-10 19:37:29 +02:00
committed by GitHub
10 changed files with 44 additions and 47 deletions
+4 -1
View File
@@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/qrscan_title"
<item android:title="@string/qr_code"
android:id="@+id/menu_qr"
android:icon="@drawable/ic_ab_qr"
app:showAsAction="always"/>
@@ -24,4 +24,7 @@
<item android:title="@string/menu_help"
android:id="@+id/menu_help" />
<item android:title="@string/switch_account"
android:id="@+id/menu_switch_account" />
</menu>
+1
View File
@@ -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>
-3
View File
@@ -59,9 +59,6 @@
<Preference android:key="pref_empty_server_folders"
android:title="@string/pref_empty_server_title" />
<Preference android:key="pref_switch_account"
android:title="@string/switch_account" />
</PreferenceCategory>
@@ -35,6 +35,7 @@ import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.thoughtcrime.securesms.components.SearchToolbar;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.map.MapActivity;
@@ -225,6 +226,9 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
case R.id.menu_global_map:
handleShowMap();
return true;
case R.id.menu_switch_account:
AccountManager.getInstance().showSwitchAccountMenu(this);
return true;
case android.R.id.home:
onBackPressed();
return true;
@@ -58,12 +58,10 @@ import org.thoughtcrime.securesms.components.reminder.DozeReminder;
import org.thoughtcrime.securesms.components.reminder.OutdatedReminder;
import org.thoughtcrime.securesms.components.reminder.Reminder;
import org.thoughtcrime.securesms.components.reminder.ReminderView;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
import org.thoughtcrime.securesms.connect.DcChatlistLoader;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.RelayUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.guava.Optional;
@@ -178,13 +176,6 @@ public class ConversationListFragment extends Fragment
fab.setOnClickListener(v -> getActivity().startActivityForResult(intent, REQUEST_RELAY));
} else {
fab.setOnClickListener(v -> startActivity(intent));
fab.setOnLongClickListener(v -> {
if (Prefs.isAccountSwitchingEnabled(getActivity())) {
AccountManager.getInstance().showSwitchAccountMenu(getActivity());
return true;
}
return false;
});
}
}
@@ -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();
@@ -135,8 +135,6 @@ public class AccountManager {
} catch (Exception e) {
e.printStackTrace();
}
Prefs.setAccountSwitchingEnabled(context, result.size()>1);
return result;
}
@@ -160,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);
@@ -171,8 +169,6 @@ public class AccountManager {
sharedPreferences.edit().putString("curr_account_db_name", inCreationDbName).apply();
resetDcContext(context);
Prefs.setAccountSwitchingEnabled(context, true);
}
public boolean canRollbackAccountCreation(Context context) {
@@ -188,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();
@@ -225,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) {
@@ -265,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));
}
@@ -299,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();
}
}
});
@@ -353,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();
}
}
@@ -96,14 +96,6 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
emptyServerFolders.setOnPreferenceClickListener(new EmptyServerFoldersListener());
}
Preference switchAccount = this.findPreference("pref_switch_account");
if(switchAccount!=null) {
switchAccount.setOnPreferenceClickListener(preference -> {
AccountManager.getInstance().showSwitchAccountMenu(getActivity());
return true;
});
}
Preference manageKeys = this.findPreference("pref_manage_keys");
manageKeys.setOnPreferenceClickListener(new ManageKeysListener());
@@ -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:
@@ -186,19 +186,6 @@ public class Prefs {
}
}
public static void setAccountSwitchingEnabled(Context context, boolean value) {
setBooleanPreference(context, "pref_account_switching_enabled", value);
}
public static boolean isAccountSwitchingEnabled(Context context) {
try {
return getBooleanPreference(context, "pref_account_switching_enabled", false);
}
catch(Exception e) {
return false;
}
}
// ringtone
public static @NonNull Uri getNotificationRingtone(Context context) {