transport invitee from welcome activity to start conversations activity

This commit is contained in:
Daniel Gultsch 2017-12-16 20:38:14 +01:00
parent c58fcb1dc6
commit 21615477ed
6 changed files with 106 additions and 81 deletions

View File

@ -312,7 +312,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
&& mAccount.isOptionSet(Account.OPTION_REGISTER) && mAccount.isOptionSet(Account.OPTION_REGISTER)
&& xmppConnectionService.getAccounts().size() == 1) { && xmppConnectionService.getAccounts().size() == 1) {
xmppConnectionService.deleteAccount(mAccount); xmppConnectionService.deleteAccount(mAccount);
startActivity(new Intent(EditAccountActivity.this, WelcomeActivity.class)); Intent intent = new Intent(EditAccountActivity.this, WelcomeActivity.class);
WelcomeActivity.addInvitee(intent, getIntent());
startActivity(intent);
} }
} }
@ -367,30 +369,27 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}; };
protected void finishInitialSetup(final Avatar avatar) { protected void finishInitialSetup(final Avatar avatar) {
runOnUiThread(new Runnable() { runOnUiThread(() -> {
hideKeyboard();
@Override final Intent intent;
public void run() { final XmppConnection connection = mAccount.getXmppConnection();
hideKeyboard(); final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
final Intent intent; if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
final XmppConnection connection = mAccount.getXmppConnection(); intent = new Intent(getApplicationContext(), StartConversationActivity.class);
final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
intent = new Intent(getApplicationContext(), StartConversationActivity.class);
if (wasFirstAccount) {
intent.putExtra("init", true);
}
} else {
intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
intent.putExtra("setup", true);
}
if (wasFirstAccount) { if (wasFirstAccount) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra("init", true);
} }
startActivity(intent); } else {
finish(); intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
intent.putExtra("setup", true);
} }
if (wasFirstAccount) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
WelcomeActivity.addInvitee(intent, getIntent());
startActivity(intent);
finish();
}); });
} }

View File

