Fix not reloading when deleting files
This commit is contained in:
parent
3184d33886
commit
3c7328f9c6
7 changed files with 45 additions and 10 deletions
|
@ -104,6 +104,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
||||||
ActivityCompat.postponeEnterTransition(this)
|
ActivityCompat.postponeEnterTransition(this)
|
||||||
val viewModelFactory = AlbumDetailsViewModelFactory(application, albumId)
|
val viewModelFactory = AlbumDetailsViewModelFactory(application, albumId)
|
||||||
viewModel = ViewModelProvider(this, viewModelFactory).get(AlbumDetailsViewModel::class.java)
|
viewModel = ViewModelProvider(this, viewModelFactory).get(AlbumDetailsViewModel::class.java)
|
||||||
|
addMusicServiceEventListener(viewModel)
|
||||||
viewModel.getAlbum().observe(this, androidx.lifecycle.Observer {
|
viewModel.getAlbum().observe(this, androidx.lifecycle.Observer {
|
||||||
ActivityCompat.startPostponedEnterTransition(this@AlbumDetailsActivity)
|
ActivityCompat.startPostponedEnterTransition(this@AlbumDetailsActivity)
|
||||||
album(it)
|
album(it)
|
||||||
|
@ -388,6 +389,10 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
removeMusicServiceEventListener(viewModel)
|
||||||
|
}
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val EXTRA_ALBUM_ID = "extra_album_id"
|
const val EXTRA_ALBUM_ID = "extra_album_id"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.Album
|
import code.name.monkey.retromusic.model.Album
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.providers.RepositoryImpl
|
import code.name.monkey.retromusic.providers.RepositoryImpl
|
||||||
|
@ -17,7 +18,7 @@ import kotlinx.coroutines.launch
|
||||||
class AlbumDetailsViewModel(
|
class AlbumDetailsViewModel(
|
||||||
application: Application,
|
application: Application,
|
||||||
private val albumId: Int
|
private val albumId: Int
|
||||||
) : AndroidViewModel(application) {
|
) : AndroidViewModel(application), MusicServiceEventListener {
|
||||||
private val _repository = RepositoryImpl(application.applicationContext)
|
private val _repository = RepositoryImpl(application.applicationContext)
|
||||||
private val _album = MutableLiveData<Album>()
|
private val _album = MutableLiveData<Album>()
|
||||||
private val _artist = MutableLiveData<Artist>()
|
private val _artist = MutableLiveData<Artist>()
|
||||||
|
@ -28,10 +29,10 @@ class AlbumDetailsViewModel(
|
||||||
fun getAlbumInfo(): LiveData<LastFmAlbum> = _lastFmAlbum
|
fun getAlbumInfo(): LiveData<LastFmAlbum> = _lastFmAlbum
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadDetails()
|
loadAlbumDetails()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadDetails() = viewModelScope.launch {
|
private fun loadAlbumDetails() = viewModelScope.launch {
|
||||||
val album = loadAlbumAsync.await() ?: throw NullPointerException("Album couldn't found")
|
val album = loadAlbumAsync.await() ?: throw NullPointerException("Album couldn't found")
|
||||||
_album.postValue(album)
|
_album.postValue(album)
|
||||||
}
|
}
|
||||||
|
@ -50,4 +51,16 @@ class AlbumDetailsViewModel(
|
||||||
get() = viewModelScope.async(Dispatchers.IO) {
|
get() = viewModelScope.async(Dispatchers.IO) {
|
||||||
_repository.albumById(albumId)
|
_repository.albumById(albumId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMediaStoreChanged() {
|
||||||
|
loadAlbumDetails()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceConnected() {}
|
||||||
|
override fun onServiceDisconnected() {}
|
||||||
|
override fun onQueueChanged() {}
|
||||||
|
override fun onPlayingMetaChanged() {}
|
||||||
|
override fun onPlayStateChanged() {}
|
||||||
|
override fun onRepeatModeChanged() {}
|
||||||
|
override fun onShuffleModeChanged() {}
|
||||||
}
|
}
|
|
@ -98,6 +98,7 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
|
||||||
val viewModelFactory = ArtistDetailsViewModelFactory(application, artistId)
|
val viewModelFactory = ArtistDetailsViewModelFactory(application, artistId)
|
||||||
viewModel =
|
viewModel =
|
||||||
ViewModelProvider(this, viewModelFactory).get(ArtistDetailsViewModel::class.java)
|
ViewModelProvider(this, viewModelFactory).get(ArtistDetailsViewModel::class.java)
|
||||||
|
addMusicServiceEventListener(viewModel)
|
||||||
viewModel.getArtist().observe(this, androidx.lifecycle.Observer {
|
viewModel.getArtist().observe(this, androidx.lifecycle.Observer {
|
||||||
ActivityCompat.startPostponedEnterTransition(this@ArtistDetailActivity)
|
ActivityCompat.startPostponedEnterTransition(this@ArtistDetailActivity)
|
||||||
artist(it)
|
artist(it)
|
||||||
|
@ -320,6 +321,11 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
removeMusicServiceEventListener(viewModel)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val EXTRA_ARTIST_ID = "extra_artist_id"
|
const val EXTRA_ARTIST_ID = "extra_artist_id"
|
||||||
const val REQUEST_CODE_SELECT_IMAGE = 9003
|
const val REQUEST_CODE_SELECT_IMAGE = 9003
|
||||||
|
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.providers.RepositoryImpl
|
import code.name.monkey.retromusic.providers.RepositoryImpl
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
import code.name.monkey.retromusic.rest.model.LastFmArtist
|
||||||
|
@ -16,7 +17,7 @@ import kotlinx.coroutines.launch
|
||||||
class ArtistDetailsViewModel(
|
class ArtistDetailsViewModel(
|
||||||
application: Application,
|
application: Application,
|
||||||
private val artistId: Int
|
private val artistId: Int
|
||||||
) : AndroidViewModel(application) {
|
) : AndroidViewModel(application), MusicServiceEventListener {
|
||||||
|
|
||||||
private val loadArtistDetailsAsync: Deferred<Artist?>
|
private val loadArtistDetailsAsync: Deferred<Artist?>
|
||||||
get() = viewModelScope.async(Dispatchers.IO) {
|
get() = viewModelScope.async(Dispatchers.IO) {
|
||||||
|
@ -43,4 +44,16 @@ class ArtistDetailsViewModel(
|
||||||
val info = _repository.artistInfo(name, lang, cache)
|
val info = _repository.artistInfo(name, lang, cache)
|
||||||
_lastFmArtist.postValue(info)
|
_lastFmArtist.postValue(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMediaStoreChanged() {
|
||||||
|
loadArtistDetails()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onServiceConnected() {}
|
||||||
|
override fun onServiceDisconnected() {}
|
||||||
|
override fun onQueueChanged() {}
|
||||||
|
override fun onPlayingMetaChanged() {}
|
||||||
|
override fun onPlayStateChanged() {}
|
||||||
|
override fun onRepeatModeChanged() {}
|
||||||
|
override fun onShuffleModeChanged() {}
|
||||||
}
|
}
|
|
@ -36,7 +36,6 @@ class LibraryViewModel(application: Application) :
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
loadLibraryContent()
|
loadLibraryContent()
|
||||||
loadHomeSections()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +45,7 @@ class LibraryViewModel(application: Application) :
|
||||||
_artists.value = loadArtists.await()
|
_artists.value = loadArtists.await()
|
||||||
_playlist.value = loadPlaylists.await()
|
_playlist.value = loadPlaylists.await()
|
||||||
_genre.value = loadGenres.await()
|
_genre.value = loadGenres.await()
|
||||||
|
loadHomeSections()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadHomeSections() = viewModelScope.launch {
|
private fun loadHomeSections() = viewModelScope.launch {
|
||||||
|
|
|
@ -106,8 +106,8 @@ object PlaylistLoader {
|
||||||
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
|
||||||
arrayOf(
|
arrayOf(
|
||||||
BaseColumns._ID, /* 0 */
|
BaseColumns._ID, /* 0 */
|
||||||
PlaylistsColumns.NAME
|
PlaylistsColumns.NAME /* 1 */
|
||||||
), /* 1 */
|
),
|
||||||
selection,
|
selection,
|
||||||
values,
|
values,
|
||||||
MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER
|
MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER
|
||||||
|
|
|
@ -88,9 +88,7 @@
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
app:retroCornerSize="36dp"
|
app:retroCornerSize="36dp"
|
||||||
app:srcCompat="@drawable/ic_person_flat"
|
app:srcCompat="@drawable/ic_person_flat" />
|
||||||
app:strokeColor="?attr/colorSurface"
|
|
||||||
app:strokeWidth="2dp" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue