From 48d282a864f54473c06f6b1c364eaf6f6a2ad601 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 11 Oct 2019 13:37:56 +1100 Subject: [PATCH] Require the user to pick a display name --- ..._details.xml => activity_display_name.xml} | 4 +-- res/values/strings.xml | 2 +- .../ApplicationPreferencesActivity.java | 2 +- .../securesms/ConversationListActivity.java | 2 +- .../securesms/CreateProfileActivity.java | 5 +++- .../securesms/components/AvatarImageView.java | 2 +- .../securesms/loki/DisplayNameActivity.kt | 26 +++++++++---------- .../widgets/ProfilePreference.java | 2 +- 8 files changed, 22 insertions(+), 23 deletions(-) rename res/layout/{activity_account_details.xml => activity_display_name.xml} (94%) diff --git a/res/layout/activity_account_details.xml b/res/layout/activity_display_name.xml similarity index 94% rename from res/layout/activity_account_details.xml rename to res/layout/activity_display_name.xml index 04afffbcf9..fc934a4df0 100644 --- a/res/layout/activity_account_details.xml +++ b/res/layout/activity_display_name.xml @@ -2,10 +2,8 @@ + android:layout_height="match_parent"> Create Your Loki Messenger Account Enter a name to be shown to your contacts - Display Name (Optional) + Display Name Next Create Your Loki Messenger Account diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 6799c9a3c6..f9b4cd3b15 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -157,7 +157,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA super.onCreate(icicle); String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(getContext()); - boolean isMasterDevice = (masterHexEncodedPublicKey != null); + boolean isMasterDevice = (masterHexEncodedPublicKey == null); Preference profilePreference = this.findPreference(PREFERENCE_CATEGORY_PROFILE); // Hide if this is a slave device diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index ddd3ad3dff..b817a2b16e 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -203,7 +203,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit int height = profilePictureImageView.getHeight(); if (width == 0 || height == 0) return true; profilePictureImageView.getViewTreeObserver().removeOnPreDrawListener(this); - JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, recipient.getAddress().serialize()); + JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, recipient.getAddress().serialize().toLowerCase()); profilePictureImageView.setImageDrawable(identicon); return true; } diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index 2d39b63fb7..cae89065d3 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -229,7 +229,10 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { - if (s.toString().getBytes().length > ProfileCipher.NAME_PADDED_LENGTH) { + if (s.toString().isEmpty()) { + name.getInput().setError("Invalid"); + finishButton.setEnabled(false); + } else if (s.toString().getBytes().length > ProfileCipher.NAME_PADDED_LENGTH) { name.getInput().setError(getString(R.string.CreateProfileActivity_too_long)); finishButton.setEnabled(false); } else if (name.getInput().getError() != null || !finishButton.isEnabled()) { diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index 9eb5f9cec8..9158ab0689 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -119,7 +119,7 @@ public class AvatarImageView extends AppCompatImageView { image = new GeneratedContactPhoto(name, R.drawable.ic_profile_default).asDrawable(context, fallbackColor.toAvatarColor(context)); } else { - image = new JazzIdenticonDrawable(w, h, recipient.getAddress().serialize()); + image = new JazzIdenticonDrawable(w, h, recipient.getAddress().serialize().toLowerCase()); } setImageDrawable(image); } diff --git a/src/org/thoughtcrime/securesms/loki/DisplayNameActivity.kt b/src/org/thoughtcrime/securesms/loki/DisplayNameActivity.kt index 3685a2ad92..1db9912be5 100644 --- a/src/org/thoughtcrime/securesms/loki/DisplayNameActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/DisplayNameActivity.kt @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.loki import android.content.Intent import android.os.Bundle import android.view.inputmethod.InputMethodManager -import kotlinx.android.synthetic.main.activity_account_details.* +import kotlinx.android.synthetic.main.activity_display_name.* import network.loki.messenger.R import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity @@ -19,21 +19,21 @@ class DisplayNameActivity : BaseActionBarActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_account_details) + setContentView(R.layout.activity_display_name) nextButton.setOnClickListener { continueIfPossible() } Analytics.shared.track("Display Name Screen Viewed") } private fun continueIfPossible() { - val uncheckedName = nameEditText.text.toString() - val name = if (uncheckedName.isNotEmpty()) { uncheckedName.trim() } else { null } - if (name != null) { - if (name.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) { - return nameEditText.input.setError("Too Long") - } else { - Analytics.shared.track("Display Name Updated") - TextSecurePreferences.setProfileName(this, name) - } + val name = nameEditText.text.toString() + if (name.isEmpty()) { + return nameEditText.input.setError("Invalid") + } + if (name.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) { + return nameEditText.input.setError("Too Long") + } else { + Analytics.shared.track("Display Name Updated") + TextSecurePreferences.setProfileName(this, name) } val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(nameEditText.windowToken, 0) @@ -49,8 +49,6 @@ class DisplayNameActivity : BaseActionBarActivity() { val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).privateKey.serialize() val apiDatabase = DatabaseFactory.getLokiAPIDatabase(this) val userDatabase = DatabaseFactory.getLokiUserDatabase(this) - if (name != null) { - LokiGroupChatAPI(userHexEncodedPublicKey, userPrivateKey, apiDatabase, userDatabase).setDisplayName(name, LokiGroupChatAPI.publicChatServer) - } + LokiGroupChatAPI(userHexEncodedPublicKey, userPrivateKey, apiDatabase, userDatabase).setDisplayName(name, LokiGroupChatAPI.publicChatServer) } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java index 49e60e1f97..0d464dd325 100644 --- a/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java +++ b/src/org/thoughtcrime/securesms/preferences/widgets/ProfilePreference.java @@ -100,7 +100,7 @@ public class ProfilePreference extends Preference { int height = avatarView.getHeight(); if (width == 0 || height == 0) return true; avatarView.getViewTreeObserver().removeOnPreDrawListener(this); - JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, userHexEncodedPublicKey); + JazzIdenticonDrawable identicon = new JazzIdenticonDrawable(width, height, userHexEncodedPublicKey.toLowerCase()); avatarView.setImageDrawable(identicon); return true; }