From fb3951c6ee7129e07d84753e63d12ee79b78ca82 Mon Sep 17 00:00:00 2001 From: Arne Date: Sun, 23 Jan 2022 16:40:41 +0100 Subject: [PATCH] allow skipping some entry screens if you have an existing account (Christian Schneppe) --- .../conversations/ui/EditAccountActivity.java | 1 + .../conversations/ui/EnterNameActivity.java | 31 +++++++++++++++++++ src/main/res/layout/activity_enter_name.xml | 10 ++++++ 3 files changed, 42 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index d46b6f004..f4b53f06e 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -330,6 +330,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (redirectInProgress.compareAndSet(false, true)) { Intent intent = new Intent(this, EnterNameActivity.class); intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().asBareJid().toString()); + intent.putExtra("existing", mExisting); startActivity(intent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); finish(); diff --git a/src/main/java/eu/siacs/conversations/ui/EnterNameActivity.java b/src/main/java/eu/siacs/conversations/ui/EnterNameActivity.java index b1f5eec4f..bf1317662 100644 --- a/src/main/java/eu/siacs/conversations/ui/EnterNameActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EnterNameActivity.java @@ -19,6 +19,7 @@ public class EnterNameActivity extends XmppActivity implements XmppConnectionSer private ActivityEnterNameBinding binding; private Account account; + private boolean mExisting = false; private AtomicBoolean setNick = new AtomicBoolean(false); @Override @@ -27,6 +28,7 @@ public class EnterNameActivity extends XmppActivity implements XmppConnectionSer this.binding = DataBindingUtil.setContentView(this, R.layout.activity_enter_name); setSupportActionBar((Toolbar) this.binding.toolbar); this.binding.next.setOnClickListener(this::next); + this.binding.skip.setOnClickListener(this::skip); updateNextButton(); this.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick", false)); } @@ -40,6 +42,18 @@ public class EnterNameActivity extends XmppActivity implements XmppConnectionSer this.binding.next.setText(R.string.next); } } + @Override + protected void onStart() { + super.onStart(); + final Intent intent = getIntent(); + final int theme = findTheme(); + if (this.mTheme != theme) { + recreate(); + } else if (intent != null) { + boolean existing = intent.getBooleanExtra("existing", false); + this.mExisting = existing; + } + } private void next(View view) { FirstStartManager firstStartManager = new FirstStartManager(this); @@ -62,6 +76,23 @@ public class EnterNameActivity extends XmppActivity implements XmppConnectionSer } finish(); } + private void skip(View view) { + if (account != null) { + String name = this.binding.name.getText().toString().trim(); + account.setDisplayName(name); + xmppConnectionService.publishDisplayName(account); + final Intent intent = new Intent(getApplicationContext(), StartConversationActivity.class); + if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) { + intent.putExtra("init", true); + } + StartConversationActivity.addInviteUri(intent, getIntent()); + intent.putExtra(EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); + startActivity(intent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + finish(); + } + finish(); + } @Override public void onSaveInstanceState(Bundle savedInstanceState) { diff --git a/src/main/res/layout/activity_enter_name.xml b/src/main/res/layout/activity_enter_name.xml index fcdb62ae4..1850850b2 100644 --- a/src/main/res/layout/activity_enter_name.xml +++ b/src/main/res/layout/activity_enter_name.xml @@ -58,6 +58,16 @@ android:layout_alignParentBottom="true" android:text="@string/next" android:textColor="?attr/colorAccent" /> +