forked from upstream-mirrors/quik
#207 - Dual SIM support
commit c3dc3ada558c466be5115cd7ddbf9651a229c217 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sat Jun 2 02:54:06 2018 -0400 Dual SIM support for QK Reply commit 48688dd4720bd1b3abc049d365e208e1dfe5ccb8 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Sat Jun 2 00:37:08 2018 -0400 #1172 - Load all recipients and subId from threadId when sending message from notification reply bar commit 0b7195fb134c0a9f2a6b551176c6c25a26bf5838 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:43:30 2018 -0400 Fix missing subId for RetrySending params commit 0d3ec43c0e60bab4acc293947ea9f6d2228c1b19 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:27:56 2018 -0400 Switch to appropriate SIM when new message is received commit 1ae883af890104cf1da9e970571371c95666db66 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 23:07:16 2018 -0400 Fix message grouping for incoming messages commit 2bf7b2d99ddbfdcafff873f305180d6d38c37d65 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 22:56:31 2018 -0400 Correctly assign subId for incoming SMS commit 1f6028f8921320358a3053a2dbc2c6e05410964b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 20:52:01 2018 -0400 Abstract SubscriptionManager usage behind SubscriptionUtils commit 8b18f16271f19a42800c737cfbd867365c4aa781 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 20:05:52 2018 -0400 Store subId when receiving SMS commit f0e4ffdf15eb54d8ef78adfe244943ef4cb95d4e Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Fri Jun 1 19:52:40 2018 -0400 Use appropriate SIM card based on last message commit b7893d69891e4fb61755b0733a5fab561e86bbf3 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Thu May 31 00:20:42 2018 -0400 Fix crash when device doesn't support multi-sim commit bb038068129227e931167976628e1a535efb09a0 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 23:54:14 2018 -0400 Show sim indicator when subId changes in conversation commit 952f15f7ebfb85a03feef51373ef30568b76d5eb Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 22:13:57 2018 -0400 Send message from selected SIM commit 4cfab7ca9ec9bd9c7ce82b3eb5f228cf511a7c7b Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 21:46:01 2018 -0400 Fix filename for ActiveSubscriptionObservable commit 720cb79cb4fbfb98b10e169f2fea84be02fd2f91 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 20:35:30 2018 -0400 Allow cycling through inserted sims commit fa95980e9bc8e8c01dab7b4b8e4ed3a1c9a0f0b0 Author: Moez Bhatti <moez.bhatti@gmail.com> Date: Wed May 30 18:26:44 2018 -0400 Show sim card slot in compose bar
This commit is contained in:
@@ -172,7 +172,7 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.forEach { uri -> notification.addPerson(uri) }
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
notification.addAction(getReplyAction(conversation.recipients[0]?.address.orEmpty(), threadId))
|
||||
notification.addAction(getReplyAction(threadId))
|
||||
} else {
|
||||
val replyIntent = Intent(context, QkReplyActivity::class.java).putExtra("threadId", threadId)
|
||||
val replyPI = PendingIntent.getActivity(context, threadId.toInt() + 40000, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
@@ -224,10 +224,8 @@ class NotificationManagerImpl @Inject constructor(
|
||||
notificationManager.notify(threadId.toInt() + 50000, notification.build())
|
||||
}
|
||||
|
||||
private fun getReplyAction(address: String, threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java)
|
||||
.putExtra("address", address)
|
||||
.putExtra("threadId", threadId)
|
||||
private fun getReplyAction(threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java).putExtra("threadId", threadId)
|
||||
val replyPI = PendingIntent.getBroadcast(context, threadId.toInt() + 40000, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val responseSet = context.resources.getStringArray(R.array.qk_responses)
|
||||
|
||||
@@ -89,12 +89,13 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val galleryIntent by lazy { gallery.clicks() }
|
||||
override val attachmentSelectedIntent: Subject<Uri> = PublishSubject.create()
|
||||
override val inputContentIntent by lazy { message.inputContentSelected }
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
|
||||
|
||||
var cameraDestination: Uri? = null
|
||||
private var cameraDestination: Uri? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
@@ -197,6 +198,9 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
sim.setVisible(state.subscription != null)
|
||||
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package feature.compose
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import io.realm.RealmResults
|
||||
import model.Attachment
|
||||
import model.Contact
|
||||
@@ -41,5 +42,6 @@ data class ComposeState(
|
||||
val attachments: List<Attachment> = ArrayList(),
|
||||
val attaching: Boolean = false,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfo? = null,
|
||||
val canSend: Boolean = false
|
||||
)
|
||||
@@ -47,6 +47,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val galleryIntent: Observable<*>
|
||||
val attachmentSelectedIntent: Observable<Uri>
|
||||
val inputContentIntent: Observable<InputContentInfoCompat>
|
||||
val changeSimIntent: Observable<*>
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
fun clearSelection()
|
||||
|
||||
@@ -56,6 +56,7 @@ import model.Message
|
||||
import model.PhoneNumber
|
||||
import repository.ContactRepository
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.asObservable
|
||||
import util.extensions.isImage
|
||||
import util.extensions.mapNotNull
|
||||
@@ -79,6 +80,7 @@ class ComposeViewModel @Inject constructor(
|
||||
private val permissionManager: PermissionManager,
|
||||
private val retrySending: RetrySending,
|
||||
private val sendMessage: SendMessage,
|
||||
private val subUtils: SubscriptionUtils,
|
||||
private val syncContacts: ContactSync
|
||||
) : QkViewModel<ComposeView, ComposeState>(ComposeState(query = intent.extras?.getString("query") ?: "")) {
|
||||
|
||||
@@ -196,6 +198,15 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
}.subscribe()
|
||||
|
||||
val latestSubId = messages
|
||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||
.distinctUntilChanged()
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { it.copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
|
||||
if (threadId == 0L) {
|
||||
syncContacts.execute(Unit)
|
||||
}
|
||||
@@ -494,14 +505,30 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
.withLatestFrom(state) { _, state ->
|
||||
val subs = subUtils.subscriptions
|
||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||
val subscription = when {
|
||||
subIndex == -1 -> null
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { it.copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(attachments, conversation, { body, attachments, conversation ->
|
||||
.withLatestFrom(state, attachments, conversation, { body, state, attachments, conversation ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
sendMessage.execute(SendMessage.Params(threadId, addresses, body, attachments))
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body, attachments))
|
||||
view.setDraft("")
|
||||
this.attachments.onNext(ArrayList())
|
||||
})
|
||||
|
||||
@@ -21,7 +21,6 @@ package feature.compose
|
||||
import android.animation.ObjectAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.text.Spannable
|
||||
@@ -43,7 +42,6 @@ import common.util.DateFormatter
|
||||
import common.util.GlideApp
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.forwardTouches
|
||||
import common.util.extensions.resolveThemeColor
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.setPadding
|
||||
import common.util.extensions.setTint
|
||||
@@ -59,6 +57,7 @@ import model.Conversation
|
||||
import model.Message
|
||||
import model.Recipient
|
||||
import util.Preferences
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.hasThumbnails
|
||||
import util.extensions.isImage
|
||||
import util.extensions.isVideo
|
||||
@@ -70,7 +69,8 @@ class MessagesAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
private val prefs: Preferences,
|
||||
private val subUtils: SubscriptionUtils
|
||||
) : QkRealmAdapter<Message>() {
|
||||
|
||||
companion object {
|
||||
@@ -116,6 +116,7 @@ class MessagesAdapter @Inject constructor(
|
||||
private val contactCache = ContactCache()
|
||||
private val expanded = HashMap<Long, Boolean>()
|
||||
private val disposables = CompositeDisposable()
|
||||
private val subs = subUtils.subscriptions
|
||||
|
||||
var theme: Colors.Theme = colors.theme()
|
||||
|
||||
@@ -206,8 +207,14 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
// Bind the timestamp
|
||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
||||
val simIndex = subs.takeIf { it.size > 1 }?.indexOfFirst { it.subscriptionId == message.subId } ?: -1
|
||||
|
||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
view.timestamp.visibility = if (timeSincePrevious < TIMESTAMP_THRESHOLD) View.GONE else View.VISIBLE
|
||||
view.simIndex.text = "${simIndex + 1}"
|
||||
|
||||
view.timestamp.setVisible(timeSincePrevious >= TIMESTAMP_THRESHOLD || message.subId != previous?.subId && simIndex != -1)
|
||||
view.sim.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
view.simIndex.setVisible(message.subId != previous?.subId && simIndex != -1)
|
||||
|
||||
|
||||
// Bind the grouping
|
||||
@@ -283,15 +290,6 @@ class MessagesAdapter @Inject constructor(
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(mediaView.thumbnail)
|
||||
view.attachments.addView(mediaView)
|
||||
}
|
||||
|
||||
|
||||
// If we're on API 21, we need to re-tint the background
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
view.body.setBackgroundTint(when (message.isMe()) {
|
||||
true -> context.resolveThemeColor(R.attr.bubbleColor)
|
||||
false -> theme.theme
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindStatus(viewHolder: QkViewHolder, message: Message, next: Message?) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import android.view.WindowManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.jakewharton.rxbinding2.widget.textChanges
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.R.id.*
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.base.QkThemedActivity
|
||||
@@ -52,6 +51,7 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
||||
|
||||
override val menuItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[QkReplyViewModel::class.java] }
|
||||
@@ -99,6 +99,9 @@ class QkReplyActivity : QkThemedActivity(), QkReplyView {
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
sim.setVisible(state.subscription != null)
|
||||
simIndex.text = "${state.subscription?.simSlotIndex?.plus(1)}"
|
||||
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package feature.qkreply
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.content.Intent
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import injection.ViewModelKey
|
||||
import javax.inject.Named
|
||||
|
||||
@Module
|
||||
class QkReplyActivityModule {
|
||||
|
||||
@Provides
|
||||
fun provideIntent(activity: QkReplyActivity): Intent = activity.intent
|
||||
@Named("threadId")
|
||||
fun provideThreadId(activity: QkReplyActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L
|
||||
|
||||
@Provides
|
||||
@IntoMap
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package feature.qkreply
|
||||
|
||||
import android.telephony.SubscriptionInfo
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
@@ -28,5 +29,6 @@ data class QkReplyState(
|
||||
val expanded: Boolean = false,
|
||||
val data: Pair<Conversation, RealmResults<Message>>? = null,
|
||||
val remaining: String = "",
|
||||
val subscription: SubscriptionInfo? = null,
|
||||
val canSend: Boolean = false
|
||||
)
|
||||
@@ -25,6 +25,7 @@ interface QkReplyView : QkView<QkReplyState> {
|
||||
|
||||
val menuItemIntent: Observable<Int>
|
||||
val textChangedIntent: Observable<CharSequence>
|
||||
val changeSimIntent: Observable<*>
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
fun setDraft(draft: String)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package feature.qkreply
|
||||
|
||||
import android.content.Intent
|
||||
import android.telephony.SmsMessage
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -27,37 +26,42 @@ import common.Navigator
|
||||
import common.base.QkViewModel
|
||||
import interactor.MarkRead
|
||||
import interactor.SendMessage
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import repository.MessageRepository
|
||||
import util.SubscriptionUtils
|
||||
import util.extensions.asObservable
|
||||
import util.extensions.mapNotNull
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class QkReplyViewModel @Inject constructor(
|
||||
private val intent: Intent,
|
||||
@Named("threadId") threadId: Long,
|
||||
private val markRead: MarkRead,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val navigator: Navigator,
|
||||
private val sendMessage: SendMessage
|
||||
private val sendMessage: SendMessage,
|
||||
private val subUtils: SubscriptionUtils
|
||||
) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
|
||||
|
||||
private val conversation by lazy {
|
||||
messageRepo.getConversationAsync(intent.getLongExtra("threadId", -1))
|
||||
messageRepo.getConversationAsync(threadId)
|
||||
.asObservable<Conversation>()
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
|
||||
private val messages: Subject<RealmResults<Message>> = PublishSubject.create()
|
||||
private val messages: Subject<RealmResults<Message>> =
|
||||
BehaviorSubject.createDefault(messageRepo.getUnreadMessages(threadId))
|
||||
|
||||
init {
|
||||
disposables += markRead
|
||||
@@ -65,10 +69,11 @@ class QkReplyViewModel @Inject constructor(
|
||||
|
||||
// When the set of messages changes, update the state
|
||||
// If we're ever showing an empty set of messages, then it's time to shut down to activity
|
||||
disposables += messages
|
||||
.withLatestFrom(conversation, { messages, conversation -> Pair(conversation, messages) })
|
||||
.doOnNext { data -> newState { it.copy(data = data) } }
|
||||
.map { data -> data.second }
|
||||
disposables += Observables
|
||||
.combineLatest(messages, conversation) { messages, conversation ->
|
||||
newState { it.copy(data = Pair(conversation, messages)) }
|
||||
messages
|
||||
}
|
||||
.switchMap { messages -> messages.asObservable() }
|
||||
.filter { it.isLoaded }
|
||||
.filter { it.isValid }
|
||||
@@ -76,10 +81,18 @@ class QkReplyViewModel @Inject constructor(
|
||||
.subscribe { newState { it.copy(hasError = true) } }
|
||||
|
||||
disposables += conversation
|
||||
.doOnNext { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||
.distinctUntilChanged { conversation -> conversation.id } // We only need to set the messages once
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.subscribe { messages.onNext(it) }
|
||||
.map { conversation -> conversation.getTitle() }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { title -> newState { it.copy(title = title) } }
|
||||
|
||||
val latestSubId = messages
|
||||
.map { messages -> messages.lastOrNull()?.subId ?: -1 }
|
||||
.distinctUntilChanged()
|
||||
|
||||
disposables += Observables.combineLatest(latestSubId, subUtils.subscriptionsObservable) { subId, subs ->
|
||||
val sub = if (subs.size > 1) subs.firstOrNull { it.subscriptionId == subId } ?: subs[0] else null
|
||||
newState { it.copy(subscription = sub) }
|
||||
}.subscribe()
|
||||
}
|
||||
|
||||
override fun bindView(view: QkReplyView) {
|
||||
@@ -115,7 +128,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.filter { id -> id == R.id.expand }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.map { conversation -> messageRepo.getMessages(conversation.id) }
|
||||
.doOnNext { messages.onNext(it) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = true) } }
|
||||
|
||||
@@ -124,7 +137,7 @@ class QkReplyViewModel @Inject constructor(
|
||||
.filter { id -> id == R.id.collapse }
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.map { conversation -> messageRepo.getUnreadMessages(conversation.id) }
|
||||
.doOnNext { messages.onNext(it) }
|
||||
.doOnNext(messages::onNext)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { newState { it.copy(expanded = false) } }
|
||||
|
||||
@@ -173,18 +186,31 @@ class QkReplyViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Toggle to the next sim slot
|
||||
view.changeSimIntent
|
||||
.withLatestFrom(state) { _, state ->
|
||||
val subs = subUtils.subscriptions
|
||||
val subIndex = subs.indexOfFirst { it.subscriptionId == state.subscription?.subscriptionId }
|
||||
val subscription = when {
|
||||
subIndex == -1 -> null
|
||||
subIndex < subs.size - 1 -> subs[subIndex + 1]
|
||||
else -> subs[0]
|
||||
}
|
||||
newState { it.copy(subscription = subscription) }
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||
view.sendIntent
|
||||
.withLatestFrom(view.textChangedIntent, { _, body -> body })
|
||||
.map { body -> body.toString() }
|
||||
.withLatestFrom(conversation, { body, conversation ->
|
||||
.withLatestFrom(state, conversation, { body, state, conversation ->
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val threadId = conversation.id
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
|
||||
sendMessage.execute(SendMessage.Params(subId, threadId, addresses, body))
|
||||
view.setDraft("")
|
||||
sendMessage.execute(SendMessage.Params(threadId, addresses, body, listOf())) {
|
||||
}
|
||||
|
||||
threadId
|
||||
})
|
||||
.doOnNext { threadId ->
|
||||
|
||||
@@ -59,6 +59,8 @@ import repository.MessageRepository
|
||||
import repository.MessageRepositoryImpl
|
||||
import repository.SyncRepository
|
||||
import repository.SyncRepositoryImpl
|
||||
import util.SubscriptionUtils
|
||||
import util.SubscriptionUtilsImpl
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@@ -137,4 +139,10 @@ class AppModule(private var application: Application) {
|
||||
@Provides
|
||||
fun provideSyncRepository(repository: SyncRepositoryImpl): SyncRepository = repository
|
||||
|
||||
|
||||
// Utils
|
||||
|
||||
@Provides
|
||||
fun provideSubscriptionUtils(utils: SubscriptionUtilsImpl): SubscriptionUtils = utils
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user