From 21615477ed76c68239db45239d75cc3d386e60f4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 16 Dec 2017 20:38:14 +0100 Subject: [PATCH] transport invitee from welcome activity to start conversations activity --- .../conversations/ui/EditAccountActivity.java | 43 +++++++------ .../conversations/ui/MagicCreateActivity.java | 60 +++++++++---------- .../ui/PublishProfilePictureActivity.java | 8 +-- .../ui/StartConversationActivity.java | 17 +++++- .../conversations/ui/UriHandlerActivity.java | 1 + .../conversations/ui/WelcomeActivity.java | 58 +++++++++++------- 6 files changed, 106 insertions(+), 81 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 78aa95310..61932b236 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -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,30 +369,27 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat }; protected void finishInitialSetup(final Avatar avatar) { - runOnUiThread(new Runnable() { - - @Override - public void run() { - hideKeyboard(); - final Intent intent; - final XmppConnection connection = mAccount.getXmppConnection(); - 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); - } + runOnUiThread(() -> { + hideKeyboard(); + final Intent intent; + final XmppConnection connection = mAccount.getXmppConnection(); + 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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.putExtra("init", true); } - startActivity(intent); - finish(); + } else { + 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(); }); } diff --git a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java index 0b7db2bbf..52d984794 100644 --- a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java @@ -54,39 +54,37 @@ 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) { - String username = mUsername.getText().toString(); - if (username.contains("@") || username.length() < 3) { + 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)); + 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.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() { 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(); diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index 32e3d41f3..f7c70d26b 100644 --- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -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); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 631acf295..cb532fcd2 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -268,7 +268,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU if (this.mTheme != theme) { recreate(); } else { - askForContactsPermissions(); + 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()) { diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index d28c1b340..d0b36f16d 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -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; } diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java index 5dc4b83f2..aae788e65 100644 --- a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -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); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - startActivity(intent); - } + 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) { - List 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); - } else if (accounts.size() >= 1) { - intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class); - } - startActivity(intent); + final Button useOwnProvider = findViewById(R.id.use_own_provider); + useOwnProvider.setOnClickListener(v -> { + List 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); + } 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)); + } + } + }