return to welcome activity after deleting last account

This commit is contained in:
Daniel Gultsch 2018-02-10 10:45:33 +01:00
parent 97406ecf51
commit facc56bc7b
4 changed files with 59 additions and 59 deletions

View File

@ -1834,12 +1834,15 @@ public class XmppConnectionService extends Service {
} }
public void createAccountFromKey(final String alias, final OnAccountCreated callback) { public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
try { try {
X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias); final X509Certificate[] chain = KeyChain.getCertificateChain(this, alias);
Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); final X509Certificate cert = chain != null && chain.length > 0 ? chain[0] : null;
if (cert == null) {
callback.informUser(R.string.unable_to_parse_certificate);
return;
}
Pair<Jid, String> info = CryptoHelper.extractJidAndName(cert);
if (info == null) { if (info == null) {
callback.informUser(R.string.certificate_does_not_contain_jid); callback.informUser(R.string.certificate_does_not_contain_jid);
return; return;
@ -1865,7 +1868,6 @@ public class XmppConnectionService extends Service {
e.printStackTrace(); e.printStackTrace();
callback.informUser(R.string.unable_to_parse_certificate); callback.informUser(R.string.unable_to_parse_certificate);
} }
}
}).start(); }).start();
} }
@ -1876,6 +1878,10 @@ public class XmppConnectionService extends Service {
X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias); X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias);
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " loaded certificate chain"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + " loaded certificate chain");
Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]); Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]);
if (info == null) {
showErrorToastInUi(R.string.certificate_does_not_contain_jid);
return;
}
if (account.getJid().toBareJid().equals(info.first)) { if (account.getJid().toBareJid().equals(info.first)) {
account.setPrivateKeyAlias(alias); account.setPrivateKeyAlias(alias);
account.setDisplayName(info.second); account.setDisplayName(info.second);
@ -1942,20 +1948,12 @@ public class XmppConnectionService extends Service {
} }
} }
if (account.getXmppConnection() != null) { if (account.getXmppConnection() != null) {
new Thread(new Runnable() { new Thread(() -> disconnect(account, true)).start();
@Override
public void run() {
disconnect(account, true);
} }
}).start(); final Runnable runnable = () -> {
}
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!databaseBackend.deleteAccount(account)) { if (!databaseBackend.deleteAccount(account)) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": unable to delete account"); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": unable to delete account");
} }
}
}; };
mDatabaseWriterExecutor.execute(runnable); mDatabaseWriterExecutor.execute(runnable);
this.accounts.remove(account); this.accounts.remove(account);

View File

@ -1248,10 +1248,7 @@ public class ConversationActivity extends XmppActivity
startActivity(redirectionIntent); startActivity(redirectionIntent);
overridePendingTransition(0,0); overridePendingTransition(0,0);
} else if (Config.MAGIC_CREATE_DOMAIN != null) { } else if (Config.MAGIC_CREATE_DOMAIN != null) {
Intent redirectionIntent =new Intent(this, WelcomeActivity.class); WelcomeActivity.launch(this);
redirectionIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(redirectionIntent);
overridePendingTransition(0,0);
} else { } else {
Intent editAccount = new Intent(this, EditAccountActivity.class); Intent editAccount = new Intent(this, EditAccountActivity.class);
editAccount.putExtra("init",true); editAccount.putExtra("init",true);

View File

@ -353,17 +353,16 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
} }
private void deleteAccount(final Account account) { private void deleteAccount(final Account account) {
AlertDialog.Builder builder = new AlertDialog.Builder( AlertDialog.Builder builder = new AlertDialog.Builder(this);
ManageAccountActivity.this);
builder.setTitle(getString(R.string.mgmt_account_are_you_sure)); builder.setTitle(getString(R.string.mgmt_account_are_you_sure));
builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text)); builder.setMessage(getString(R.string.mgmt_account_delete_confirm_text));
builder.setPositiveButton(getString(R.string.delete), builder.setPositiveButton(getString(R.string.delete),
new OnClickListener() { (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
xmppConnectionService.deleteAccount(account); xmppConnectionService.deleteAccount(account);
selectedAccount = null; selectedAccount = null;
if (xmppConnectionService.getAccounts().size() == 0 && Config.MAGIC_CREATE_DOMAIN != null) {
WelcomeActivity.launch(this);
} }
}); });
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
@ -401,16 +400,14 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
@Override @Override
public void onAccountCreated(Account account) { public void onAccountCreated(Account account) {
switchToAccount(account, true); Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
intent.putExtra("init", true);
startActivity(intent);
} }
@Override @Override
public void informUser(final int r) { public void informUser(final int r) {
runOnUiThread(new Runnable() { runOnUiThread(() -> Toast.makeText(ManageAccountActivity.this, r, Toast.LENGTH_LONG).show());
@Override
public void run() {
Toast.makeText(ManageAccountActivity.this, r, Toast.LENGTH_LONG).show();
}
});
} }
} }

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
@ -93,4 +94,11 @@ public class WelcomeActivity extends XmppActivity {
} }
} }
public static void launch(Activity activity) {
Intent intent = new Intent(activity, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.startActivity(intent);
activity.overridePendingTransition(0,0);
}
} }