forked from GitHub-Mirror/riotX-android
Fix / Block command completion in Quote and Edit mode
This commit is contained in:
parent
c6e428c047
commit
1da0b5be76
@ -20,11 +20,13 @@ import android.text.Spannable
|
|||||||
import com.otaliastudios.autocomplete.AutocompletePolicy
|
import com.otaliastudios.autocomplete.AutocompletePolicy
|
||||||
|
|
||||||
class CommandAutocompletePolicy : AutocompletePolicy {
|
class CommandAutocompletePolicy : AutocompletePolicy {
|
||||||
|
|
||||||
|
var enabled: Boolean = true
|
||||||
|
|
||||||
override fun getQuery(text: Spannable): CharSequence {
|
override fun getQuery(text: Spannable): CharSequence {
|
||||||
if (text.length > 0) {
|
if (text.length > 0) {
|
||||||
return text.substring(1, text.length)
|
return text.substring(1, text.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not happen
|
// Should not happen
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -34,7 +36,7 @@ class CommandAutocompletePolicy : AutocompletePolicy {
|
|||||||
|
|
||||||
// Only if text which starts with '/' and without space
|
// Only if text which starts with '/' and without space
|
||||||
override fun shouldShowPopup(text: Spannable?, cursorPos: Int): Boolean {
|
override fun shouldShowPopup(text: Spannable?, cursorPos: Int): Boolean {
|
||||||
return text?.startsWith("/") == true
|
return enabled && text?.startsWith("/") == true
|
||||||
&& !text.contains(" ")
|
&& !text.contains(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ class RoomDetailFragment :
|
|||||||
private val roomDetailViewModel: RoomDetailViewModel by fragmentViewModel()
|
private val roomDetailViewModel: RoomDetailViewModel by fragmentViewModel()
|
||||||
private val textComposerViewModel: TextComposerViewModel by fragmentViewModel()
|
private val textComposerViewModel: TextComposerViewModel by fragmentViewModel()
|
||||||
private val timelineEventController: TimelineEventController by inject { parametersOf(this) }
|
private val timelineEventController: TimelineEventController by inject { parametersOf(this) }
|
||||||
|
private val commandAutocompletePolicy = CommandAutocompletePolicy()
|
||||||
private val autocompleteCommandPresenter: AutocompleteCommandPresenter by inject { parametersOf(this) }
|
private val autocompleteCommandPresenter: AutocompleteCommandPresenter by inject { parametersOf(this) }
|
||||||
private val autocompleteUserPresenter: AutocompleteUserPresenter by inject { parametersOf(this) }
|
private val autocompleteUserPresenter: AutocompleteUserPresenter by inject { parametersOf(this) }
|
||||||
private val homePermalinkHandler: HomePermalinkHandler by inject()
|
private val homePermalinkHandler: HomePermalinkHandler by inject()
|
||||||
@ -207,6 +208,7 @@ class RoomDetailFragment :
|
|||||||
RoomDetailViewState::roomId) { mode, event, roomId ->
|
RoomDetailViewState::roomId) { mode, event, roomId ->
|
||||||
when (mode) {
|
when (mode) {
|
||||||
SendMode.REGULAR -> {
|
SendMode.REGULAR -> {
|
||||||
|
commandAutocompletePolicy.enabled = true
|
||||||
val uid = session.sessionParams.credentials.userId
|
val uid = session.sessionParams.credentials.userId
|
||||||
val meMember = session.getRoom(roomId)?.getRoomMember(uid)
|
val meMember = session.getRoom(roomId)?.getRoomMember(uid)
|
||||||
AvatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composer_avatar_view)
|
AvatarRenderer.render(meMember?.avatarUrl, uid, meMember?.displayName, composer_avatar_view)
|
||||||
@ -216,6 +218,7 @@ class RoomDetailFragment :
|
|||||||
}
|
}
|
||||||
SendMode.EDIT,
|
SendMode.EDIT,
|
||||||
SendMode.QUOTE -> {
|
SendMode.QUOTE -> {
|
||||||
|
commandAutocompletePolicy.enabled = false
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
//we should ignore? can this happen?
|
//we should ignore? can this happen?
|
||||||
Timber.e("Enter edit mode with no event selected")
|
Timber.e("Enter edit mode with no event selected")
|
||||||
@ -321,7 +324,7 @@ class RoomDetailFragment :
|
|||||||
val elevation = 6f
|
val elevation = 6f
|
||||||
val backgroundDrawable = ColorDrawable(Color.WHITE)
|
val backgroundDrawable = ColorDrawable(Color.WHITE)
|
||||||
Autocomplete.on<Command>(composerEditText)
|
Autocomplete.on<Command>(composerEditText)
|
||||||
.with(CommandAutocompletePolicy())
|
.with(commandAutocompletePolicy)
|
||||||
.with(autocompleteCommandPresenter)
|
.with(autocompleteCommandPresenter)
|
||||||
.with(elevation)
|
.with(elevation)
|
||||||
.with(backgroundDrawable)
|
.with(backgroundDrawable)
|
||||||
|
Loading…
Reference in New Issue
Block a user