forked from upstream-mirrors/quik
changes to disable reply controls and display a relevant message to the user on compose screen if all other participant numbers are non-replyable (ie alphanumeric sender id)
This commit is contained in:
@@ -40,6 +40,8 @@ import android.view.View
|
||||
import android.view.View.OnTouchListener
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.constraintlayout.widget.ConstraintSet
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@@ -289,6 +291,26 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
|
||||
// if not in editing mode, and there are no non-me participants that can be sent to,
|
||||
// hide controls that allow constructing a reply and inform user no valid recipients
|
||||
if (!state.editingMode && (state.validRecipientNumbers == 0)) {
|
||||
composeBar.visibility = View.GONE
|
||||
noValidRecipients.visibility = View.VISIBLE
|
||||
|
||||
// change constraint of messageList to constrain bottom to top of noValidRecipients
|
||||
val constraintLayout = findViewById<ConstraintLayout>(R.id.contentView)
|
||||
val constraintSet = ConstraintSet()
|
||||
constraintSet.clone(constraintLayout)
|
||||
constraintSet.connect(
|
||||
R.id.messageList,
|
||||
ConstraintSet.BOTTOM,
|
||||
R.id.noValidRecipients,
|
||||
ConstraintSet.TOP,
|
||||
0
|
||||
)
|
||||
constraintSet.applyTo(constraintLayout)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearSelection() = messageAdapter.clearSelection()
|
||||
|
||||
@@ -44,5 +44,6 @@ data class ComposeState(
|
||||
val attaching: Boolean = false,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfoCompat? = null,
|
||||
val canSend: Boolean = false
|
||||
val canSend: Boolean = false,
|
||||
val validRecipientNumbers: Int = 1,
|
||||
)
|
||||
@@ -207,6 +207,23 @@ class ComposeViewModel @Inject constructor(
|
||||
.filter { messages -> messages.isValid }
|
||||
.subscribe(searchResults::onNext)
|
||||
|
||||
// on conversation change/init, work out how many non-me participants of the conversation
|
||||
// have a valid address (subscriber number) for replying/sending to
|
||||
disposables += conversation
|
||||
.distinctUntilChanged { conversation -> conversation.id }
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map { conversation ->
|
||||
var possibleNumbers = 0
|
||||
conversation.recipients.forEach { recipient ->
|
||||
if (phoneNumberUtils.isPossibleNumber(recipient.address))
|
||||
++possibleNumbers
|
||||
}
|
||||
possibleNumbers
|
||||
}
|
||||
.subscribe { validRecipientNumbers ->
|
||||
newState { copy(validRecipientNumbers = validRecipientNumbers) }
|
||||
}
|
||||
|
||||
disposables += Observables.combineLatest(searchSelection, searchResults) { selected, messages ->
|
||||
if (selected == -1L) {
|
||||
messages.lastOrNull()?.let { message -> searchSelection.onNext(message.id) }
|
||||
|
||||
Reference in New Issue
Block a user