mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Save search query to savedinstancestate.
This commit is contained in:
committed by
Cody Henthorne
parent
46ca979e59
commit
524ffd9d79
@@ -126,6 +126,8 @@ class ContactSearchMediator(
|
||||
}
|
||||
}
|
||||
|
||||
fun getFilter(): String? = viewModel.getQuery()
|
||||
|
||||
fun onConversationFilterRequestChanged(conversationFilterRequest: ConversationFilterRequest) {
|
||||
viewModel.setConversationFilterRequest(conversationFilterRequest)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.thoughtcrime.securesms.contacts.paged
|
||||
|
||||
import androidx.lifecycle.AbstractSavedStateViewModelFactory
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.map
|
||||
import androidx.lifecycle.switchMap
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
@@ -26,6 +27,7 @@ import org.whispersystems.signalservice.api.util.Preconditions
|
||||
* Simple, reusable view model that manages a ContactSearchPagedDataSource as well as filter and expansion state.
|
||||
*/
|
||||
class ContactSearchViewModel(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
private val selectionLimits: SelectionLimits,
|
||||
private val contactSearchRepository: ContactSearchRepository,
|
||||
private val performSafetyNumberChecks: Boolean,
|
||||
@@ -34,6 +36,10 @@ class ContactSearchViewModel(
|
||||
private val contactSearchPagedDataSourceRepository: ContactSearchPagedDataSourceRepository
|
||||
) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private const val QUERY = "query"
|
||||
}
|
||||
|
||||
private val safetyNumberRepository: SafetyNumberRepository by lazy { SafetyNumberRepository() }
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
@@ -45,7 +51,7 @@ class ContactSearchViewModel(
|
||||
.build()
|
||||
|
||||
private val pagedData = MutableLiveData<LivePagedData<ContactSearchKey, ContactSearchData>>()
|
||||
private val configurationStore = Store(ContactSearchState())
|
||||
private val configurationStore = Store(ContactSearchState(query = savedStateHandle[QUERY]))
|
||||
private val selectionStore = Store<Set<ContactSearchKey>>(emptySet())
|
||||
private val errorEvents = PublishSubject.create<ContactSearchError>()
|
||||
|
||||
@@ -73,7 +79,10 @@ class ContactSearchViewModel(
|
||||
pagedData.value = PagedData.createForLiveData(pagedDataSource, pagingConfig)
|
||||
}
|
||||
|
||||
fun getQuery(): String? = savedStateHandle[QUERY]
|
||||
|
||||
fun setQuery(query: String?) {
|
||||
savedStateHandle[QUERY] = query
|
||||
configurationStore.update { it.copy(query = query) }
|
||||
}
|
||||
|
||||
@@ -169,10 +178,11 @@ class ContactSearchViewModel(
|
||||
private val arbitraryRepository: ArbitraryRepository?,
|
||||
private val searchRepository: SearchRepository,
|
||||
private val contactSearchPagedDataSourceRepository: ContactSearchPagedDataSourceRepository
|
||||
) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
) : AbstractSavedStateViewModelFactory() {
|
||||
override fun <T : ViewModel> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T {
|
||||
return modelClass.cast(
|
||||
ContactSearchViewModel(
|
||||
savedStateHandle = handle,
|
||||
selectionLimits = selectionLimits,
|
||||
contactSearchRepository = repository,
|
||||
performSafetyNumberChecks = performSafetyNumberChecks,
|
||||
|
||||
Reference in New Issue
Block a user