diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-12-30 21:19:49 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-12-30 21:19:49 +0100 |
commit | 4e78a72af907ac32eccd87ebdbf6ec44a4336d36 (patch) | |
tree | 522e5198719f28c3f6d4d3a81376e9681a8c87a6 /src/main/java/de/pixart | |
parent | 15451513504c1f8692b05be9e6fbc285a43b1026 (diff) |
add ability to set nickname in profile
Diffstat (limited to 'src/main/java/de/pixart')
3 files changed, 117 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index bd157f442..edc0a2e67 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -236,7 +236,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { if (bookmark.getConversation() != null) { return get(bookmark.getConversation(), size, cachedOnly); } else { - final Jid jid = bookmark.getFullJid(); + Jid jid = bookmark.getJid(); Account account = bookmark.getAccount(); Contact contact = jid == null ? null : account.getRoster().getContact(jid); if (contact != null && contact.getAvatarFilename() != null) { @@ -407,8 +407,13 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size); if (avatar == null) { + final String displayName = account.getDisplayName(); final String jid = account.getJid().asBareJid().toEscapedString(); - avatar = get(jid, null, size, false); + if (QuickConversationsService.isQuicksy() && !TextUtils.isEmpty(displayName)) { + avatar = get(displayName, jid, size, false); + } else { + avatar = get(jid, null, size, false); + } } mXmppConnectionService.getBitmapCache().put(KEY, avatar); return avatar; diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 123591b03..d04289d22 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -593,6 +593,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.port.addTextChangedListener(mTextWatcher); this.binding.saveButton.setOnClickListener(this.mSaveButtonClickListener); this.binding.cancelButton.setOnClickListener(this.mCancelButtonClickListener); + this.binding.actionEditYourName.setOnClickListener(this::onEditYourNameClicked); if (savedInstanceState != null && savedInstanceState.getBoolean("showMoreTable")) { changeMoreTableVisibility(true); } @@ -617,6 +618,21 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat }); } + private void onEditYourNameClicked(View view) { + quickEdit(mAccount.getDisplayName(), R.string.your_name, value -> { + final String displayName = value.trim(); + updateDisplayName(displayName); + mAccount.setDisplayName(displayName); + xmppConnectionService.publishDisplayName(mAccount); + refreshAvatar(); + return null; + }, true); + } + + private void refreshAvatar() { + binding.avater.setImageBitmap(avatarService().get(mAccount, (int) getResources().getDimension(R.dimen.avatar_on_details_screen_size))); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { super.onCreateOptionsMenu(menu); @@ -1011,6 +1027,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.binding.accountJid.setEnabled(editable); this.binding.accountJid.setFocusable(editable); this.binding.accountJid.setFocusableInTouchMode(editable); + this.binding.accountJid.setCursorVisible(editable); + + final String displayName = mAccount.getDisplayName(); + updateDisplayName(displayName); final boolean tooglePassword = mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || !mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY); final boolean editPassword = !mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) || (!mAccount.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY) && QuickConversationsService.isConversations()) || mAccount.getLastErrorStatus() == Account.State.UNAUTHORIZED; @@ -1228,6 +1248,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat return "0"; } + private void updateDisplayName(String displayName) { + if (TextUtils.isEmpty(displayName)) { + this.binding.yourName.setText(R.string.no_name_set_instructions); + this.binding.yourName.setTextAppearance(this, R.style.TextAppearance_Conversations_Body1_Tertiary); + } else { + this.binding.yourName.setText(displayName); + this.binding.yourName.setTextAppearance(this, R.style.TextAppearance_Conversations_Body1); + } + } + private void removeErrorsOnAllBut(TextInputLayout exception) { if (this.binding.accountJidLayout != exception) { this.binding.accountJidLayout.setErrorEnabled(false); diff --git a/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java new file mode 100644 index 000000000..ac400b9f3 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/EnterNameActivity.java @@ -0,0 +1,80 @@ +package de.pixart.messenger.ui; + +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.os.Bundle; +import android.support.v7.widget.Toolbar; +import android.view.View; + +import java.util.concurrent.atomic.AtomicBoolean; +import de.pixart.messenger.R; +import de.pixart.messenger.databinding.ActivityEnterNameBinding; +import de.pixart.messenger.entities.Account; +import de.pixart.messenger.services.XmppConnectionService; +import de.pixart.messenger.utils.AccountUtils; + +public class EnterNameActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate { + + private ActivityEnterNameBinding binding; + + private Account account; + + private AtomicBoolean setNick = new AtomicBoolean(false); + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + 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)); + } + + 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); + } + finish(); + } + + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + savedInstanceState.putBoolean("set_nick", this.setNick.get()); + super.onSaveInstanceState(savedInstanceState); + } + + @Override + protected void refreshUiReal() { + checkSuggestPreviousNick(); + } + + @Override + void onBackendConnected() { + this.account = AccountUtils.getFirst(xmppConnectionService); + checkSuggestPreviousNick(); + } + + private void checkSuggestPreviousNick() { + String displayName = this.account == null ? null : this.account.getDisplayName(); + if (displayName != null) { + if (setNick.compareAndSet(false, true) && this.binding.name.getText().length() == 0) { + this.binding.name.getText().append(displayName); + } + } + } + + @Override + public void onAccountUpdate() { + refreshUi(); + } +}
\ No newline at end of file |