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 75c5b1acb6
commit ade92ac03a
6 changed files with 198 additions and 120 deletions
@@ -106,6 +106,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks } override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks }
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges } override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
override val cancelSendingIntent: Subject<Long> by lazy { messageAdapter.cancelSending } 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 attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
override val textChangedIntent by lazy { message.textChanges() } override val textChangedIntent by lazy { message.textChanges() }
override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) } override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) }
@@ -39,6 +39,7 @@ interface ComposeView : QkView<ComposeState> {
val messagePartClickIntent: Subject<Long> val messagePartClickIntent: Subject<Long>
val messagesSelectedIntent: Observable<List<Long>> val messagesSelectedIntent: Observable<List<Long>>
val cancelSendingIntent: Subject<Long> val cancelSendingIntent: Subject<Long>
val sendNowIntent: Subject<Long>
val attachmentDeletedIntent: Subject<Attachment> val attachmentDeletedIntent: Subject<Attachment>
val textChangedIntent: Observable<CharSequence> val textChangedIntent: Observable<CharSequence>
val attachIntent: Observable<Unit> val attachIntent: Observable<Unit>
@@ -471,6 +471,26 @@ class ComposeViewModel @Inject constructor(
cancelMessage.execute(CancelDelayedMessage.Params(message.id, message.threadId)) 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 // Set the current conversation
Observables Observables
.combineLatest( .combineLatest(
@@ -33,6 +33,7 @@ import android.widget.ImageView
import android.widget.ProgressBar import android.widget.ProgressBar
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.jakewharton.rxbinding2.view.clicks import com.jakewharton.rxbinding2.view.clicks
import com.jakewharton.rxbinding2.view.longClicks
import dev.octoshrimpy.quik.R import dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkRealmAdapter import dev.octoshrimpy.quik.common.base.QkRealmAdapter
import dev.octoshrimpy.quik.common.base.QkViewHolder import dev.octoshrimpy.quik.common.base.QkViewHolder
@@ -68,6 +69,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.timestamp
import kotlinx.android.synthetic.main.message_list_item_in.view.* 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.*
import kotlinx.android.synthetic.main.message_list_item_out.view.cancel
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@@ -98,6 +100,7 @@ class MessagesAdapter @Inject constructor(
val clicks: Subject<Long> = PublishSubject.create() val clicks: Subject<Long> = PublishSubject.create()
val partClicks: Subject<Long> = PublishSubject.create() val partClicks: Subject<Long> = PublishSubject.create()
val cancelSending: Subject<Long> = PublishSubject.create() val cancelSending: Subject<Long> = PublishSubject.create()
val sendNow: Subject<Long> = PublishSubject.create()
var data: Pair<Conversation, RealmResults<Message>>? = null var data: Pair<Conversation, RealmResults<Message>>? = null
set(value) { set(value) {
@@ -148,6 +151,7 @@ class MessagesAdapter @Inject constructor(
view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false) view = layoutInflater.inflate(R.layout.message_list_item_out, parent, false)
view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme) view.findViewById<ImageView>(R.id.cancelIcon).setTint(theme.theme)
view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme) view.findViewById<ProgressBar>(R.id.cancel).setTint(theme.theme)
view.findViewById<ImageView>(R.id.sendNowIcon).setTint(theme.theme)
} else { } else {
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false) view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
} }
@@ -194,25 +198,37 @@ class MessagesAdapter @Inject constructor(
// Update the selected state // Update the selected state
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
// Bind the cancel view // Bind the cancelFrame (cancel button) view
holder.cancel?.let { cancel -> if (holder.cancelFrame != null) {
val isCancellable = message.isSending() && message.date > System.currentTimeMillis() holder.cancelFrame.let { cancelFrame ->
cancel.setVisible(isCancellable) val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
cancel.clicks().subscribe { cancelSending.onNext(message.id) } cancelFrame.visibility = if (isCancellable) View.VISIBLE else View.GONE
cancel.progress = 2 cancelFrame.clicks().subscribe { cancelSending.onNext(message.id) }
cancelFrame.cancel.progress = 2
if (isCancellable) { if (isCancellable) {
val delay = when (prefs.sendDelay.get()) { val delay = when (prefs.sendDelay.get()) {
Preferences.SEND_DELAY_SHORT -> 3000 Preferences.SEND_DELAY_SHORT -> 3000
Preferences.SEND_DELAY_MEDIUM -> 5000 Preferences.SEND_DELAY_MEDIUM -> 5000
Preferences.SEND_DELAY_LONG -> 10000 Preferences.SEND_DELAY_LONG -> 10000
else -> 0 else -> 0
} }
val progress = (1 - (message.date - System.currentTimeMillis()) / delay.toFloat()) * 100 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()) .setDuration(message.date - System.currentTimeMillis())
.start() .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) }
} }
} }
@@ -17,133 +17,167 @@
~ You should have received a copy of the GNU General Public License ~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>. ~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
--> -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"> android:orientation="vertical">
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/timestamp" <androidx.constraintlayout.widget.ConstraintLayout
style="@style/TextSecondary" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:background="?attr/selectableItemBackground"
android:padding="8dp" android:contentDescription="@string/compose_message_item">
app:layout_constraintEnd_toStartOf="@id/sim"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Tue at 11:39pm" />
<ImageView <dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/sim" android:id="@+id/timestamp"
android:layout_width="16dp" style="@style/TextSecondary"
android:layout_height="16dp" android:layout_width="wrap_content"
android:layout_marginEnd="2dp" android:layout_height="wrap_content"
android:src="@drawable/ic_sim_card_black_24dp" android:gravity="center"
android:tint="?android:attr/textColorSecondary" android:padding="8dp"
app:layout_constraintBottom_toBottomOf="@id/timestamp" app:layout_constraintEnd_toStartOf="@id/sim"
app:layout_constraintEnd_toStartOf="@id/simIndex" app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toEndOf="@id/timestamp" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/timestamp" /> app:layout_constraintTop_toTopOf="parent"
tools:text="Tue at 11:39pm" />
<dev.octoshrimpy.quik.common.widget.QkTextView <ImageView
android:id="@+id/simIndex" android:id="@+id/sim"
android:layout_width="wrap_content" android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="2dp"
android:contentDescription="@string/compose_message_sim"
android:src="@drawable/ic_sim_card_black_24dp"
app:layout_constraintBottom_toBottomOf="@id/timestamp"
app:layout_constraintEnd_toStartOf="@id/simIndex"
app:layout_constraintStart_toEndOf="@id/timestamp"
app:layout_constraintTop_toTopOf="@id/timestamp"
app:tint="?android:attr/textColorSecondary" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/simIndex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="@id/timestamp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/sim"
app:layout_constraintTop_toTopOf="@id/timestamp"
app:textSize="tertiary"
tools:text="1" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/attachments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginStart="60dp"
android:layout_marginEnd="12dp"
android:gravity="end"
android:nestedScrollingEnabled="false"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintTop_toBottomOf="@id/timestamp"
tools:itemCount="1"
tools:listitem="@layout/mms_preview_list_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary" android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="@id/timestamp" android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintStart_toEndOf="@id/sim"
app:layout_constraintTop_toTopOf="@id/timestamp"
app:textSize="tertiary"
tools:text="1" />
<androidx.recyclerview.widget.RecyclerView <FrameLayout
android:id="@+id/attachments" android:id="@+id/cancelFrame"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_marginStart="12dp"
android:layout_marginStart="60dp" android:layout_marginEnd="12dp"
android:layout_marginEnd="12dp" android:clipToPadding="false"
android:gravity="end" android:paddingBottom="6dp">
android:nestedScrollingEnabled="false"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintTop_toBottomOf="@id/timestamp"
tools:itemCount="1"
tools:listitem="@layout/mms_preview_list_item" />
<dev.octoshrimpy.quik.common.widget.TightTextView <ProgressBar
android:id="@+id/body" android:id="@+id/cancel"
style="@style/TextPrimary" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content" android:layout_width="36dp"
android:layout_height="wrap_content" android:layout_height="36dp"
android:layout_marginStart="60dp" android:background="@drawable/circle"
android:layout_marginTop="2dp" android:backgroundTint="?attr/bubbleColor"
android:layout_marginEnd="12dp" android:clickable="false"
android:autoLink="email|phone|web" android:elevation="4dp"
android:background="@drawable/message_only" android:foreground="?attr/selectableItemBackground"
android:backgroundTint="?attr/bubbleColor" android:indeterminate="false"
android:gravity="start|center_vertical" android:progressDrawable="@drawable/circular_progress_bar"
android:minHeight="36dp" tools:progress="45"
android:textIsSelectable="true" tools:progressTint="@color/tools_theme" />
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/attachments"
app:layout_constraintWidth_max="384dp"
tools:text="Hey! How's it going?" />
<ProgressBar <ImageView
android:id="@+id/cancel" android:id="@+id/cancelIcon"
style="?android:attr/progressBarStyleHorizontal" android:layout_width="36dp"
android:layout_width="36dp" android:layout_height="36dp"
android:layout_height="36dp" android:clickable="false"
android:layout_marginEnd="8dp" android:contentDescription="@string/compose_message_cancel"
android:background="@drawable/circle" android:elevation="4dp"
android:backgroundTint="?attr/bubbleColor" android:padding="6dp"
android:elevation="4dp" android:src="@drawable/ic_stop_black_24dp"
android:foreground="?attr/selectableItemBackground" tools:tint="@color/tools_theme" />
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
app:layout_constraintBottom_toBottomOf="@id/body"
app:layout_constraintEnd_toStartOf="@id/body"
tools:progress="45"
tools:progressTint="@color/tools_theme" />
<ImageView </FrameLayout>
android:id="@+id/cancelIcon"
android:layout_width="0dp" <View
android:layout_height="0dp" android:layout_width="0dp"
android:elevation="4dp" android:layout_height="match_parent"
android:padding="6dp" android:layout_weight="1" />
android:src="@drawable/ic_stop_black_24dp"
app:layout_constraintBottom_toBottomOf="@id/cancel" <ImageView
app:layout_constraintEnd_toEndOf="@id/cancel" android:id="@+id/sendNowIcon"
app:layout_constraintStart_toStartOf="@id/cancel" android:layout_width="36dp"
app:layout_constraintTop_toTopOf="@id/cancel" android:layout_height="36dp"
tools:tint="@color/tools_theme" /> android:background="@drawable/circle"
android:contentDescription="@string/compose_message_send_now"
android:elevation="4dp"
android:padding="6dp"
android:src="@drawable/ic_send_black_24dp"
tools:tint="@color/tools_theme" />
<dev.octoshrimpy.quik.common.widget.TightTextView
android:id="@+id/body"
style="@style/TextPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="12dp"
android:autoLink="email|phone|web"
android:background="@drawable/message_only"
android:backgroundTint="?attr/bubbleColor"
android:gravity="start|center_vertical"
android:minHeight="36dp"
android:textIsSelectable="true"
app:layout_constrainedWidth="true"
tools:text="Hey! How's it going?" />
</LinearLayout>
<dev.octoshrimpy.quik.common.widget.QkTextView <dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/status" android:id="@+id/status"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:contentDescription="@string/compose_message_attachment"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/body"
app:textSize="tertiary" app:textSize="tertiary"
tools:text="Sending..." /> tools:text="Sending..." />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
@@ -148,6 +148,12 @@
<string name="compose_sim_cd">%s selected, change SIM card</string> <string name="compose_sim_cd">%s selected, change SIM card</string>
<string name="compose_send_cd">Send message</string> <string name="compose_send_cd">Send message</string>
<string name="compose_message_cancel">Cancel</string>
<string name="compose_message_send_now">Send now</string>
<string name="compose_message_sim">SIM number</string>
<string name="compose_message_item">Message item</string>
<string name="compose_message_attachment">Attachment</string>
<string name="message_status_sending">Sending…</string> <string name="message_status_sending">Sending…</string>
<string name="message_status_delivered">Delivered %s</string> <string name="message_status_delivered">Delivered %s</string>
<string name="message_status_failed">Failed to send. Tap to try again</string> <string name="message_status_failed">Failed to send. Tap to try again</string>