mirror of
https://github.com/NiciDieNase/chaosflix
synced 2024-11-23 04:43:07 +00:00
add LiveData to get update-status so we can show a loading-spinner
This commit is contained in:
parent
fb167cb4dd
commit
b6cc2808b4
4 changed files with 44 additions and 32 deletions
|
@ -3,16 +3,10 @@ package de.nicidienase.chaosflix.touch.browse
|
|||
import android.arch.lifecycle.LiveData
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import de.nicidienase.chaosflix.common.entities.ChaosflixDatabase
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.ConferenceGroup
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.PersistentConference
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.PersistentEvent
|
||||
import de.nicidienase.chaosflix.common.entities.recording.persistence.PersistentRecording
|
||||
import de.nicidienase.chaosflix.common.entities.userdata.WatchlistItem
|
||||
import de.nicidienase.chaosflix.common.network.RecordingService
|
||||
import de.nicidienase.chaosflix.common.network.StreamingService
|
||||
import de.nicidienase.chaosflix.touch.sync.Downloader
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class BrowseViewModel(
|
||||
val database: ChaosflixDatabase,
|
||||
|
@ -22,25 +16,30 @@ class BrowseViewModel(
|
|||
|
||||
val downloader = Downloader(recordingApi, database)
|
||||
|
||||
fun getConferenceGroups(): LiveData<List<ConferenceGroup>> {
|
||||
downloader.updateConferencesAndGroups()
|
||||
return database.conferenceGroupDao().getAll()
|
||||
}
|
||||
fun getConferenceGroups()
|
||||
= database.conferenceGroupDao().getAll()
|
||||
|
||||
fun getConference(conferenceId: Long): LiveData<PersistentConference>
|
||||
fun getConference(conferenceId: Long)
|
||||
= database.conferenceDao().findConferenceById(conferenceId)
|
||||
|
||||
fun getConferencesByGroup(groupId: Long): LiveData<List<PersistentConference>>
|
||||
fun getConferencesByGroup(groupId: Long)
|
||||
= database.conferenceDao().findConferenceByGroup(groupId)
|
||||
|
||||
fun getEventsforConference(conferenceId: Long): LiveData<List<PersistentEvent>> {
|
||||
downloader.updateEventsForConference(conferenceId)
|
||||
return database.eventDao().findEventsByConference(conferenceId)
|
||||
}
|
||||
fun getEventsforConference(conferenceId: Long)
|
||||
= database.eventDao().findEventsByConference(conferenceId)
|
||||
|
||||
fun getBookmarkedEvents(): LiveData<List<PersistentEvent>> = database.eventDao().findBookmarkedEvents()
|
||||
fun updateConferences()
|
||||
= downloader.updateConferencesAndGroups()
|
||||
|
||||
fun getInProgressEvents(): LiveData<List<PersistentEvent>> = database.eventDao().findInProgressEvents()
|
||||
fun updateEventsForConference(conferenceId: Long)
|
||||
= downloader.updateEventsForConference(conferenceId)
|
||||
|
||||
fun getLivestreams() = streamingApi.getStreamingConferences()
|
||||
fun getBookmarkedEvents()
|
||||
= database.eventDao().findBookmarkedEvents()
|
||||
|
||||
fun getInProgressEvents()
|
||||
= database.eventDao().findInProgressEvents()
|
||||
|
||||
fun getLivestreams()
|
||||
= streamingApi.getStreamingConferences()
|
||||
}
|
|
@ -74,6 +74,7 @@ public class ConferencesTabBrowseFragment extends BrowseFragment {
|
|||
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
});
|
||||
getViewModel().updateConferences(); // TODO show and dismiss loading-spinner
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ public class EventsListFragment extends BrowseFragment implements SearchView.OnQ
|
|||
});
|
||||
|
||||
getViewModel().getEventsforConference(conferenceId).observe(this, listObserver);
|
||||
getViewModel().updateEventsForConference(conferenceId); // TODO show/dismiss loading-spinner
|
||||
}
|
||||
}
|
||||
return view;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.nicidienase.chaosflix.touch.sync
|
||||
|
||||
import android.arch.lifecycle.LiveData
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import android.util.Log
|
||||
import de.nicidienase.chaosflix.common.Util
|
||||
import de.nicidienase.chaosflix.common.entities.ChaosflixDatabase
|
||||
|
@ -18,9 +20,9 @@ class Downloader(val recordingApi: RecordingService,
|
|||
|
||||
private fun updateEverything() {
|
||||
updateConferencesAndGroups { conferenceIds ->
|
||||
for(id in conferenceIds){
|
||||
updateEventsForConference(id){ eventIds ->
|
||||
for(id in eventIds){
|
||||
for (id in conferenceIds) {
|
||||
updateEventsForConference(id) { eventIds ->
|
||||
for (id in eventIds) {
|
||||
updateRecordingsForEvent(id)
|
||||
}
|
||||
}
|
||||
|
@ -28,41 +30,50 @@ class Downloader(val recordingApi: RecordingService,
|
|||
}
|
||||
}
|
||||
|
||||
fun updateConferencesAndGroups(listener: ((List<Long>) -> Unit)? = null) {
|
||||
fun updateConferencesAndGroups(listener: ((List<Long>) -> Unit)? = null): LiveData<Boolean> {
|
||||
val updateFinished = MutableLiveData<Boolean>()
|
||||
updateFinished.value = false
|
||||
recordingApi.getConferencesWrapper()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe( { con: ConferencesWrapper? -> saveConferences(con, listener) },{
|
||||
t: Throwable? -> Log.d(TAG,t?.message,t)
|
||||
.subscribe({ con: ConferencesWrapper? ->
|
||||
saveConferences(con, listener)
|
||||
updateFinished.postValue(true)
|
||||
}, { t: Throwable? ->
|
||||
Log.d(TAG, t?.message, t)
|
||||
})
|
||||
return updateFinished
|
||||
}
|
||||
|
||||
private val TAG: String? = Downloader::class.simpleName
|
||||
|
||||
fun updateEventsForConference(conferenceId: Long, listener: ((List<Long>) -> Unit)? = null) {
|
||||
if(conferenceId < 0)
|
||||
if (conferenceId < 0)
|
||||
return
|
||||
val updateFinished = MutableLiveData<Boolean>()
|
||||
updateFinished.value = false
|
||||
recordingApi.getConference(conferenceId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe({ conference: Conference? ->
|
||||
saveEvents(conference, listener)
|
||||
}, {
|
||||
t: Throwable? -> Log.d(TAG,t?.message,t)
|
||||
updateFinished.postValue(true)
|
||||
}, { t: Throwable? ->
|
||||
Log.d(TAG, t?.message, t)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fun updateRecordingsForEvent(eventId: Long, listener: ((List<Long>) -> Unit)? = null) {
|
||||
if(eventId < 0)
|
||||
if (eventId < 0)
|
||||
return
|
||||
recordingApi.getEvent(eventId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe ({ event: Event? ->
|
||||
.subscribe({ event: Event? ->
|
||||
saveRecordings(event, listener)
|
||||
}, {
|
||||
t: Throwable? -> Log.d(TAG,t?.message,t)
|
||||
}, { t: Throwable? ->
|
||||
Log.d(TAG, t?.message, t)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue