added a 'send now' button to delay sent sms. user can now long press 'send now' to send a delayed message immediately

This commit is contained in:
gavine99
2025-01-19 21:03:28 +11:00
parent 77ce54fd1b
commit 43b8e70a12
6 changed files with 198 additions and 120 deletions
@@ -99,6 +99,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks }
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
override val cancelSendingIntent: Subject<Long> by lazy { messageAdapter.cancelSending }
override val sendNowIntent: Subject<Long> by lazy { messageAdapter.sendNow }
override val attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
override val textChangedIntent by lazy { message.textChanges() }
override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) }
@@ -48,6 +48,7 @@ interface ComposeView : QkView<ComposeState> {
val messagePartClickIntent: Subject<Long>
val messagesSelectedIntent: Observable<List<Long>>
val cancelSendingIntent: Subject<Long>
val sendNowIntent: Subject<Long>
val attachmentDeletedIntent: Subject<Attachment>
val textChangedIntent: Observable<CharSequence>
val attachIntent: Observable<Unit>
@@ -487,6 +487,26 @@ class ComposeViewModel @Inject constructor(
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
}
// send a delayed message now
view.sendNowIntent
.mapNotNull(messageRepo::getMessage)
.autoDisposable(view.scope())
.subscribe { message ->
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId))
val address = listOf(conversationRepo
.getConversation(threadId)?.recipients?.firstOrNull()?.address ?: message.address)
sendMessage.execute(
SendMessage.Params(
message.subId,
message.threadId,
address,
message.body,
listOf(), // sms with attachments (mms) can't be delayed so we can know attachments are empty for a 'send now' delayed sms
0
)
)
}
// Set the current conversation
Observables
.combineLatest(
@@ -32,6 +32,7 @@ import android.widget.ImageView
import android.widget.ProgressBar
import androidx.recyclerview.widget.RecyclerView
import com.jakewharton.rxbinding2.view.clicks
import com.jakewharton.rxbinding2.view.longClicks
import com.moez.QKSMS.common.QkMediaPlayer
import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
@@ -69,6 +70,7 @@ import kotlinx.android.synthetic.main.message_list_item_in.status
import kotlinx.android.synthetic.main.message_list_item_in.timestamp
import kotlinx.android.synthetic.main.message_list_item_in.view.*
import kotlinx.android.synthetic.main.message_list_item_out.*
import kotlinx.android.synthetic.main.message_list_item_out.view.cancel
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@@ -106,6 +108,7 @@ class MessagesAdapter @Inject constructor(
val clicks: Subject<Long> = PublishSubject.create()
val partClicks: Subject<Long> = PublishSubject.create()
val cancelSending: Subject<Long> = PublishSubject.create()
val sendNow: Subject<Long> = PublishSubject.create()
var data: Pair<Conversation, RealmResults<Message>>? = null
set(value) {
@@ -157,6 +160,7 @@ class MessagesAdapter @Inject constructor(
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
view.findViewById<ImageView>(R.id.sendNowIcon).setTint(theme.theme)
} else {
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
}
@@ -202,25 +206,37 @@ class MessagesAdapter @Inject constructor(
// Update the selected state
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
// Bind the cancel view
holder.cancel?.let { cancel ->
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
cancel.setVisible(isCancellable)
cancel.clicks().subscribe { cancelSending.onNext(message.id) }
cancel.progress = 2
// Bind the cancelFrame (cancel button) view
if (holder.cancelFrame != null) {
holder.cancelFrame.let { cancelFrame ->
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
cancelFrame.visibility = if (isCancellable) View.VISIBLE else View.GONE
cancelFrame.clicks().subscribe { cancelSending.onNext(message.id) }
cancelFrame.cancel.progress = 2
if (isCancellable) {
val delay = when (prefs.sendDelay.get()) {
Preferences.SEND_DELAY_SHORT -> 3000
Preferences.SEND_DELAY_MEDIUM -> 5000
Preferences.SEND_DELAY_LONG -> 10000
else -> 0
}
val progress = (1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
if (isCancellable) {
val delay = when (prefs.sendDelay.get()) {
Preferences.SEND_DELAY_SHORT -> 3000
Preferences.SEND_DELAY_MEDIUM -> 5000
Preferences.SEND_DELAY_LONG -> 10000
else -> 0
}
val progress =
(1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100
ObjectAnimator.ofInt(cancel, "progress", progress.toInt(), 100)
ObjectAnimator.ofInt(cancelFrame.cancel, "progress", progress.toInt(), 100)
.setDuration(message.date - System.currentTimeMillis())
.start()
}
}
}
// Bind the send now icon view
if (holder.sendNowIcon != null) {
holder.sendNowIcon.let { sendNowIcon ->
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
sendNowIcon.visibility = if (isCancellable) View.VISIBLE else View.GONE
sendNowIcon.longClicks().subscribe { sendNow.onNext(message.id) }
}
}