From d74cf5b6f0ed5b493ea4953f57a93347c03253b3 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 14 Mar 2019 21:26:41 +0100 Subject: rework user name input during account creation --- .../pixart/messenger/ui/EditAccountActivity.java | 30 ++++++++++------------ .../de/pixart/messenger/ui/EnterNameActivity.java | 7 ++--- src/main/res/layout/activity_edit_account.xml | 3 ++- 3 files changed, 18 insertions(+), 22 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 456b907df..f62d68bef 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -98,6 +98,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private AlertDialog mCaptchaDialog = null; private final AtomicBoolean mPendingReconnect = new AtomicBoolean(false); + private final AtomicBoolean redirectInProgress = new AtomicBoolean(false); private Jid jidToEdit; private boolean mInitMode = false; private boolean mUsernameMode = Config.DOMAIN_LOCK != null; @@ -298,10 +299,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat overridePendingTransition(R.animator.fade_in, R.animator.fade_out); finish(); } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) { - if (!mFetchingAvatar) { - mFetchingAvatar = true; - xmppConnectionService.checkForAvatar(mAccount, mAvatarFetchCallback); - } + runOnUiThread(this::performPostVerificationRedirect); } if (mAccount != null) { updateAccountInformation(false); @@ -309,6 +307,15 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat updateSaveButton(); } + private void performPostVerificationRedirect() { + if (redirectInProgress.compareAndSet(false, true)) { + Intent intent = new Intent(this, EnterNameActivity.class); + startActivity(intent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + finish(); + } + } + @Override public boolean onNavigateUp() { deleteAccountAndReturnIfNecessary(); @@ -624,18 +631,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } private void onEditYourNameClicked(View view) { - String nick; - try { - if (mAccount != null) { - nick = mAccount.getDisplayName(); - } else { - nick = ""; - } - } catch (Exception e) { - e.printStackTrace(); - nick = ""; - } - quickEdit(nick, R.string.your_name, value -> { + quickEdit(mAccount.getDisplayName(), R.string.your_name, value -> { final String displayName = value.trim(); updateDisplayName(displayName); mAccount.setDisplayName(displayName); @@ -742,6 +738,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat setTitle(getString(R.string.account_details)); configureActionBar(getSupportActionBar(), !openedFromNotification); } else { + this.binding.yourNameBox.setVisibility(View.GONE); this.binding.avater.setVisibility(View.GONE); configureActionBar(getSupportActionBar(), !(init && Config.MAGIC_CREATE_DOMAIN == null)); setTitle(R.string.action_add_account); @@ -1112,6 +1109,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } else { this.binding.accountRegisterNew.setVisibility(mInitMode ? View.VISIBLE : View.GONE); } + this.binding.yourNameBox.setVisibility(mInitMode ? View.GONE : View.VISIBLE); if (this.mAccount.isOnlineAndConnected() && !this.mFetchingAvatar) { Features features = this.mAccount.getXmppConnection().getFeatures(); this.binding.stats.setVisibility(View.VISIBLE); diff --git a/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java index a1a6b28b5..1f59901a6 100644 --- a/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java @@ -28,22 +28,19 @@ 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.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick",false)); + this.setNick.set(savedInstanceState != null && savedInstanceState.getBoolean("set_nick", false)); } private void next(View view) { if (account != null) { - String name = this.binding.name.getText().toString().trim(); - account.setDisplayName(name); - xmppConnectionService.publishDisplayName(account); - Intent intent = new Intent(this, PublishProfilePictureActivity.class); intent.putExtra(PublishProfilePictureActivity.EXTRA_ACCOUNT, account.getJid().asBareJid().toEscapedString()); intent.putExtra("setup", true); startActivity(intent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } finish(); } diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index 6aced7fd3..bb28dd52e 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -49,7 +49,8 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentTop="true" - android:layout_marginBottom="@dimen/activity_vertical_margin"> + android:layout_marginBottom="@dimen/activity_vertical_margin" + android:visibility="gone">