This commit is contained in:
Niels Andriesse 2019-10-10 15:30:34 +11:00
parent 871f629e64
commit f0224f8ec6
2 changed files with 14 additions and 2 deletions

View File

@ -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 == '@') {

View File

@ -14,6 +14,7 @@ class UserSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: In
private var users = listOf<Tuple2<String, String>>()
set(newValue) { field = newValue; userSelectionViewAdapter.users = newValue }
private var hasGroupContext = false
var onUserSelected: ((Tuple2<String, String>) -> 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<Tuple2<String, String>>, threadID: Long) {