Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change all exposed MutableLiveData to LiveData #794

Merged
merged 5 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.fossasia.openevent.general.about

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -12,28 +13,33 @@ import timber.log.Timber
class AboutEventViewModel(private val eventService: EventService) : ViewModel() {

private val compositeDisposable = CompositeDisposable()
val progressAboutEvent = MutableLiveData<Boolean>()
val event = MutableLiveData<Event>()
val error = MutableLiveData<String>()

private val mutableProgressAboutEvent = MutableLiveData<Boolean>()
val progressAboutEvent: LiveData<Boolean> = mutableProgressAboutEvent
private val mutableEvent = MutableLiveData<Event>()
val event: LiveData<Event> = mutableEvent
private val mutableError = MutableLiveData<String>()
val error: LiveData<String> = mutableError

fun loadEvent(id: Long) {
if (id.equals(-1)) {
error.value = "Error fetching event"
mutableError.value = "Error fetching event"
return
}
compositeDisposable.add(eventService.getEvent(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe({
progressAboutEvent.value = true
}).doFinally({
progressAboutEvent.value = false
}).subscribe({ eventList ->
event.value = eventList
}, {
error.value = "Error fetching event"
Timber.e(it, "Error fetching event %d", id)
}))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe({
mutableProgressAboutEvent.value = true
}).doFinally({
mutableProgressAboutEvent.value = false
}).subscribe({ eventList ->
mutableEvent.value = eventList
}, {
mutableError.value = "Error fetching event"
Timber.e(it, "Error fetching event %d", id)
})
)
}

override fun onCleared() {
Expand Down