Code refactor 🧑💻
This commit is contained in:
parent
859d10d907
commit
2817dc1db5
30 changed files with 285 additions and 117 deletions
|
@ -1,5 +1,6 @@
|
|||
package code.name.monkey.retromusic.adapter
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -22,14 +23,14 @@ class GenreAdapter(
|
|||
var dataSet: List<Genre>,
|
||||
private val mItemLayoutRes: Int
|
||||
) : RecyclerView.Adapter<GenreAdapter.ViewHolder>() {
|
||||
|
||||
|
||||
val colors = listOf<Int>(Color.RED, Color.BLUE)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(LayoutInflater.from(activity).inflate(mItemLayoutRes, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val genre = dataSet[position]
|
||||
|
||||
holder.title?.text = genre.name
|
||||
holder.text?.text = String.format(
|
||||
Locale.getDefault(),
|
||||
|
|
|
@ -40,8 +40,8 @@ class HomeAdapter(
|
|||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val layout = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.section_recycler_view, parent, false)
|
||||
val layout =
|
||||
LayoutInflater.from(activity).inflate(R.layout.section_recycler_view, parent, false)
|
||||
return when (viewType) {
|
||||
RECENT_ARTISTS, TOP_ARTISTS -> ArtistViewHolder(layout)
|
||||
GENRES -> GenreViewHolder(layout)
|
||||
|
@ -205,10 +205,13 @@ class HomeAdapter(
|
|||
fun bind(home: Home) {
|
||||
arrow.hide()
|
||||
title.setText(home.titleRes)
|
||||
val genreAdapter = GenreAdapter(
|
||||
activity,
|
||||
home.arrayList as List<Genre>,
|
||||
R.layout.item_grid_genre
|
||||
)
|
||||
recyclerView.apply {
|
||||
layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.HORIZONTAL, false)
|
||||
val genreAdapter =
|
||||
GenreAdapter(activity, home.arrayList as List<Genre>, R.layout.item_grid_genre)
|
||||
adapter = genreAdapter
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package code.name.monkey.retromusic.db
|
|||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
|
||||
@Entity
|
||||
class HistoryEntity(
|
||||
|
@ -30,22 +29,4 @@ class HistoryEntity(
|
|||
val albumArtist: String?,
|
||||
@ColumnInfo(name = "time_played")
|
||||
val timePlayed: Long
|
||||
) {
|
||||
fun toSong(): Song {
|
||||
return Song(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
|
@ -0,0 +1,34 @@
|
|||
package code.name.monkey.retromusic.db
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
class PlayCountEntity(
|
||||
@PrimaryKey
|
||||
val id: Int,
|
||||
val title: String,
|
||||
@ColumnInfo(name = "track_number")
|
||||
val trackNumber: Int,
|
||||
val year: Int,
|
||||
val duration: Long,
|
||||
val data: String,
|
||||
@ColumnInfo(name = "date_modified")
|
||||
val dateModified: Long,
|
||||
@ColumnInfo(name = "album_id")
|
||||
val albumId: Int,
|
||||
@ColumnInfo(name = "album_name")
|
||||
val albumName: String,
|
||||
@ColumnInfo(name = "artist_id")
|
||||
val artistId: Int,
|
||||
@ColumnInfo(name = "artist_name")
|
||||
val artistName: String,
|
||||
val composer: String?,
|
||||
@ColumnInfo(name = "album_artist")
|
||||
val albumArtist: String?,
|
||||
@ColumnInfo(name = "time_played")
|
||||
val timePlayed: Long,
|
||||
@ColumnInfo(name = "play_count")
|
||||
var playCount: Int
|
||||
)
|
|
@ -18,7 +18,7 @@ interface PlaylistDao {
|
|||
suspend fun playlists(): List<PlaylistEntity>
|
||||
|
||||
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId")
|
||||
suspend fun deleteSongsFromPlaylist(playlistId: Int)
|
||||
suspend fun deleteSongsInPlaylist(playlistId: Int)
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM PlaylistEntity")
|
||||
|
@ -43,13 +43,13 @@ interface PlaylistDao {
|
|||
suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>)
|
||||
|
||||
@Delete
|
||||
suspend fun removeSongsFromPlaylist(songs: List<SongEntity>)
|
||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun addSong(historyEntity: HistoryEntity)
|
||||
suspend fun insertSongInHistory(historyEntity: HistoryEntity)
|
||||
|
||||
@Query("SELECT * FROM HistoryEntity WHERE id = :songId LIMIT 1")
|
||||
suspend fun songPresentInHistory(songId: Int): HistoryEntity?
|
||||
suspend fun isSongPresentInHistory(songId: Int): HistoryEntity?
|
||||
|
||||
@Update
|
||||
suspend fun updateHistorySong(historyEntity: HistoryEntity)
|
||||
|
@ -63,4 +63,18 @@ interface PlaylistDao {
|
|||
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
|
||||
fun favoritesSongs(playlistId: Int): List<SongEntity>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
|
||||
@Update
|
||||
fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
|
||||
@Delete
|
||||
fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
|
||||
@Query("SELECT * FROM PlayCountEntity WHERE id =:songId")
|
||||
fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity>
|
||||
|
||||
@Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC")
|
||||
fun playCountSongs(): List<PlayCountEntity>
|
||||
}
|
|
@ -4,8 +4,8 @@ import androidx.room.Database
|
|||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(
|
||||
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class],
|
||||
version = 16,
|
||||
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class],
|
||||
version = 17,
|
||||
exportSchema = false
|
||||
)
|
||||
abstract class RetroDatabase : RoomDatabase() {
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.os.Parcelable
|
|||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
|
@ -37,27 +36,5 @@ class SongEntity(
|
|||
@ColumnInfo(name = "song_key")
|
||||
var songPrimaryKey: Long = 0
|
||||
|
||||
fun toSong(): Song {
|
||||
return Song(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<SongEntity>.toSongs(): List<Song> {
|
||||
return map {
|
||||
it.toSong()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package code.name.monkey.retromusic.db
|
||||
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
|
||||
fun List<SongEntity>.toSongs(): List<Song> {
|
||||
return map {
|
||||
it.toSong()
|
||||
}
|
||||
}
|
||||
|
||||
fun SongEntity.toSong(): Song {
|
||||
return Song(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist
|
||||
)
|
||||
}
|
||||
|
||||
fun PlayCountEntity.toSong(): Song {
|
||||
return Song(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist
|
||||
)
|
||||
}
|
||||
|
||||
fun HistoryEntity.toSong(): Song {
|
||||
return Song(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist
|
||||
)
|
||||
}
|
||||
|
||||
fun Song.toPlayCount(): PlayCountEntity {
|
||||
return PlayCountEntity(
|
||||
id,
|
||||
title,
|
||||
trackNumber,
|
||||
year,
|
||||
duration,
|
||||
data,
|
||||
dateModified,
|
||||
albumId,
|
||||
albumName,
|
||||
artistId,
|
||||
artistName,
|
||||
composer,
|
||||
albumArtist,
|
||||
System.currentTimeMillis(),
|
||||
1
|
||||
)
|
||||
}
|
|
@ -14,7 +14,7 @@ import code.name.monkey.retromusic.extensions.colorButtons
|
|||
import code.name.monkey.retromusic.extensions.extraNotNull
|
||||
import code.name.monkey.retromusic.extensions.materialDialog
|
||||
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||
import code.name.monkey.retromusic.fragments.ReloadType
|
||||
import code.name.monkey.retromusic.fragments.ReloadType.Playlists
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.repository.RealRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -59,7 +59,7 @@ class AddToRetroPlaylist : DialogFragment() {
|
|||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val songEntities = songs.toSongEntity(playlistEntities[which - 1])
|
||||
repository.insertSongs(songEntities)
|
||||
libraryViewModel.forceReload(ReloadType.Playlists)
|
||||
libraryViewModel.forceReload(Playlists)
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
|
|
|
@ -65,7 +65,7 @@ class RemoveSongFromPlaylistDialog : DialogFragment() {
|
|||
.setMessage(pair.second)
|
||||
.setPositiveButton(R.string.remove_action) { _, _ ->
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
repository.removeSongsFromPlaylist(songs)
|
||||
repository.deleteSongsInPlaylist(songs)
|
||||
}
|
||||
/* PlaylistsUtil.removeFromPlaylist(
|
||||
requireContext(),
|
||||
|
|
|
@ -131,6 +131,12 @@ fun MaterialButton.applyColor(color: Int) {
|
|||
iconTint = textColorColorStateList
|
||||
}
|
||||
|
||||
fun MaterialButton.applyOutlineColor(color: Int) {
|
||||
val textColorColorStateList = ColorStateList.valueOf(color)
|
||||
setTextColor(textColorColorStateList)
|
||||
iconTint = textColorColorStateList
|
||||
}
|
||||
|
||||
fun TextInputLayout.accentColor() {
|
||||
val accentColor = ThemeStore.accentColor(context)
|
||||
val colorState = ColorStateList.valueOf(accentColor)
|
||||
|
|
|
@ -12,6 +12,7 @@ import code.name.monkey.retromusic.*
|
|||
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
|
||||
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
|
||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||
import code.name.monkey.retromusic.db.toSong
|
||||
import code.name.monkey.retromusic.fragments.albums.AlbumClickListener
|
||||
import code.name.monkey.retromusic.fragments.artists.ArtistClickListener
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
||||
import code.name.monkey.retromusic.db.toPlayCount
|
||||
import code.name.monkey.retromusic.fragments.ReloadType.*
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
|
||||
|
@ -127,6 +128,14 @@ class LibraryViewModel(
|
|||
} else {
|
||||
repository.addSongToHistory(MusicPlayerRemote.currentSong)
|
||||
}
|
||||
val songs = repository.checkSongExistInPlayCount(MusicPlayerRemote.currentSong.id)
|
||||
if (songs.isNotEmpty()) {
|
||||
repository.updateSongInPlayCount(songs.first().apply {
|
||||
playCount += playCount + 1
|
||||
})
|
||||
} else {
|
||||
repository.insertSongInPlayCount(MusicPlayerRemote.currentSong.toPlayCount())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
|
|||
import code.name.monkey.retromusic.dialogs.AddToRetroPlaylist
|
||||
import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
|
||||
import code.name.monkey.retromusic.extensions.applyColor
|
||||
import code.name.monkey.retromusic.extensions.applyOutlineColor
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
|
||||
import code.name.monkey.retromusic.glide.AlbumGlideRequest
|
||||
|
@ -240,7 +241,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
|||
|
||||
private fun setColors(color: MediaNotificationProcessor) {
|
||||
shuffleAction.applyColor(color.backgroundColor)
|
||||
playAction.applyColor(color.backgroundColor)
|
||||
playAction.applyOutlineColor(color.backgroundColor)
|
||||
}
|
||||
|
||||
override fun onAlbumClick(albumId: Int, view: View) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter
|
|||
import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
|
||||
import code.name.monkey.retromusic.dialogs.AddToRetroPlaylist
|
||||
import code.name.monkey.retromusic.extensions.applyColor
|
||||
import code.name.monkey.retromusic.extensions.applyOutlineColor
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.fragments.albums.AlbumClickListener
|
||||
|
@ -191,7 +192,7 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
|
|||
|
||||
private fun setColors(color: MediaNotificationProcessor) {
|
||||
shuffleAction.applyColor(color.backgroundColor)
|
||||
playAction.applyColor(color.backgroundColor)
|
||||
playAction.applyOutlineColor(color.backgroundColor)
|
||||
}
|
||||
|
||||
override fun onAlbumClick(albumId: Int, view: View) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import code.name.monkey.retromusic.dialogs.*
|
|||
import code.name.monkey.retromusic.extensions.hide
|
||||
import code.name.monkey.retromusic.extensions.whichFragment
|
||||
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||
import code.name.monkey.retromusic.fragments.ReloadType.Playlists
|
||||
import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.interfaces.PaletteColorHolder
|
||||
|
@ -169,6 +170,7 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
|||
repository.removeSongFromPlaylist(songEntity)
|
||||
} else {
|
||||
repository.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
|
||||
libraryViewModel.forceReload(Playlists)
|
||||
}
|
||||
requireContext().sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED))
|
||||
}
|
||||
|
|
|
@ -17,10 +17,7 @@ package code.name.monkey.retromusic.repository
|
|||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.retromusic.db.HistoryEntity
|
||||
import code.name.monkey.retromusic.db.PlaylistEntity
|
||||
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
||||
import code.name.monkey.retromusic.db.SongEntity
|
||||
import code.name.monkey.retromusic.db.*
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.model.smartplaylist.NotPlayedPlaylist
|
||||
import code.name.monkey.retromusic.network.LastFMService
|
||||
|
@ -75,7 +72,7 @@ interface Repository {
|
|||
suspend fun roomPlaylists(): List<PlaylistEntity>
|
||||
suspend fun deleteRoomPlaylist(playlists: List<PlaylistEntity>)
|
||||
suspend fun renameRoomPlaylist(playlistId: Int, name: String)
|
||||
suspend fun removeSongsFromPlaylist(songs: List<SongEntity>)
|
||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||
suspend fun removeSongFromPlaylist(songEntity: SongEntity)
|
||||
suspend fun deleteSongsFromPlaylist(playlists: List<PlaylistEntity>)
|
||||
suspend fun favoritePlaylist(): List<PlaylistEntity>
|
||||
|
@ -86,6 +83,11 @@ interface Repository {
|
|||
suspend fun favoritePlaylistSongs(): List<SongEntity>
|
||||
suspend fun recentSongs(): List<Song>
|
||||
suspend fun topPlayedSongs(): List<Song>
|
||||
suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity>
|
||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||
fun historySong(): LiveData<List<HistoryEntity>>
|
||||
fun favorites(): LiveData<List<SongEntity>>
|
||||
}
|
||||
|
@ -185,13 +187,14 @@ class RealRepository(
|
|||
|
||||
override suspend fun homeSections(): List<Home> {
|
||||
val homeSections = mutableListOf<Home>()
|
||||
val sections = listOf(
|
||||
val sections: List<Home> = listOf(
|
||||
suggestionsHome(),
|
||||
topArtistsHome(),
|
||||
topAlbumsHome(),
|
||||
recentArtistsHome(),
|
||||
recentAlbumsHome(),
|
||||
favoritePlaylistHome()
|
||||
favoritePlaylistHome(),
|
||||
genresHome()
|
||||
)
|
||||
for (section in sections) {
|
||||
if (section.arrayList.isNotEmpty()) {
|
||||
|
@ -231,8 +234,8 @@ class RealRepository(
|
|||
override suspend fun renameRoomPlaylist(playlistId: Int, name: String) =
|
||||
roomRepository.renamePlaylistEntity(playlistId, name)
|
||||
|
||||
override suspend fun removeSongsFromPlaylist(songs: List<SongEntity>) =
|
||||
roomRepository.removeSongsFromPlaylist(songs)
|
||||
override suspend fun deleteSongsInPlaylist(songs: List<SongEntity>) =
|
||||
roomRepository.deleteSongsInPlaylist(songs)
|
||||
|
||||
override suspend fun removeSongFromPlaylist(songEntity: SongEntity) =
|
||||
roomRepository.removeSongFromPlaylist(songEntity)
|
||||
|
@ -263,6 +266,21 @@ class RealRepository(
|
|||
|
||||
override suspend fun topPlayedSongs(): List<Song> = topPlayedRepository.topTracks()
|
||||
|
||||
override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
roomRepository.insertSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
roomRepository.updateSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
roomRepository.deleteSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity> =
|
||||
roomRepository.checkSongExistInPlayCount(songId)
|
||||
|
||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||
roomRepository.playCountSongs()
|
||||
|
||||
override fun historySong(): LiveData<List<HistoryEntity>> =
|
||||
roomRepository.historySongs()
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ interface RoomPlaylistRepository {
|
|||
suspend fun getSongs(playlistEntity: PlaylistEntity): List<SongEntity>
|
||||
suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>)
|
||||
suspend fun renamePlaylistEntity(playlistId: Int, name: String)
|
||||
suspend fun removeSongsFromPlaylist(songs: List<SongEntity>)
|
||||
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
|
||||
suspend fun deleteSongsFromPlaylist(playlists: List<PlaylistEntity>)
|
||||
suspend fun favoritePlaylist(favorite: String): List<PlaylistEntity>
|
||||
suspend fun isFavoriteSong(songEntity: SongEntity): List<SongEntity>
|
||||
|
@ -24,6 +24,11 @@ interface RoomPlaylistRepository {
|
|||
suspend fun songPresentInHistory(song: Song): HistoryEntity?
|
||||
suspend fun updateHistorySong(song: Song)
|
||||
suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity>
|
||||
suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
|
||||
suspend fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity>
|
||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||
fun historySongs(): LiveData<List<HistoryEntity>>
|
||||
fun favoritePlaylistLiveData(favorite: String): LiveData<List<SongEntity>>
|
||||
}
|
||||
|
@ -67,12 +72,12 @@ class RealRoomRepository(
|
|||
override suspend fun renamePlaylistEntity(playlistId: Int, name: String) =
|
||||
playlistDao.renamePlaylistEntity(playlistId, name)
|
||||
|
||||
override suspend fun removeSongsFromPlaylist(songs: List<SongEntity>) =
|
||||
playlistDao.removeSongsFromPlaylist(songs)
|
||||
override suspend fun deleteSongsInPlaylist(songs: List<SongEntity>) =
|
||||
playlistDao.deleteSongsInPlaylist(songs)
|
||||
|
||||
override suspend fun deleteSongsFromPlaylist(playlists: List<PlaylistEntity>) {
|
||||
playlists.forEach {
|
||||
playlistDao.deleteSongsFromPlaylist(it.playListId)
|
||||
playlistDao.deleteSongsInPlaylist(it.playListId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,10 +94,10 @@ class RealRoomRepository(
|
|||
playlistDao.removeSong(songEntity.playlistCreatorId, songEntity.id)
|
||||
|
||||
override suspend fun addSongToHistory(currentSong: Song) =
|
||||
playlistDao.addSong(currentSong.toHistoryEntity(System.currentTimeMillis()))
|
||||
playlistDao.insertSongInHistory(currentSong.toHistoryEntity(System.currentTimeMillis()))
|
||||
|
||||
override suspend fun songPresentInHistory(song: Song): HistoryEntity? =
|
||||
playlistDao.songPresentInHistory(song.id)
|
||||
playlistDao.isSongPresentInHistory(song.id)
|
||||
|
||||
override suspend fun updateHistorySong(song: Song) =
|
||||
playlistDao.updateHistorySong(song.toHistoryEntity(System.currentTimeMillis()))
|
||||
|
@ -106,9 +111,25 @@ class RealRoomRepository(
|
|||
playlistDao.checkPlaylistExists(favorite).first().playListId
|
||||
)
|
||||
|
||||
override suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity> =
|
||||
playlistDao.favoritesSongs(
|
||||
playlistDao.checkPlaylistExists(favorite).first().playListId
|
||||
)
|
||||
override suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity> {
|
||||
return if (playlistDao.checkPlaylistExists(favorite).isNotEmpty())
|
||||
playlistDao.favoritesSongs(
|
||||
playlistDao.checkPlaylistExists(favorite).first().playListId
|
||||
) else emptyList()
|
||||
}
|
||||
|
||||
override suspend fun insertSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
playlistDao.insertSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun updateSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
playlistDao.updateSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun deleteSongInPlayCount(playCountEntity: PlayCountEntity) =
|
||||
playlistDao.deleteSongInPlayCount(playCountEntity)
|
||||
|
||||
override suspend fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity> =
|
||||
playlistDao.checkSongExistInPlayCount(songId)
|
||||
|
||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||
playlistDao.playCountSongs()
|
||||
}
|
|
@ -116,13 +116,13 @@ class RealTopPlayedRepository(
|
|||
|
||||
private fun makeTopTracksCursorImpl(): SortedLongCursor? {
|
||||
// first get the top results ids from the internal database
|
||||
val songs =
|
||||
val cursor =
|
||||
SongPlayCountStore.getInstance(context).getTopPlayedResults(NUMBER_OF_TOP_TRACKS)
|
||||
|
||||
songs.use { localSongs ->
|
||||
cursor.use { songs ->
|
||||
return makeSortedCursor(
|
||||
localSongs,
|
||||
localSongs.getColumnIndex(SongPlayCountStore.SongPlayCountColumns.ID)
|
||||
songs,
|
||||
songs.getColumnIndex(SongPlayCountStore.SongPlayCountColumns.ID)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@
|
|||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/md_white_1000"
|
||||
android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22 0.03 -1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z" />
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM7.07,18.28c0.43,-0.9 3.05,-1.78 4.93,-1.78s4.51,0.88 4.93,1.78C15.57,19.36 13.86,20 12,20s-3.57,-0.64 -4.93,-1.72zM18.36,16.83c-1.43,-1.74 -4.9,-2.33 -6.36,-2.33s-4.93,0.59 -6.36,2.33C4.62,15.49 4,13.82 4,12c0,-4.41 3.59,-8 8,-8s8,3.59 8,8c0,1.82 -0.62,3.49 -1.64,4.83zM12,6c-1.94,0 -3.5,1.56 -3.5,3.5S10.06,13 12,13s3.5,-1.56 3.5,-3.5S13.94,6 12,6zM12,11c-0.83,0 -1.5,-0.67 -1.5,-1.5S11.17,8 12,8s1.5,0.67 1.5,1.5S12.83,11 12,11z" />
|
||||
</vector>
|
|
@ -87,7 +87,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="0dp"
|
||||
android:textAppearance="@style/TextViewHeadline5"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textColor="@color/md_white_1000"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/userImage"
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="0dp"
|
||||
android:textAppearance="@style/TextViewHeadline5"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/userImage"
|
||||
|
|
|
@ -8,14 +8,17 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/playAction"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/action_play_all"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:backgroundTint="?attr/colorSurface"
|
||||
app:icon="@drawable/ic_play_arrow"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/shuffleAction"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -23,14 +26,17 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/shuffleAction"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/shuffle"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:backgroundTint="?attr/colorSurface"
|
||||
app:icon="@drawable/ic_shuffle"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/playAction"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
app:layout_constraintStart_toEndOf="@id/artistImage"
|
||||
app:layout_constraintTop_toTopOf="@id/artistImage"
|
||||
tools:ignore="MissingPrefix"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
tools:text="@tools:sample/full_names" />
|
||||
|
||||
<code.name.monkey.retromusic.views.BaselineGridTextView
|
||||
android:id="@+id/albumText"
|
||||
|
@ -100,7 +100,7 @@
|
|||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textAppearance="@style/TextViewSubtitle1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -108,7 +108,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/albumTitle"
|
||||
app:lineHeightHint="24sp"
|
||||
tools:ignore="MissingPrefix"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
tools:text="@tools:sample/full_names" />
|
||||
|
||||
<include
|
||||
layout="@layout/fragment_album_content"
|
||||
|
|
|
@ -8,13 +8,17 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/playAction"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/action_play_all"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:backgroundTint="?attr/colorSurface"
|
||||
app:icon="@drawable/ic_play_arrow"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/shuffleAction"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -22,13 +26,17 @@
|
|||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/shuffleAction"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:text="@string/shuffle"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:backgroundTint="?attr/colorSurface"
|
||||
app:icon="@drawable/ic_shuffle"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/playAction"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textAppearance="@style/TextViewSubtitle1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="0dp"
|
||||
android:textAppearance="@style/TextViewHeadline5"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textColor="@color/md_white_1000"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/userImage"
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="0dp"
|
||||
android:textAppearance="@style/TextViewHeadline5"
|
||||
android:textAppearance="@style/TextViewHeadline6"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/userImage"
|
||||
|
|
|
@ -28,26 +28,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="3"
|
||||
tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
tools:listitem="@layout/item_album_card" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="112dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/emptyContainer"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -74,5 +54,26 @@
|
|||
android:textAppearance="@style/TextViewNormal"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:overScrollMode="never"
|
||||
tools:itemCount="10"
|
||||
tools:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
tools:listitem="@layout/item_album_card"
|
||||
tools:spanCount="3" />
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="112dp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
|
@ -4,6 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="2dp"
|
||||
android:background="?attr/rectSelector"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
|
Loading…
Reference in a new issue