Code refactor
This commit is contained in:
parent
ffa0749849
commit
061b9c90ab
24 changed files with 108 additions and 126 deletions
|
@ -31,7 +31,7 @@ object Constants {
|
||||||
const val APP_TWITTER_LINK = "https://twitter.com/retromusicapp"
|
const val APP_TWITTER_LINK = "https://twitter.com/retromusicapp"
|
||||||
const val FAQ_LINK = "https://github.com/h4h13/RetroMusicPlayer/blob/master/FAQ.md"
|
const val FAQ_LINK = "https://github.com/h4h13/RetroMusicPlayer/blob/master/FAQ.md"
|
||||||
const val PINTEREST = "https://in.pinterest.com/retromusicapp/"
|
const val PINTEREST = "https://in.pinterest.com/retromusicapp/"
|
||||||
const val BASE_URL = "https://ws.audioscrobbler.com/2.0/"
|
const val AUDIO_SCROBBLER_URL = "https://ws.audioscrobbler.com/2.0/"
|
||||||
|
|
||||||
const val IS_MUSIC =
|
const val IS_MUSIC =
|
||||||
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"
|
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"
|
||||||
|
@ -70,8 +70,8 @@ const val NOW_PLAYING_SCREEN_ID = "now_playing_screen_id"
|
||||||
const val CAROUSEL_EFFECT = "carousel_effect"
|
const val CAROUSEL_EFFECT = "carousel_effect"
|
||||||
const val COLORED_NOTIFICATION = "colored_notification"
|
const val COLORED_NOTIFICATION = "colored_notification"
|
||||||
const val CLASSIC_NOTIFICATION = "classic_notification"
|
const val CLASSIC_NOTIFICATION = "classic_notification"
|
||||||
const val GAPLESS_PLAYBACK = "gapless_playback"
|
const val GAP_LESS_PLAYBACK = "gap_less_playback"
|
||||||
const val ALBUM_ART_ON_LOCKSCREEN = "album_art_on_lockscreen"
|
const val ALBUM_ART_ON_LOCK_SCREEN = "album_art_on_lock_screen"
|
||||||
const val BLURRED_ALBUM_ART = "blurred_album_art"
|
const val BLURRED_ALBUM_ART = "blurred_album_art"
|
||||||
const val NEW_BLUR_AMOUNT = "new_blur_amount"
|
const val NEW_BLUR_AMOUNT = "new_blur_amount"
|
||||||
const val TOGGLE_HEADSET = "toggle_headset"
|
const val TOGGLE_HEADSET = "toggle_headset"
|
||||||
|
@ -92,7 +92,6 @@ const val ALBUM_COVER_STYLE = "album_cover_style_id"
|
||||||
const val ALBUM_COVER_TRANSFORM = "album_cover_transform"
|
const val ALBUM_COVER_TRANSFORM = "album_cover_transform"
|
||||||
const val TAB_TEXT_MODE = "tab_text_mode"
|
const val TAB_TEXT_MODE = "tab_text_mode"
|
||||||
const val LANGUAGE_NAME = "language_name"
|
const val LANGUAGE_NAME = "language_name"
|
||||||
const val DIALOG_CORNER = "dialog_corner"
|
|
||||||
const val SLEEP_TIMER_FINISH_SONG = "sleep_timer_finish_song"
|
const val SLEEP_TIMER_FINISH_SONG = "sleep_timer_finish_song"
|
||||||
const val ALBUM_GRID_STYLE = "album_grid_style_home"
|
const val ALBUM_GRID_STYLE = "album_grid_style_home"
|
||||||
const val ARTIST_GRID_STYLE = "artist_grid_style_home"
|
const val ARTIST_GRID_STYLE = "artist_grid_style_home"
|
||||||
|
|
|
@ -13,7 +13,6 @@ import code.name.monkey.retromusic.fragments.artists.ArtistDetailsViewModel
|
||||||
import code.name.monkey.retromusic.fragments.genres.GenreDetailsViewModel
|
import code.name.monkey.retromusic.fragments.genres.GenreDetailsViewModel
|
||||||
import code.name.monkey.retromusic.fragments.playlists.PlaylistDetailsViewModel
|
import code.name.monkey.retromusic.fragments.playlists.PlaylistDetailsViewModel
|
||||||
import code.name.monkey.retromusic.fragments.search.SearchViewModel
|
import code.name.monkey.retromusic.fragments.search.SearchViewModel
|
||||||
import code.name.monkey.retromusic.fragments.songs.SongsViewModel
|
|
||||||
import code.name.monkey.retromusic.model.Genre
|
import code.name.monkey.retromusic.model.Genre
|
||||||
import code.name.monkey.retromusic.network.networkModule
|
import code.name.monkey.retromusic.network.networkModule
|
||||||
import code.name.monkey.retromusic.repository.*
|
import code.name.monkey.retromusic.repository.*
|
||||||
|
@ -152,10 +151,6 @@ private val viewModules = module {
|
||||||
viewModel {
|
viewModel {
|
||||||
SearchViewModel(get())
|
SearchViewModel(get())
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel {
|
|
||||||
SongsViewModel(get())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val appModules = listOf(mainModule, dataModule, viewModules, networkModule, roomModule)
|
val appModules = listOf(mainModule, dataModule, viewModules, networkModule, roomModule)
|
|
@ -51,7 +51,8 @@ class AddToRetroPlaylist : BottomSheetDialogFragment() {
|
||||||
return materialDialog(R.string.add_playlist_title)
|
return materialDialog(R.string.add_playlist_title)
|
||||||
.setItems(playlistNames.toTypedArray()) { _, which ->
|
.setItems(playlistNames.toTypedArray()) { _, which ->
|
||||||
if (which == 0) {
|
if (which == 0) {
|
||||||
CreateRetroPlaylist.create(songs).show(requireActivity().supportFragmentManager, "Dialog")
|
CreateRetroPlaylist.create(songs)
|
||||||
|
.show(requireActivity().supportFragmentManager, "Dialog")
|
||||||
} else {
|
} else {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val songEntities = songs.toSongEntity(playlistEntities[which - 1])
|
val songEntities = songs.toSongEntity(playlistEntities[which - 1])
|
||||||
|
|
|
@ -12,9 +12,7 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||||
import code.name.monkey.retromusic.model.*
|
import code.name.monkey.retromusic.model.*
|
||||||
import code.name.monkey.retromusic.repository.RealRepository
|
import code.name.monkey.retromusic.repository.RealRepository
|
||||||
import kotlinx.coroutines.Deferred
|
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class LibraryViewModel(
|
class LibraryViewModel(
|
||||||
|
@ -25,75 +23,95 @@ class LibraryViewModel(
|
||||||
private val albums = MutableLiveData<List<Album>>()
|
private val albums = MutableLiveData<List<Album>>()
|
||||||
private val songs = MutableLiveData<List<Song>>()
|
private val songs = MutableLiveData<List<Song>>()
|
||||||
private val artists = MutableLiveData<List<Artist>>()
|
private val artists = MutableLiveData<List<Artist>>()
|
||||||
private val playlists = MutableLiveData<List<Playlist>>()
|
private val playlists = MutableLiveData<List<PlaylistWithSongs>>()
|
||||||
private val roomPlaylists = MutableLiveData<List<PlaylistWithSongs>>()
|
|
||||||
private val genres = MutableLiveData<List<Genre>>()
|
private val genres = MutableLiveData<List<Genre>>()
|
||||||
private val home = MutableLiveData<List<Home>>()
|
private val home = MutableLiveData<List<Home>>()
|
||||||
|
|
||||||
val paletteColorLiveData: LiveData<Int> = paletteColor
|
val paletteColorLiveData: LiveData<Int> = paletteColor
|
||||||
val homeLiveData: LiveData<List<Home>> = home
|
|
||||||
val albumsLiveData: LiveData<List<Album>> = albums
|
|
||||||
val songsLiveData: LiveData<List<Song>> = songs
|
|
||||||
val artistsLiveData: LiveData<List<Artist>> = artists
|
|
||||||
val playlisitsLiveData: LiveData<List<Playlist>> = playlists
|
|
||||||
val roomPlaylistsLiveData: LiveData<List<PlaylistWithSongs>> = roomPlaylists
|
|
||||||
val genresLiveData: LiveData<List<Genre>> = genres
|
|
||||||
|
|
||||||
init {
|
private fun loadLibraryContent() = viewModelScope.launch(IO) {
|
||||||
viewModelScope.launch {
|
fetchSongs()
|
||||||
loadLibraryContent()
|
fetchAlbums()
|
||||||
|
fetchArtists()
|
||||||
|
fetchGenres()
|
||||||
|
fetchHomeSections()
|
||||||
|
fetchPlaylists()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSongs(): LiveData<List<Song>> {
|
||||||
|
fetchSongs()
|
||||||
|
return songs
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAlbums(): LiveData<List<Album>> {
|
||||||
|
fetchAlbums()
|
||||||
|
return albums
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getArtists(): LiveData<List<Artist>> {
|
||||||
|
fetchArtists()
|
||||||
|
return artists
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPlaylists(): LiveData<List<PlaylistWithSongs>> {
|
||||||
|
fetchPlaylists()
|
||||||
|
return playlists
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGenre(): LiveData<List<Genre>> {
|
||||||
|
fetchGenres()
|
||||||
|
return genres
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getHome(): LiveData<List<Home>> {
|
||||||
|
fetchHomeSections()
|
||||||
|
return home
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchSongs() {
|
||||||
|
viewModelScope.launch(IO) {
|
||||||
|
songs.postValue(repository.allSongs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadLibraryContent() = viewModelScope.launch {
|
private fun fetchAlbums() {
|
||||||
home.value = loadHome.await()
|
viewModelScope.launch(IO) {
|
||||||
songs.value = loadSongs.await()
|
albums.postValue(repository.fetchAlbums())
|
||||||
albums.value = loadAlbums.await()
|
}
|
||||||
artists.value = loadArtists.await()
|
|
||||||
playlists.value = loadPlaylists.await()
|
|
||||||
roomPlaylists.value = loadPlaylistsWithSongs.await()
|
|
||||||
genres.value = loadGenres.await()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loadHome: Deferred<List<Home>>
|
private fun fetchArtists() {
|
||||||
get() = viewModelScope.async { repository.homeSections() }
|
viewModelScope.launch(IO) {
|
||||||
|
artists.postValue(repository.fetchArtists())
|
||||||
private val loadSongs: Deferred<List<Song>>
|
}
|
||||||
get() = viewModelScope.async(IO) { repository.allSongs() }
|
|
||||||
|
|
||||||
private val loadAlbums: Deferred<List<Album>>
|
|
||||||
get() = viewModelScope.async(IO) {
|
|
||||||
repository.allAlbums()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loadArtists: Deferred<List<Artist>>
|
private fun fetchPlaylists() {
|
||||||
get() = viewModelScope.async(IO) {
|
viewModelScope.launch(IO) {
|
||||||
repository.albumArtists()
|
playlists.postValue(repository.fetchPlaylistWithSongs())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loadPlaylists: Deferred<List<Playlist>>
|
private fun fetchGenres() {
|
||||||
get() = viewModelScope.async(IO) {
|
viewModelScope.launch(IO) {
|
||||||
repository.allPlaylists()
|
genres.postValue(repository.fetchGenres())
|
||||||
}
|
}
|
||||||
private val loadPlaylistsWithSongs: Deferred<List<PlaylistWithSongs>>
|
|
||||||
get() = viewModelScope.async(IO) {
|
|
||||||
repository.playlistWithSongs()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val loadGenres: Deferred<List<Genre>>
|
private fun fetchHomeSections() {
|
||||||
get() = viewModelScope.async(IO) {
|
viewModelScope.launch(IO) {
|
||||||
repository.allGenres()
|
home.postValue(repository.homeSections())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun forceReload(reloadType: ReloadType) = viewModelScope.launch {
|
fun forceReload(reloadType: ReloadType) = viewModelScope.launch {
|
||||||
when (reloadType) {
|
when (reloadType) {
|
||||||
Songs -> songs.value = loadSongs.await()
|
Songs -> fetchSongs()
|
||||||
Albums -> albums.value = loadAlbums.await()
|
Albums -> fetchAlbums()
|
||||||
Artists -> artists.value = loadArtists.await()
|
Artists -> fetchArtists()
|
||||||
HomeSections -> home.value = loadHome.await()
|
HomeSections -> fetchHomeSections()
|
||||||
Playlists -> roomPlaylists.value = loadPlaylistsWithSongs.await()
|
Playlists -> fetchPlaylists()
|
||||||
Genres -> genres.value = loadGenres.await()
|
Genres -> fetchGenres()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ enum class NowPlayingScreen constructor(
|
||||||
Gradient(R.string.gradient, R.drawable.np_gradient, 17),
|
Gradient(R.string.gradient, R.drawable.np_gradient, 17),
|
||||||
Material(R.string.material, R.drawable.np_material, 11),
|
Material(R.string.material, R.drawable.np_material, 11),
|
||||||
Normal(R.string.normal, R.drawable.np_normal, 0),
|
Normal(R.string.normal, R.drawable.np_normal, 0),
|
||||||
|
|
||||||
//Peak(R.string.peak, R.drawable.np_peak, 14),
|
//Peak(R.string.peak, R.drawable.np_peak, 14),
|
||||||
Plain(R.string.plain, R.drawable.np_plain, 3),
|
Plain(R.string.plain, R.drawable.np_plain, 3),
|
||||||
Simple(R.string.simple, R.drawable.np_simple, 8),
|
Simple(R.string.simple, R.drawable.np_simple, 8),
|
||||||
|
|
|
@ -287,7 +287,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, songs)
|
AddToRetroPlaylist.create(playlists, songs)
|
||||||
.show(childFragmentManager, "ADD_PLAYLIST")
|
.show(childFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -23,7 +23,7 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridL
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.albumsLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getAlbums().observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
|
|
|
@ -227,7 +227,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, songs)
|
AddToRetroPlaylist.create(playlists, songs)
|
||||||
.show(childFragmentManager, "ADD_PLAYLIST")
|
.show(childFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -22,7 +22,7 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment<ArtistAdapter, Gri
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.artistsLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getArtists().observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
|
|
|
@ -72,7 +72,7 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
lifecycleScope.launch(IO) {
|
lifecycleScope.launch(IO) {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Main) {
|
withContext(Main) {
|
||||||
AddToRetroPlaylist.create(playlists, song)
|
AddToRetroPlaylist.create(playlists, song)
|
||||||
.show(childFragmentManager, "ADD_PLAYLIST")
|
.show(childFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -26,7 +26,7 @@ class GenresFragment : AbsRecyclerViewFragment<GenreAdapter, LinearLayoutManager
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.genresLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getGenre().observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
|
|
|
@ -96,7 +96,7 @@ class HomeFragment :
|
||||||
adapter = homeAdapter
|
adapter = homeAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryViewModel.homeLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getHome().observe(viewLifecycleOwner, Observer {
|
||||||
homeAdapter.swapData(it)
|
homeAdapter.swapData(it)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class PlaylistsFragment : AbsRecyclerViewFragment<PlaylistAdapter, GridLayoutMan
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.roomPlaylistsLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getPlaylists().observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,9 +16,11 @@ import code.name.monkey.retromusic.util.RetroUtil
|
||||||
|
|
||||||
class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>() {
|
class SongsFragment : AbsRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>() {
|
||||||
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.songsLiveData.observe(viewLifecycleOwner, Observer {
|
libraryViewModel.getSongs().observe(viewLifecycleOwner, Observer {
|
||||||
|
println(Thread.currentThread().name)
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package code.name.monkey.retromusic.fragments.songs
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
|
||||||
import code.name.monkey.retromusic.repository.SongRepository
|
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class SongsViewModel(
|
|
||||||
private val songRepository: SongRepository
|
|
||||||
) : ViewModel() {
|
|
||||||
init {
|
|
||||||
update()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val songsData = MutableLiveData<List<Song>>().apply { value = mutableListOf() }
|
|
||||||
|
|
||||||
fun getSongList(): LiveData<List<Song>> {
|
|
||||||
return songsData
|
|
||||||
}
|
|
||||||
|
|
||||||
fun update() {
|
|
||||||
viewModelScope.launch(IO) {
|
|
||||||
val songs = songRepository.songs()
|
|
||||||
songsData.postValue(songs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,7 +45,7 @@ object GenreMenuHelper : KoinComponent {
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, getGenreSongs(genre))
|
AddToRetroPlaylist.create(playlists, getGenreSongs(genre))
|
||||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -58,7 +58,7 @@ object PlaylistMenuHelper : KoinComponent {
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, playlistWithSongs.songs.toSongs())
|
AddToRetroPlaylist.create(playlists, playlistWithSongs.songs.toSongs())
|
||||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -71,7 +71,7 @@ object SongMenuHelper : KoinComponent {
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, song)
|
AddToRetroPlaylist.create(playlists, song)
|
||||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -45,7 +45,7 @@ object SongsMenuHelper : KoinComponent {
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val playlists = get<RealRepository>().roomPlaylists()
|
val playlists = get<RealRepository>().fetchPlaylists()
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
AddToRetroPlaylist.create(playlists, songs)
|
AddToRetroPlaylist.create(playlists, songs)
|
||||||
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package code.name.monkey.retromusic.network
|
package code.name.monkey.retromusic.network
|
||||||
|
|
||||||
import code.name.monkey.retromusic.App
|
import code.name.monkey.retromusic.App
|
||||||
import code.name.monkey.retromusic.Constants.BASE_URL
|
import code.name.monkey.retromusic.Constants.AUDIO_SCROBBLER_URL
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import okhttp3.Cache
|
import okhttp3.Cache
|
||||||
import okhttp3.ConnectionPool
|
import okhttp3.ConnectionPool
|
||||||
|
@ -37,7 +37,7 @@ fun provideLastFmService(retrofit: Retrofit): LastFMService =
|
||||||
retrofit.create(LastFMService::class.java)
|
retrofit.create(LastFMService::class.java)
|
||||||
|
|
||||||
fun providerRetrofit(okHttpClient: OkHttpClient.Builder): Retrofit = Retrofit.Builder()
|
fun providerRetrofit(okHttpClient: OkHttpClient.Builder): Retrofit = Retrofit.Builder()
|
||||||
.baseUrl(BASE_URL)
|
.baseUrl(AUDIO_SCROBBLER_URL)
|
||||||
.callFactory(okHttpClient.build())
|
.callFactory(okHttpClient.build())
|
||||||
.addConverterFactory(GsonConverterFactory.create(Gson()))
|
.addConverterFactory(GsonConverterFactory.create(Gson()))
|
||||||
.build()
|
.build()
|
||||||
|
|
|
@ -37,14 +37,14 @@ interface Repository {
|
||||||
fun genresFlow(): Flow<Result<List<Genre>>>
|
fun genresFlow(): Flow<Result<List<Genre>>>
|
||||||
fun historySong(): LiveData<List<HistoryEntity>>
|
fun historySong(): LiveData<List<HistoryEntity>>
|
||||||
fun favorites(): LiveData<List<SongEntity>>
|
fun favorites(): LiveData<List<SongEntity>>
|
||||||
suspend fun allAlbums(): List<Album>
|
suspend fun fetchAlbums(): List<Album>
|
||||||
suspend fun albumByIdAsync(albumId: Int): Album
|
suspend fun albumByIdAsync(albumId: Int): Album
|
||||||
fun albumById(albumId: Int): Album
|
fun albumById(albumId: Int): Album
|
||||||
suspend fun allSongs(): List<Song>
|
suspend fun allSongs(): List<Song>
|
||||||
suspend fun allArtists(): List<Artist>
|
suspend fun fetchArtists(): List<Artist>
|
||||||
suspend fun albumArtists(): List<Artist>
|
suspend fun albumArtists(): List<Artist>
|
||||||
suspend fun allPlaylists(): List<Playlist>
|
suspend fun allPlaylists(): List<Playlist>
|
||||||
suspend fun allGenres(): List<Genre>
|
suspend fun fetchGenres(): List<Genre>
|
||||||
suspend fun search(query: String?): MutableList<Any>
|
suspend fun search(query: String?): MutableList<Any>
|
||||||
suspend fun getPlaylistSongs(playlist: Playlist): List<Song>
|
suspend fun getPlaylistSongs(playlist: Playlist): List<Song>
|
||||||
suspend fun getGenre(genreId: Int): List<Song>
|
suspend fun getGenre(genreId: Int): List<Song>
|
||||||
|
@ -66,12 +66,12 @@ interface Repository {
|
||||||
suspend fun homeSections(): List<Home>
|
suspend fun homeSections(): List<Home>
|
||||||
suspend fun homeSectionsFlow(): Flow<Result<List<Home>>>
|
suspend fun homeSectionsFlow(): Flow<Result<List<Home>>>
|
||||||
suspend fun playlist(playlistId: Int): Playlist
|
suspend fun playlist(playlistId: Int): Playlist
|
||||||
suspend fun playlistWithSongs(): List<PlaylistWithSongs>
|
suspend fun fetchPlaylistWithSongs(): List<PlaylistWithSongs>
|
||||||
suspend fun playlistSongs(playlistWithSongs: PlaylistWithSongs): List<Song>
|
suspend fun playlistSongs(playlistWithSongs: PlaylistWithSongs): List<Song>
|
||||||
suspend fun insertSongs(songs: List<SongEntity>)
|
suspend fun insertSongs(songs: List<SongEntity>)
|
||||||
suspend fun checkPlaylistExists(playlistName: String): List<PlaylistEntity>
|
suspend fun checkPlaylistExists(playlistName: String): List<PlaylistEntity>
|
||||||
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
|
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
|
||||||
suspend fun roomPlaylists(): List<PlaylistEntity>
|
suspend fun fetchPlaylists(): List<PlaylistEntity>
|
||||||
suspend fun deleteRoomPlaylist(playlists: List<PlaylistEntity>)
|
suspend fun deleteRoomPlaylist(playlists: List<PlaylistEntity>)
|
||||||
suspend fun renameRoomPlaylist(playlistId: Int, name: String)
|
suspend fun renameRoomPlaylist(playlistId: Int, name: String)
|
||||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||||
|
@ -107,11 +107,11 @@ class RealRepository(
|
||||||
private val roomRepository: RoomRepository
|
private val roomRepository: RoomRepository
|
||||||
) : Repository {
|
) : Repository {
|
||||||
|
|
||||||
override suspend fun allAlbums(): List<Album> = albumRepository.albums()
|
override suspend fun fetchAlbums(): List<Album> = albumRepository.albums()
|
||||||
|
|
||||||
override suspend fun albumByIdAsync(albumId: Int): Album = albumRepository.album(albumId)
|
override suspend fun albumByIdAsync(albumId: Int): Album = albumRepository.album(albumId)
|
||||||
override fun albumById(albumId: Int): Album = albumRepository.album(albumId)
|
override fun albumById(albumId: Int): Album = albumRepository.album(albumId)
|
||||||
override suspend fun allArtists(): List<Artist> = artistRepository.artists()
|
override suspend fun fetchArtists(): List<Artist> = artistRepository.artists()
|
||||||
|
|
||||||
override suspend fun albumArtists(): List<Artist> = artistRepository.albumArtists()
|
override suspend fun albumArtists(): List<Artist> = artistRepository.albumArtists()
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ class RealRepository(
|
||||||
|
|
||||||
override suspend fun allPlaylists(): List<Playlist> = playlistRepository.playlists()
|
override suspend fun allPlaylists(): List<Playlist> = playlistRepository.playlists()
|
||||||
|
|
||||||
override suspend fun allGenres(): List<Genre> = genreRepository.genres()
|
override suspend fun fetchGenres(): List<Genre> = genreRepository.genres()
|
||||||
|
|
||||||
override suspend fun allSongs(): List<Song> = songRepository.songs()
|
override suspend fun allSongs(): List<Song> = songRepository.songs()
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class RealRepository(
|
||||||
override suspend fun playlist(playlistId: Int) =
|
override suspend fun playlist(playlistId: Int) =
|
||||||
playlistRepository.playlist(playlistId)
|
playlistRepository.playlist(playlistId)
|
||||||
|
|
||||||
override suspend fun playlistWithSongs(): List<PlaylistWithSongs> =
|
override suspend fun fetchPlaylistWithSongs(): List<PlaylistWithSongs> =
|
||||||
roomRepository.playlistWithSongs()
|
roomRepository.playlistWithSongs()
|
||||||
|
|
||||||
override suspend fun playlistSongs(playlistWithSongs: PlaylistWithSongs): List<Song> =
|
override suspend fun playlistSongs(playlistWithSongs: PlaylistWithSongs): List<Song> =
|
||||||
|
@ -222,7 +222,7 @@ class RealRepository(
|
||||||
override suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long =
|
override suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long =
|
||||||
roomRepository.createPlaylist(playlistEntity)
|
roomRepository.createPlaylist(playlistEntity)
|
||||||
|
|
||||||
override suspend fun roomPlaylists(): List<PlaylistEntity> = roomRepository.playlists()
|
override suspend fun fetchPlaylists(): List<PlaylistEntity> = roomRepository.playlists()
|
||||||
|
|
||||||
override suspend fun deleteRoomPlaylist(playlists: List<PlaylistEntity>) =
|
override suspend fun deleteRoomPlaylist(playlists: List<PlaylistEntity>) =
|
||||||
roomRepository.deletePlaylistEntities(playlists)
|
roomRepository.deletePlaylistEntities(playlists)
|
||||||
|
|
|
@ -84,11 +84,11 @@ import code.name.monkey.retromusic.util.MusicUtil;
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||||
import code.name.monkey.retromusic.util.RetroUtil;
|
import code.name.monkey.retromusic.util.RetroUtil;
|
||||||
|
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.ALBUM_ART_ON_LOCKSCREEN;
|
import static code.name.monkey.retromusic.ConstantsKt.ALBUM_ART_ON_LOCK_SCREEN;
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.BLURRED_ALBUM_ART;
|
import static code.name.monkey.retromusic.ConstantsKt.BLURRED_ALBUM_ART;
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.CLASSIC_NOTIFICATION;
|
import static code.name.monkey.retromusic.ConstantsKt.CLASSIC_NOTIFICATION;
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.COLORED_NOTIFICATION;
|
import static code.name.monkey.retromusic.ConstantsKt.COLORED_NOTIFICATION;
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.GAPLESS_PLAYBACK;
|
import static code.name.monkey.retromusic.ConstantsKt.GAP_LESS_PLAYBACK;
|
||||||
import static code.name.monkey.retromusic.ConstantsKt.TOGGLE_HEADSET;
|
import static code.name.monkey.retromusic.ConstantsKt.TOGGLE_HEADSET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -727,7 +727,7 @@ public class MusicService extends Service implements
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(@NonNull SharedPreferences sharedPreferences, @NonNull String key) {
|
public void onSharedPreferenceChanged(@NonNull SharedPreferences sharedPreferences, @NonNull String key) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case GAPLESS_PLAYBACK:
|
case GAP_LESS_PLAYBACK:
|
||||||
if (sharedPreferences.getBoolean(key, false)) {
|
if (sharedPreferences.getBoolean(key, false)) {
|
||||||
prepareNext();
|
prepareNext();
|
||||||
} else {
|
} else {
|
||||||
|
@ -736,7 +736,7 @@ public class MusicService extends Service implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ALBUM_ART_ON_LOCKSCREEN:
|
case ALBUM_ART_ON_LOCK_SCREEN:
|
||||||
case BLURRED_ALBUM_ART:
|
case BLURRED_ALBUM_ART:
|
||||||
updateMediaSessionMetaData();
|
updateMediaSessionMetaData();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -243,7 +243,7 @@ object PreferenceUtil {
|
||||||
|
|
||||||
val isAlbumArtOnLockScreen
|
val isAlbumArtOnLockScreen
|
||||||
get() = sharedPreferences.getBoolean(
|
get() = sharedPreferences.getBoolean(
|
||||||
ALBUM_ART_ON_LOCKSCREEN, false
|
ALBUM_ART_ON_LOCK_SCREEN, false
|
||||||
)
|
)
|
||||||
|
|
||||||
val isAudioDucking
|
val isAudioDucking
|
||||||
|
@ -292,7 +292,7 @@ object PreferenceUtil {
|
||||||
|
|
||||||
val isGapLessPlayback
|
val isGapLessPlayback
|
||||||
get() = sharedPreferences.getBoolean(
|
get() = sharedPreferences.getBoolean(
|
||||||
GAPLESS_PLAYBACK, false
|
GAP_LESS_PLAYBACK, false
|
||||||
)
|
)
|
||||||
|
|
||||||
val isAdaptiveColor
|
val isAdaptiveColor
|
||||||
|
@ -471,7 +471,7 @@ object PreferenceUtil {
|
||||||
|
|
||||||
var artistGridSizeLand
|
var artistGridSizeLand
|
||||||
get() = sharedPreferences.getInt(
|
get() = sharedPreferences.getInt(
|
||||||
ALBUM_GRID_SIZE_LAND,
|
ARTIST_GRID_SIZE_LAND,
|
||||||
App.getContext().getIntRes(R.integer.default_grid_columns_land)
|
App.getContext().getIntRes(R.integer.default_grid_columns_land)
|
||||||
)
|
)
|
||||||
set(value) = sharedPreferences.edit {
|
set(value) = sharedPreferences.edit {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="12dp">
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/history"
|
android:id="@+id/history"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
Loading…
Reference in a new issue