use RxAwareViewModel for more ViewModels (#1613)
* use RxAwareViewModel for more ViewModels * fix ReportViewModel
This commit is contained in:
parent
88d59da13c
commit
cdb9d87f41
6 changed files with 83 additions and 115 deletions
|
|
@ -4,15 +4,13 @@ import android.util.Log
|
|||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.paging.PagedList
|
||||
import com.keylesspalace.tusky.db.AccountManager
|
||||
import com.keylesspalace.tusky.db.AppDatabase
|
||||
import com.keylesspalace.tusky.network.TimelineCases
|
||||
import com.keylesspalace.tusky.util.Listing
|
||||
import com.keylesspalace.tusky.util.NetworkState
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.addTo
|
||||
import com.keylesspalace.tusky.util.RxAwareViewModel
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -21,7 +19,7 @@ class ConversationsViewModel @Inject constructor(
|
|||
private val timelineCases: TimelineCases,
|
||||
private val database: AppDatabase,
|
||||
private val accountManager: AccountManager
|
||||
) : ViewModel() {
|
||||
) : RxAwareViewModel() {
|
||||
|
||||
private val repoResult = MutableLiveData<Listing<ConversationEntity>>()
|
||||
|
||||
|
|
@ -29,8 +27,6 @@ class ConversationsViewModel @Inject constructor(
|
|||
val networkState: LiveData<NetworkState> = Transformations.switchMap(repoResult) { it.networkState }
|
||||
val refreshState: LiveData<NetworkState> = Transformations.switchMap(repoResult) { it.refreshState }
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
fun load() {
|
||||
val accountId = accountManager.activeAccount?.id ?: return
|
||||
if (repoResult.value == null) {
|
||||
|
|
@ -61,7 +57,7 @@ class ConversationsViewModel @Inject constructor(
|
|||
.doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) }
|
||||
.onErrorReturnItem(0)
|
||||
.subscribe()
|
||||
.addTo(disposables)
|
||||
.autoDispose()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -79,7 +75,7 @@ class ConversationsViewModel @Inject constructor(
|
|||
.subscribeOn(Schedulers.io())
|
||||
.doOnError { t -> Log.w("ConversationViewModel", "Failed to bookmark conversation", t) }
|
||||
.subscribe()
|
||||
.addTo(disposables)
|
||||
.autoDispose()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -98,7 +94,7 @@ class ConversationsViewModel @Inject constructor(
|
|||
.doOnError { t -> Log.w("ConversationViewModel", "Failed to favourite conversation", t) }
|
||||
.onErrorReturnItem(0)
|
||||
.subscribe()
|
||||
.addTo(disposables)
|
||||
.autoDispose()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -150,8 +146,4 @@ class ConversationsViewModel @Inject constructor(
|
|||
.subscribe()
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
disposables.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue