Merge pull request #249 from gavine99/scheduled-messages-click-doesnt-schedule-18

Scheduled messages click doesnt schedule 18
This commit is contained in:
octoshrimpy
2025-02-01 12:50:31 -07:00
committed by GitHub
7 changed files with 29 additions and 2 deletions
@@ -95,9 +95,10 @@ class Navigator @Inject constructor(
}
}
fun showCompose(body: String? = null, attachments: List<Uri>? = null) {
fun showCompose(body: String? = null, attachments: List<Uri>? = null, mode: String? = null) {
val intent = Intent(context, ComposeActivity::class.java)
intent.putExtra(Intent.EXTRA_TEXT, body)
intent.putExtra("mode", mode)
attachments?.takeIf { it.isNotEmpty() }?.let {
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(attachments))
@@ -71,10 +71,12 @@ import dev.octoshrimpy.quik.feature.contacts.ContactsActivity
import dev.octoshrimpy.quik.model.Attachment
import dev.octoshrimpy.quik.model.Recipient
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.compose_activity.*
import kotlinx.android.synthetic.main.main_activity.toolbar
import kotlinx.coroutines.reactive.publish
import java.text.SimpleDateFormat
import java.util.*
import javax.inject.Inject
@@ -94,6 +96,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val chipDeletedIntent: Subject<Recipient> by lazy { chipsAdapter.chipDeleted }
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
override val scheduleAction: Subject<Boolean> = PublishSubject.create()
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
override val messageClickIntent: Subject<Long> by lazy { messageAdapter.clicks }
override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks }
@@ -323,6 +326,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
)
constraintSet.applyTo(constraintLayout)
}
// if scheduling mode is set, show schedule dialog
if (state.scheduling)
scheduleAction.onNext(true)
}
override fun clearSelection() = messageAdapter.clearSelection()
@@ -82,6 +82,12 @@ class ComposeActivityModule {
return Attachments(uris.mapNotNull { Attachment(it) })
}
@Provides
@Named("mode")
fun provideSharedAction(activity: ComposeActivity): String {
return activity.intent.getStringExtra("mode") ?: "";
}
@Provides
@IntoMap
@ViewModelKey(ComposeViewModel::class)
@@ -42,6 +42,7 @@ data class ComposeState(
val scheduled: Long = 0,
val attachments: List<Attachment> = ArrayList(),
val attaching: Boolean = false,
val scheduling: Boolean = false,
val remaining: String = "",
val subscription: SubscriptionInfoCompat? = null,
val canSend: Boolean = false,
@@ -56,6 +56,7 @@ interface ComposeView : QkView<ComposeState> {
val attachAnyFileIntent: Observable<*>
val attachImageFileIntent: Observable<*>
val scheduleIntent: Observable<*>
val scheduleAction: Observable<*>
val attachContactIntent: Observable<*>
val attachAnyFileSelectedIntent: Observable<Uri>
val contactSelectedIntent: Observable<Uri>
@@ -80,6 +80,7 @@ class ComposeViewModel @Inject constructor(
@Named("addresses") private val addresses: List<String>,
@Named("text") private val sharedText: String,
@Named("attachments") private val sharedAttachments: Attachments,
@Named("mode") private val mode: String,
private val contactRepo: ContactRepository,
private val context: Context,
private val activeConversationManager: ActiveConversationManager,
@@ -243,6 +244,10 @@ class ComposeViewModel @Inject constructor(
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
newState { copy(subscription = sub) }
}.subscribe()
// actions
if (mode == "scheduling")
newState { copy(scheduling = true) }
}
override fun bindView(view: ComposeView) {
@@ -575,6 +580,12 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { view.requestDatePicker() }
view.scheduleAction
.take(1)
.doOnNext{ newState { copy(scheduling = false) } }
.autoDisposable(view.scope())
.subscribe { view.requestDatePicker() }
// a file, photo or otherwise, was picked by the user
Observable.merge(
view.attachAnyFileSelectedIntent.map { uri -> Attachment(uri) },
@@ -70,7 +70,7 @@ class ScheduledViewModel @Inject constructor(
view.composeIntent
.autoDisposable(view.scope())
.subscribe { navigator.showCompose() }
.subscribe { navigator.showCompose(mode = "scheduling") }
view.upgradeIntent
.autoDisposable(view.scope())