From f0224f8ec6a8e7b4ebe06d0a1e3d4d1dc2ad2dd4 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 10 Oct 2019 15:30:34 +1100 Subject: [PATCH] Debug --- .../securesms/conversation/ConversationActivity.java | 12 ++++++++++-- .../thoughtcrime/securesms/loki/UserSelectionView.kt | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 453be36ba5..5da03063cf 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -243,6 +243,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import kotlin.Unit; import network.loki.messenger.R; import nl.komponents.kovenant.combine.Tuple2; @@ -398,6 +399,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } composeText.setSelection(composeText.length(), composeText.length()); composeText.addTextChangedListener(mentionTextWatcher); + userSelectionView.setOnUserSelected(tuple -> { + String oldText = composeText.getText().toString(); + String newText = oldText.substring(0, mentionStartIndex) + tuple.getFirst(); + composeText.setText(newText); + composeText.setSelection(newText.length()); + return Unit.INSTANCE; + }); } }); } @@ -2740,8 +2748,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void onTextChanged(String text) { - if (!enabled) { return; } - int currentEndIndex = (text.length() != 0) ? text.length() - 1 : 0; + if (!enabled | text.length() == 0) { return; } + int currentEndIndex = text.length() - 1; char lastCharacter = text.charAt(currentEndIndex); LokiUserDatabase userDatabase = DatabaseFactory.getLokiUserDatabase(ConversationActivity.this); if (lastCharacter == '@') { diff --git a/src/org/thoughtcrime/securesms/loki/UserSelectionView.kt b/src/org/thoughtcrime/securesms/loki/UserSelectionView.kt index 3c56409012..ab5da3cf7e 100644 --- a/src/org/thoughtcrime/securesms/loki/UserSelectionView.kt +++ b/src/org/thoughtcrime/securesms/loki/UserSelectionView.kt @@ -14,6 +14,7 @@ class UserSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: In private var users = listOf>() set(newValue) { field = newValue; userSelectionViewAdapter.users = newValue } private var hasGroupContext = false + var onUserSelected: ((Tuple2) -> Unit)? = null private val userSelectionViewAdapter by lazy { Adapter(context) } @@ -49,6 +50,9 @@ class UserSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: In init { adapter = userSelectionViewAdapter userSelectionViewAdapter.users = users + setOnItemClickListener { _, _, position, _ -> + onUserSelected?.invoke(users[position]) + } } fun show(users: List>, threadID: Long) {