forked from upstream-mirrors/quik
@@ -27,7 +27,6 @@ import com.moez.QKSMS.feature.compose.editing.ComposeItem
|
||||
import com.moez.QKSMS.feature.compose.editing.PhoneNumberAction
|
||||
import com.moez.QKSMS.filter.ContactFilter
|
||||
import com.moez.QKSMS.filter.ContactGroupFilter
|
||||
import com.moez.QKSMS.interactor.SyncContacts
|
||||
import com.moez.QKSMS.interactor.SetDefaultPhoneNumber
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
@@ -50,7 +49,6 @@ import javax.inject.Inject
|
||||
class ContactsViewModel @Inject constructor(
|
||||
sharing: Boolean,
|
||||
serializedChips: HashMap<String, String?>,
|
||||
syncContacts: SyncContacts,
|
||||
private val contactFilter: ContactFilter,
|
||||
private val contactGroupFilter: ContactGroupFilter,
|
||||
private val contactsRepo: ContactRepository,
|
||||
@@ -76,10 +74,6 @@ class ContactsViewModel @Inject constructor(
|
||||
|
||||
private var shouldOpenKeyboard: Boolean = true
|
||||
|
||||
init {
|
||||
syncContacts.execute(Unit)
|
||||
}
|
||||
|
||||
override fun bindView(view: ContactsContract) {
|
||||
super.bindView(view)
|
||||
|
||||
|
||||
+3
-13
@@ -26,14 +26,12 @@ import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
@@ -44,7 +42,6 @@ import javax.inject.Named
|
||||
class ConversationInfoPresenter @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
messageRepo: MessageRepository,
|
||||
private val contactAddedListener: ContactAddedListener,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
@@ -105,16 +102,9 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
// Add or display the contact
|
||||
view.recipientClicks()
|
||||
.mapNotNull(conversationRepo::getRecipient)
|
||||
.flatMap { recipient ->
|
||||
val lookupKey = recipient.contact?.lookupKey
|
||||
if (lookupKey != null) {
|
||||
navigator.showContact(lookupKey)
|
||||
Observable.empty<Unit>()
|
||||
} else {
|
||||
// Allow the user to add the contact, then listen for changes
|
||||
navigator.addContact(recipient.address)
|
||||
contactAddedListener.listen(recipient.address)
|
||||
}
|
||||
.doOnNext { recipient ->
|
||||
recipient.contact?.lookupKey?.let(navigator::showContact)
|
||||
?: navigator.addContact(recipient.address)
|
||||
}
|
||||
.autoDisposable(view.scope(Lifecycle.Event.ON_DESTROY)) // ... this should be the default
|
||||
.subscribe()
|
||||
|
||||
@@ -29,7 +29,7 @@ data class MainState(
|
||||
val drawerOpen: Boolean = false,
|
||||
val upgraded: Boolean = true,
|
||||
val showRating: Boolean = false,
|
||||
val syncing: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle(),
|
||||
val syncing: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle,
|
||||
val defaultSms: Boolean = true,
|
||||
val smsPermission: Boolean = true,
|
||||
val contactPermission: Boolean = true
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
import com.moez.QKSMS.interactor.MarkUnpinned
|
||||
import com.moez.QKSMS.interactor.MarkUnread
|
||||
import com.moez.QKSMS.interactor.MigratePreferences
|
||||
import com.moez.QKSMS.interactor.SyncContacts
|
||||
import com.moez.QKSMS.interactor.SyncMessages
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
import com.moez.QKSMS.manager.ChangelogManager
|
||||
@@ -55,10 +56,10 @@ import javax.inject.Inject
|
||||
|
||||
class MainViewModel @Inject constructor(
|
||||
billingManager: BillingManager,
|
||||
contactAddedListener: ContactAddedListener,
|
||||
markAllSeen: MarkAllSeen,
|
||||
migratePreferences: MigratePreferences,
|
||||
syncRepository: SyncRepository,
|
||||
private val contactAddedListener: ContactAddedListener,
|
||||
private val changelogManager: ChangelogManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
@@ -72,6 +73,7 @@ class MainViewModel @Inject constructor(
|
||||
private val permissionManager: PermissionManager,
|
||||
private val prefs: Preferences,
|
||||
private val ratingManager: RatingManager,
|
||||
private val syncContacts: SyncContacts,
|
||||
private val syncMessages: SyncMessages
|
||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations()))) {
|
||||
|
||||
@@ -81,6 +83,7 @@ class MainViewModel @Inject constructor(
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
disposables += migratePreferences
|
||||
disposables += syncContacts
|
||||
disposables += syncMessages
|
||||
|
||||
// Show the syncing UI
|
||||
@@ -109,6 +112,12 @@ class MainViewModel @Inject constructor(
|
||||
syncMessages.execute(Unit)
|
||||
}
|
||||
|
||||
// Sync contacts when we detect a change
|
||||
disposables += contactAddedListener.listen()
|
||||
.debounce(1, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { syncContacts.execute(Unit) }
|
||||
|
||||
ratingManager.addSession()
|
||||
markAllSeen.execute(Unit)
|
||||
}
|
||||
@@ -287,7 +296,6 @@ class MainViewModel @Inject constructor(
|
||||
.map { conversation -> conversation.recipients }
|
||||
.mapNotNull { recipients -> recipients[0]?.address?.takeIf { recipients.size == 1 } }
|
||||
.doOnNext(navigator::addContact)
|
||||
.flatMap(contactAddedListener::listen)
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
|
||||
@@ -42,5 +42,5 @@ data class SettingsState(
|
||||
val mobileOnly: Boolean = false,
|
||||
val maxMmsSizeSummary: String = "100KB",
|
||||
val maxMmsSizeId: Int = 100,
|
||||
val syncProgress: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle()
|
||||
val syncProgress: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle
|
||||
)
|
||||
Reference in New Issue
Block a user