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)
&& xmppConnectionService.getAccounts().size() == 1) {
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,10 +369,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
};
protected void finishInitialSetup(final Avatar avatar) {
runOnUiThread(new Runnable() {
@Override
public void run() {
runOnUiThread(() -> {
hideKeyboard();
final Intent intent;
final XmppConnection connection = mAccount.getXmppConnection();
@ -388,9 +387,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (wasFirstAccount) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
WelcomeActivity.addInvitee(intent, getIntent());
startActivity(intent);
finish();
}
});
}

View file

@ -54,13 +54,11 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
}
super.onCreate(savedInstanceState);
setContentView(R.layout.magic_create);
mFullJidDisplay = (TextView) findViewById(R.id.full_jid);
mUsername = (EditText) findViewById(R.id.username);
mFullJidDisplay = findViewById(R.id.full_jid);
mUsername = findViewById(R.id.username);
mRandom = new SecureRandom();
Button next = (Button) findViewById(R.id.create_account);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Button next = findViewById(R.id.create_account);
next.setOnClickListener(v -> {
String username = mUsername.getText().toString();
if (username.contains("@") || username.length() < 3) {
mUsername.setError(getString(R.string.invalid_username));
@ -82,20 +80,20 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
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.requestFocus();
}
}
}
});
mUsername.addTextChangedListener(this);
}
private String createPassword() {
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)));
}
return builder.toString();

View file

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

View file

@ -268,8 +268,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (this.mTheme != theme) {
recreate();
} else {
Intent i = getIntent();
if (i == null || !i.hasExtra(WelcomeActivity.EXTRA_INVITEE)) {
askForContactsPermissions();
}
}
mConferenceAdapter.refreshSettings();
mContactsAdapter.refreshSettings();
}
@ -786,7 +789,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
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;
}
switch (intent.getAction()) {

View file

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

View file

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