diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger')
6 files changed, 98 insertions, 74 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 3f9c6c48d..c461370eb 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -328,7 +328,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); } } @@ -383,30 +385,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/de/pixart/messenger/ui/MagicCreateActivity.java b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java index b3dc782ad..6a2beaf8c 100644 --- a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java @@ -58,35 +58,33 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { mUsername = findViewById(R.id.username); mRandom = new SecureRandom(); Button next = 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) { + 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(); - } } } }); diff --git a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java index 415e5a5df..8ac690ea9 100644 --- a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java +++ b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java @@ -62,8 +62,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); } @@ -109,9 +109,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/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index e77ef8664..d765921a5 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -285,7 +285,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(); @@ -789,7 +792,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/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java index c5c2bcffe..ad289658a 100644 --- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java +++ b/src/main/java/de/pixart/messenger/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/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index a764a5d8e..3b6954f8f 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -38,9 +38,11 @@ import de.pixart.messenger.entities.Account; import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.utils.EncryptDecryptFile; +import de.pixart.messenger.utils.XmppUri; public class WelcomeActivity extends XmppActivity { + public static final String EXTRA_INVITEE = "eu.siacs.conversations.invitee"; boolean importSuccessful = false; @Override @@ -97,28 +99,24 @@ public class WelcomeActivity extends XmppActivity { }); final Button createAccount = 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); - } + 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 = findViewById(R.id.use_existing_account); - useOwnProvider.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View 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); - } else if (accounts.size() >= 1) { - intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class); - } - startActivity(intent); + 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); + } else if (accounts.size() >= 1) { + intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class); } + addInvitee(intent); + startActivity(intent); }); } @@ -314,4 +312,19 @@ public class WelcomeActivity extends XmppActivity { } } + 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)); + } + } }
\ No newline at end of file |