Commit ba785ec8 authored by mohit.mali@ftechiz.com's avatar mohit.mali@ftechiz.com Committed by Romain Hunault

Issue 26 Fixed

parent 0a3a5803
Pipeline #38446 failed with stage
in 3 minutes and 53 seconds
......@@ -25,6 +25,7 @@ import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Named
@Module
class MainActivityModule {
......@@ -33,6 +34,11 @@ class MainActivityModule {
@ActivityScope
fun provideCompositeDiposableLifecycle(): CompositeDisposable = CompositeDisposable()
@Provides
@Named("threadId")
fun provideThreadId(activity: MainActivity): Long = activity.intent.extras?.getLong("threadId")
?: 0L
@Provides
@IntoMap
@ViewModelKey(MainViewModel::class)
......
......@@ -51,25 +51,27 @@ import io.realm.Realm
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Named
class MainViewModel @Inject constructor(
markAllSeen: MarkAllSeen,
migratePreferences: MigratePreferences,
syncRepository: SyncRepository,
private val contactAddedListener: ContactAddedListener,
private val changelogManager: ChangelogManager,
private val conversationRepo: ConversationRepository,
private val deleteConversations: DeleteConversations,
private val markArchived: MarkArchived,
private val markPinned: MarkPinned,
private val markRead: MarkRead,
private val markUnarchived: MarkUnarchived,
private val markUnpinned: MarkUnpinned,
private val markUnread: MarkUnread,
private val navigator: Navigator,
private val permissionManager: PermissionManager,
private val prefs: Preferences,
private val syncMessages: SyncMessages
@Named("threadId") private val threadId: Long,
markAllSeen: MarkAllSeen,
migratePreferences: MigratePreferences,
syncRepository: SyncRepository,
private val conversationRepo: ConversationRepository,
private val deleteConversations: DeleteConversations,
private val markArchived: MarkArchived,
private val markBlocked: MarkBlocked,
private val markPinned: MarkPinned,
private val markRead: MarkRead,
private val markUnarchived: MarkUnarchived,
private val markUnpinned: MarkUnpinned,
private val markUnread: MarkUnread,
private val navigator: Navigator,
private val permissionManager: PermissionManager,
private val prefs: Preferences,
private val syncMessages: SyncMessages,
private val syncContacts: ContactSync
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations()))) {
init {
......@@ -388,6 +390,30 @@ class MainViewModel @Inject constructor(
}
.autoDisposable(view.scope())
.subscribe()
view.backPressedIntent
.withLatestFrom(state) { _, state ->
when {
state.drawerOpen -> newState { copy(drawerOpen = false) }
state.page is Searching -> view.clearSearch()
state.page is Inbox && state.page.selected > 0 -> view.clearSelection()
state.page is Archived && state.page.selected > 0 -> view.clearSelection()
state.page !is Inbox -> newState { copy(page = Inbox(data = conversationRepo.getConversations())) }
else -> newState { copy(hasError = true) }
}
}
.autoDisposable(view.scope())
.subscribe()
if (threadId == 0L) {
syncContacts.execute(Unit)
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment