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 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()) }
@@ -39,6 +39,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>
@@ -471,6 +471,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(
@@ -33,6 +33,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 dev.octoshrimpy.quik.R
import dev.octoshrimpy.quik.common.base.QkRealmAdapter
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.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
@@ -98,6 +100,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) {
@@ -148,6 +151,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)
}
@@ -194,25 +198,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) }
}
}
@@ -17,133 +17,167 @@
~ You should have received a copy of the GNU General Public License
~ 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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground">
android:orientation="vertical">
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/timestamp"
style="@style/TextSecondary"
android:layout_width="wrap_content"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
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" />
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/compose_message_item">
<ImageView
android:id="@+id/sim"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginEnd="2dp"
android:src="@drawable/ic_sim_card_black_24dp"
android:tint="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="@id/timestamp"
app:layout_constraintEnd_toStartOf="@id/simIndex"
app:layout_constraintStart_toEndOf="@id/timestamp"
app:layout_constraintTop_toTopOf="@id/timestamp" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/timestamp"
style="@style/TextSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
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" />
<dev.octoshrimpy.quik.common.widget.QkTextView
android:id="@+id/simIndex"
android:layout_width="wrap_content"
<ImageView
android:id="@+id/sim"
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: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" />
android:clipToPadding="false"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<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" />
<FrameLayout
android:id="@+id/cancelFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:clipToPadding="false"
android:paddingBottom="6dp">
<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="60dp"
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"
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
android:id="@+id/cancel"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="@drawable/circle"
android:backgroundTint="?attr/bubbleColor"
android:clickable="false"
android:elevation="4dp"
android:foreground="?attr/selectableItemBackground"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
tools:progress="45"
tools:progressTint="@color/tools_theme" />
<ProgressBar
android:id="@+id/cancel"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="8dp"
android:background="@drawable/circle"
android:backgroundTint="?attr/bubbleColor"
android:elevation="4dp"
android:foreground="?attr/selectableItemBackground"
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
android:id="@+id/cancelIcon"
android:layout_width="36dp"
android:layout_height="36dp"
android:clickable="false"
android:contentDescription="@string/compose_message_cancel"
android:elevation="4dp"
android:padding="6dp"
android:src="@drawable/ic_stop_black_24dp"
tools:tint="@color/tools_theme" />
<ImageView
android:id="@+id/cancelIcon"
android:layout_width="0dp"
android:layout_height="0dp"
android:elevation="4dp"
android:padding="6dp"
android:src="@drawable/ic_stop_black_24dp"
app:layout_constraintBottom_toBottomOf="@id/cancel"
app:layout_constraintEnd_toEndOf="@id/cancel"
app:layout_constraintStart_toStartOf="@id/cancel"
app:layout_constraintTop_toTopOf="@id/cancel"
tools:tint="@color/tools_theme" />
</FrameLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/sendNowIcon"
android:layout_width="36dp"
android:layout_height="36dp"
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
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="4dp"
android:contentDescription="@string/compose_message_attachment"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/body"
app:textSize="tertiary"
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_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_delivered">Delivered %s</string>
<string name="message_status_failed">Failed to send. Tap to try again</string>