Fix crashing for the first time

This commit is contained in:
h4h13 2020-04-26 22:57:14 +05:30
parent 58dc709a7e
commit ad6eec2240
4 changed files with 8 additions and 8 deletions

View file

@ -10,7 +10,7 @@ import code.name.monkey.retromusic.providers.RepositoryImpl
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class AlbumViewModel(application: Application) : AndroidViewModel(application) { class AlbumViewModel(application: Application) : AndroidViewModel(application) {
lateinit var albums: MutableLiveData<List<Album>> var albums = MutableLiveData<List<Album>>()
init { init {
getAlbums() getAlbums()
@ -19,7 +19,7 @@ class AlbumViewModel(application: Application) : AndroidViewModel(application) {
fun getAlbums() = viewModelScope.launch { fun getAlbums() = viewModelScope.launch {
val result = RepositoryImpl(getApplication()).allAlbums() val result = RepositoryImpl(getApplication()).allAlbums()
if (result is Result.Success) { if (result is Result.Success) {
albums = MutableLiveData(result.data) albums.value = result.data
} }
} }
} }

View file

@ -10,7 +10,7 @@ import code.name.monkey.retromusic.providers.RepositoryImpl
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class ArtistViewModel(application: Application) : AndroidViewModel(application) { class ArtistViewModel(application: Application) : AndroidViewModel(application) {
lateinit var artists: MutableLiveData<List<Artist>> var artists = MutableLiveData<List<Artist>>()
init { init {
loadArtists() loadArtists()
@ -19,7 +19,7 @@ class ArtistViewModel(application: Application) : AndroidViewModel(application)
fun loadArtists() = viewModelScope.launch { fun loadArtists() = viewModelScope.launch {
val result = RepositoryImpl(getApplication()).allArtists() val result = RepositoryImpl(getApplication()).allArtists()
if (result is Result.Success) { if (result is Result.Success) {
artists = MutableLiveData(result.data) artists.value = result.data
} }
} }
} }

View file

@ -10,7 +10,7 @@ import code.name.monkey.retromusic.providers.RepositoryImpl
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class GenreViewModel(application: Application) : AndroidViewModel(application) { class GenreViewModel(application: Application) : AndroidViewModel(application) {
lateinit var genres: MutableLiveData<List<Genre>> var genres = MutableLiveData<List<Genre>>()
init { init {
loadGenre() loadGenre()
@ -19,7 +19,7 @@ class GenreViewModel(application: Application) : AndroidViewModel(application) {
fun loadGenre() = viewModelScope.launch { fun loadGenre() = viewModelScope.launch {
val result = RepositoryImpl(getApplication()).allGenres() val result = RepositoryImpl(getApplication()).allGenres()
if (result is Success) { if (result is Success) {
genres = MutableLiveData(result.data) genres.value = result.data
} }
} }
} }

View file

@ -10,7 +10,7 @@ import code.name.monkey.retromusic.providers.RepositoryImpl
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class HomeViewModel(application: Application) : AndroidViewModel(application) { class HomeViewModel(application: Application) : AndroidViewModel(application) {
lateinit var sections: MutableLiveData<List<Home>> var sections = MutableLiveData<List<Home>>()
var repository: RepositoryImpl = RepositoryImpl(getApplication()) var repository: RepositoryImpl = RepositoryImpl(getApplication())
init { init {
@ -31,6 +31,6 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
is Result.Success -> list.add(r.data) is Result.Success -> list.add(r.data)
} }
} }
sections = MutableLiveData(list) sections.value = list
} }
} }