@ -54,39 +54,37 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.magic_create); setContentView(R.layout.magic_create);
mFullJidDisplay = (TextView) findViewById(R.id.full_jid); mFullJidDisplay = findViewById(R.id.full_jid);
mUsername = (EditText) findViewById(R.id.username); mUsername = findViewById(R.id.username);
mRandom = new SecureRandom(); mRandom = new SecureRandom();
Button next = (Button) findViewById(R.id.create_account); Button next = findViewById(R.id.create_account);
next.setOnClickListener(new View.OnClickListener() { next.setOnClickListener(v -> {
@Override String username = mUsername.getText().toString();
public void onClick(View v) { if (username.contains("@") || username.length() < 3) {
String username = mUsername.getText().toString(); mUsername.setError(getString(R.string.invalid_username));
if (username.contains("@") || username.length() < 3) { mUsername.requestFocus();
} else {
mUsername.setError(null);
try {
Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) {
account = new Account(jid, createPassword());
account.setOption(Account.OPTION_REGISTER, true);
account.setOption(Account.OPTION_DISABLED, true);
account.setOption(Account.OPTION_MAGIC_CREATE, true);
xmppConnectionService.createAccount(account);
}
Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
intent.putExtra("init", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
WelcomeActivity.addInvitee(intent, getIntent());
startActivity(intent);
} catch (InvalidJidException e) {
mUsername.setError(getString(R.string.invalid_username)); mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus(); mUsername.requestFocus();
} else {
mUsername.setError(null);
try {
Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) {
account = new Account(jid, createPassword());
account.setOption(Account.OPTION_REGISTER, true);
account.setOption(Account.OPTION_DISABLED, true);
account.setOption(Account.OPTION_MAGIC_CREATE, true);
xmppConnectionService.createAccount(account);
}
Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
intent.putExtra("init", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
startActivity(intent);
} catch (InvalidJidException e) {
mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus();
}
} }
} }
}); });
@ -95,7 +93,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
private String createPassword() { private String createPassword() {
StringBuilder builder = new StringBuilder(PW_LENGTH); StringBuilder builder = new StringBuilder(PW_LENGTH);
for(int i = 0; i < PW_LENGTH; ++i) { for (int i = 0; i < PW_LENGTH; ++i) {
builder.append(CHARS.charAt(mRandom.nextInt(CHARS.length() - 1))); builder.append(CHARS.charAt(mRandom.nextInt(CHARS.length() - 1)));
} }
return builder.toString(); return builder.toString();

View File

@ -61,8 +61,8 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
public void success(Avatar object) { public void success(Avatar object) {
runOnUiThread(() -> { runOnUiThread(() -> {
if (mInitialAccountSetup) { if (mInitialAccountSetup) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(), StartConversationActivity.class);
StartConversationActivity.class); WelcomeActivity.addInvitee(intent, getIntent());
intent.putExtra("init", true); intent.putExtra("init", true);
startActivity(intent); startActivity(intent);
} }
@ -108,9 +108,9 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
}); });
this.cancelButton.setOnClickListener(v -> { this.cancelButton.setOnClickListener(v -> {
if (mInitialAccountSetup) { if (mInitialAccountSetup) {
Intent intent = new Intent(getApplicationContext(), Intent intent = new Intent(getApplicationContext(), StartConversationActivity.class);
StartConversationActivity.class);
if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) { if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) {
WelcomeActivity.addInvitee(intent, getIntent());
intent.putExtra("init", true); intent.putExtra("init", true);
} }
startActivity(intent); startActivity(intent);

View File

@ -268,7 +268,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (this.mTheme != theme) { if (this.mTheme != theme) {
recreate(); recreate();
} else { } else {
askForContactsPermissions(); Intent i = getIntent();
if (i == null || !i.hasExtra(WelcomeActivity.EXTRA_INVITEE)) {
askForContactsPermissions();
}
} }
mConferenceAdapter.refreshSettings(); mConferenceAdapter.refreshSettings();
mContactsAdapter.refreshSettings(); mContactsAdapter.refreshSettings();
@ -786,7 +789,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
protected boolean handleIntent(Intent intent) { protected boolean handleIntent(Intent intent) {
if (intent == null || intent.getAction() == null) { if (intent == null) {
return false;
}
final String invitee = intent.getStringExtra(WelcomeActivity.EXTRA_INVITEE);
if (invitee != null) {
Invite invite = new Invite("xmpp:" + invitee);
if (invite.isJidValid()) {
return invite.invite();
}
}
if (intent.getAction() == null) {
return false; return false;
} }
switch (intent.getAction()) { switch (intent.getAction()) {

View File

@ -35,6 +35,7 @@ public class UriHandlerActivity extends Activity {
if (accounts.size() == 0) { if (accounts.size() == 0) {
intent = new Intent(getApplicationContext(), WelcomeActivity.class); intent = new Intent(getApplicationContext(), WelcomeActivity.class);
WelcomeActivity.addInvitee(intent, xmppUri);
startActivity(intent); startActivity(intent);
return; return;
} }

View File

@ -4,16 +4,18 @@ import android.app.ActionBar;
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;
import android.view.View;
import android.widget.Button; import android.widget.Button;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.XmppUri;
public class WelcomeActivity extends XmppActivity { public class WelcomeActivity extends XmppActivity {
public static final String EXTRA_INVITEE = "eu.siacs.conversations.invitee";
@Override @Override
protected void refreshUiReal() { protected void refreshUiReal() {
@ -45,31 +47,43 @@ public class WelcomeActivity extends XmppActivity {
ab.setDisplayShowHomeEnabled(false); ab.setDisplayShowHomeEnabled(false);
ab.setDisplayHomeAsUpEnabled(false); ab.setDisplayHomeAsUpEnabled(false);
} }
final Button createAccount = (Button) findViewById(R.id.create_account); final Button createAccount = findViewById(R.id.create_account);
createAccount.setOnClickListener(new View.OnClickListener() { createAccount.setOnClickListener(v -> {
@Override final Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class);
public void onClick(View v) { intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class); addInvitee(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent);
startActivity(intent);
}
}); });
final Button useOwnProvider = (Button) findViewById(R.id.use_own_provider); final Button useOwnProvider = findViewById(R.id.use_own_provider);
useOwnProvider.setOnClickListener(new View.OnClickListener() { useOwnProvider.setOnClickListener(v -> {
@Override List<Account> accounts = xmppConnectionService.getAccounts();
public void onClick(View v) { Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class);
List<Account> accounts = xmppConnectionService.getAccounts(); if (accounts.size() == 1) {
Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class); intent.putExtra("jid", accounts.get(0).getJid().toBareJid().toString());
if (accounts.size() == 1) { intent.putExtra("init", true);
intent.putExtra("jid",accounts.get(0).getJid().toBareJid().toString()); } else if (accounts.size() >= 1) {
intent.putExtra("init",true); intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class);
} else if (accounts.size() >= 1) {
intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class);
}
startActivity(intent);
} }
addInvitee(intent);
startActivity(intent);
}); });
} }
public void addInvitee(Intent intent) {
addInvitee(intent, getIntent());
}
public static void addInvitee(Intent intent, XmppUri uri) {
if (uri.isJidValid()) {
intent.putExtra(EXTRA_INVITEE, uri.getJid().toString());
}
}
public static void addInvitee(Intent to, Intent from) {
if (from != null && from.hasExtra(EXTRA_INVITEE)) {
to.putExtra(EXTRA_INVITEE, from.getStringExtra(EXTRA_INVITEE));
}
}
} }