Code refactor

main
Hemanth S 2020-08-23 13:31:42 +05:30
parent 543893adba
commit cee4565c34
35 changed files with 107 additions and 43 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -1,6 +1,10 @@
package code.name.monkey.retromusic
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import code.name.monkey.retromusic.db.BlackListStoreEntity
import code.name.monkey.retromusic.db.PlaylistDao
import code.name.monkey.retromusic.db.PlaylistWithSongs
import code.name.monkey.retromusic.db.RetroDatabase
import code.name.monkey.retromusic.fragments.LibraryViewModel
@ -12,15 +16,30 @@ import code.name.monkey.retromusic.fragments.search.SearchViewModel
import code.name.monkey.retromusic.model.Genre
import code.name.monkey.retromusic.network.networkModule
import code.name.monkey.retromusic.repository.*
import code.name.monkey.retromusic.util.FilePathUtil
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.bind
import org.koin.dsl.module
private val roomModule = module {
single {
Room.databaseBuilder(androidContext(), RetroDatabase::class.java, "playlist.db")
.allowMainThreadQueries()
.addCallback(object : RoomDatabase.Callback() {
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
GlobalScope.launch(IO) {
FilePathUtil.blacklistFilePaths().map {
get<PlaylistDao>().insertBlacklistPath(BlackListStoreEntity(it))
}
}
}
})
.fallbackToDestructiveMigration()
.build()
}

View File

@ -3,7 +3,6 @@ package code.name.monkey.retromusic.adapter.album
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.retromusic.fragments.albums.AlbumClickListener
import code.name.monkey.retromusic.glide.AlbumGlideRequest
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
@ -30,8 +29,8 @@ class HorizontalAlbumAdapter(
}
override fun setColors(color: MediaNotificationProcessor, holder: ViewHolder) {
holder.title?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorPrimary))
holder.text?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorSecondary))
//holder.title?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorPrimary))
//holder.text?.setTextColor(ATHUtil.resolveColor(activity, android.R.attr.textColorSecondary))
}
override fun loadAlbumCover(album: Album, holder: ViewHolder) {

View File

@ -0,0 +1,10 @@
package code.name.monkey.retromusic.db
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity
class BlackListStoreEntity(
@PrimaryKey
val path: String
)

View File

@ -9,10 +9,10 @@ interface PlaylistDao {
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
@Query("UPDATE PlaylistEntity SET playlist_name = :name WHERE playlist_id = :playlistId")
suspend fun renamePlaylistEntity(playlistId: Int, name: String)
suspend fun renamePlaylist(playlistId: Int, name: String)
@Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name")
fun checkPlaylistExists(name: String): List<PlaylistEntity>
fun isPlaylistExists(name: String): List<PlaylistEntity>
@Query("SELECT * FROM PlaylistEntity")
suspend fun playlists(): List<PlaylistEntity>
@ -20,27 +20,27 @@ interface PlaylistDao {
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId")
suspend fun deleteSongsInPlaylist(playlistId: Int)
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
suspend fun removeSongFromPlaylist(playlistId: Int, songId: Int)
@Transaction
@Query("SELECT * FROM PlaylistEntity")
suspend fun playlistsWithSong(): List<PlaylistWithSongs>
suspend fun playlistsWithSongs(): List<PlaylistWithSongs>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSongs(songEntities: List<SongEntity>)
suspend fun insertSongsToPlaylist(songEntities: List<SongEntity>)
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
suspend fun checkSongExistsWithPlaylistId(playlistId: Int, songId: Int): List<SongEntity>
suspend fun isSongExistsInPlaylist(playlistId: Int, songId: Int): List<SongEntity>
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId")
suspend fun getSongs(playlistId: Int): List<SongEntity>
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
fun removeSong(playlistId: Int, songId: Int)
suspend fun songsFromPlaylist(playlistId: Int): List<SongEntity>
@Delete
suspend fun deletePlaylistEntity(playlistEntity: PlaylistEntity)
suspend fun deletePlaylist(playlistEntity: PlaylistEntity)
@Delete
suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>)
suspend fun deletePlaylists(playlistEntities: List<PlaylistEntity>)
@Delete
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
@ -77,4 +77,16 @@ interface PlaylistDao {
@Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC")
fun playCountSongs(): List<PlayCountEntity>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertBlacklistPath(blackListStoreEntity: BlackListStoreEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertBlacklistPath(blackListStoreEntities: List<BlackListStoreEntity>)
@Delete
suspend fun deleteBlacklistPath(blackListStoreEntity: BlackListStoreEntity)
@Query("DELETE FROM BlackListStoreEntity")
suspend fun clearBlacklist()
}

View File

@ -4,8 +4,8 @@ import androidx.room.Database
import androidx.room.RoomDatabase
@Database(
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class],
version = 17,
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class],
version = 18,
exportSchema = false
)
abstract class RetroDatabase : RoomDatabase() {

View File

@ -3,7 +3,6 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import code.name.monkey.retromusic.EXTRA_PLAYLISTS
import code.name.monkey.retromusic.EXTRA_SONG
@ -17,12 +16,13 @@ import code.name.monkey.retromusic.fragments.LibraryViewModel
import code.name.monkey.retromusic.fragments.ReloadType.Playlists
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.repository.RealRepository
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
class AddToRetroPlaylist : DialogFragment() {
class AddToRetroPlaylist : BottomSheetDialogFragment() {
private val repository by inject<RealRepository>()
private val libraryViewModel by sharedViewModel<LibraryViewModel>()

View File

@ -4,12 +4,12 @@ import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import androidx.lifecycle.Observer
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.recyclerview.widget.GridLayoutManager
import code.name.monkey.retromusic.EXTRA_ALBUM_ID
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
import code.name.monkey.retromusic.extensions.findActivityNavController
import code.name.monkey.retromusic.fragments.ReloadType
import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.util.PreferenceUtil
@ -95,8 +95,7 @@ class AlbumsFragment :
}
override fun onAlbumClick(albumId: Int, view: View) {
val controller = requireActivity().findNavController(R.id.fragment_container)
controller.navigate(
findActivityNavController(R.id.fragment_container).navigate(
R.id.albumDetailsFragment,
bundleOf(EXTRA_ALBUM_ID to albumId),
null,

View File

@ -73,7 +73,6 @@ class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_d
setupRecyclerView()
postponeEnterTransition()
detailsViewModel.getArtist().observe(viewLifecycleOwner, Observer {
showArtist(it)
startPostponedEnterTransition()
})

View File

@ -21,7 +21,7 @@ import code.name.monkey.retromusic.R
object HorizontalAdapterHelper {
const val LAYOUT_RES = R.layout.item_image
const val LAYOUT_RES = R.layout.item_album_card
private const val TYPE_FIRST = 1
private const val TYPE_MIDDLE = 2

View File

@ -35,6 +35,8 @@ import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
import androidx.core.content.res.ResourcesCompat;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@ -510,6 +512,7 @@ public class LrcView extends View {
if (i > 0) {
y += ((mLrcEntryList.get(i - 1).getHeight() + mLrcEntryList.get(i).getHeight()) >> 1) + mDividerHeight;
}
mLrcPaint.setTypeface(ResourcesCompat.getFont(getContext(), R.font.sans));
if (i == mCurrentLine) {
mLrcPaint.setTextSize(mCurrentTextSize);
mLrcPaint.setColor(mCurrentTextColor);

View File

@ -240,7 +240,6 @@ class RealRepository(
override suspend fun removeSongFromPlaylist(songEntity: SongEntity) =
roomRepository.removeSongFromPlaylist(songEntity)
override suspend fun deleteSongsFromPlaylist(playlists: List<PlaylistEntity>) =
roomRepository.deleteSongsFromPlaylist(playlists)

View File

@ -42,14 +42,14 @@ class RealRoomRepository(
@WorkerThread
override suspend fun checkPlaylistExists(playlistName: String): List<PlaylistEntity> =
playlistDao.checkPlaylistExists(playlistName)
playlistDao.isPlaylistExists(playlistName)
@WorkerThread
override suspend fun playlists(): List<PlaylistEntity> = playlistDao.playlists()
@WorkerThread
override suspend fun playlistWithSongs(): List<PlaylistWithSongs> =
playlistDao.playlistsWithSong()
playlistDao.playlistsWithSongs()
@WorkerThread
override suspend fun insertSongs(songs: List<SongEntity>) {
@ -59,18 +59,18 @@ class RealRoomRepository(
}.first()
println("Existing ${existingSongs.size}")
tempList.removeAll(existingSongs)*/
playlistDao.insertSongs(songs)
playlistDao.insertSongsToPlaylist(songs)
}
override suspend fun getSongs(playlistEntity: PlaylistEntity): List<SongEntity> {
return playlistDao.getSongs(playlistEntity.playListId)
return playlistDao.songsFromPlaylist(playlistEntity.playListId)
}
override suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>) =
playlistDao.deletePlaylistEntities(playlistEntities)
playlistDao.deletePlaylists(playlistEntities)
override suspend fun renamePlaylistEntity(playlistId: Int, name: String) =
playlistDao.renamePlaylistEntity(playlistId, name)
playlistDao.renamePlaylist(playlistId, name)
override suspend fun deleteSongsInPlaylist(songs: List<SongEntity>) =
playlistDao.deleteSongsInPlaylist(songs)
@ -82,16 +82,16 @@ class RealRoomRepository(
}
override suspend fun favoritePlaylist(favorite: String): List<PlaylistEntity> =
playlistDao.checkPlaylistExists(favorite)
playlistDao.isPlaylistExists(favorite)
override suspend fun isFavoriteSong(songEntity: SongEntity): List<SongEntity> =
playlistDao.checkSongExistsWithPlaylistId(
playlistDao.isSongExistsInPlaylist(
songEntity.playlistCreatorId,
songEntity.id
)
override suspend fun removeSongFromPlaylist(songEntity: SongEntity) =
playlistDao.removeSong(songEntity.playlistCreatorId, songEntity.id)
playlistDao.removeSongFromPlaylist(songEntity.playlistCreatorId, songEntity.id)
override suspend fun addSongToHistory(currentSong: Song) =
playlistDao.insertSongInHistory(currentSong.toHistoryEntity(System.currentTimeMillis()))
@ -108,13 +108,13 @@ class RealRoomRepository(
override fun favoritePlaylistLiveData(favorite: String): LiveData<List<SongEntity>> =
playlistDao.favoritesSongsLiveData(
playlistDao.checkPlaylistExists(favorite).first().playListId
playlistDao.isPlaylistExists(favorite).first().playListId
)
override suspend fun favoritePlaylistSongs(favorite: String): List<SongEntity> {
return if (playlistDao.checkPlaylistExists(favorite).isNotEmpty())
return if (playlistDao.isPlaylistExists(favorite).isNotEmpty())
playlistDao.favoritesSongs(
playlistDao.checkPlaylistExists(favorite).first().playListId
playlistDao.isPlaylistExists(favorite).first().playListId
) else emptyList()
}

View File

@ -0,0 +1,16 @@
package code.name.monkey.retromusic.util
import android.os.Environment
import java.io.File
object FilePathUtil {
fun blacklistFilePaths(): List<String> {
return listOf<File>(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES),
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS)
).map {
FileUtil.safeGetCanonicalPath(it)
}
}
}

View File

@ -12,10 +12,10 @@
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
app:lrcLabel="@string/no_lyrics_found"
app:lrcNormalTextSize="32sp"
app:lrcPadding="16dp"
app:lrcNormalTextSize="24sp"
app:lrcPadding="24dp"
app:lrcTextGravity="left"
app:lrcTextSize="32sp" />
app:lrcTextSize="28sp" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/appBarLayout"

View File

@ -83,7 +83,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:maxLines="3"
android:textAppearance="@style/TextViewHeadline4"
android:textAppearance="@style/TextViewHeadline4.Compress"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
app:layout_constrainedWidth="true"

View File

@ -14,9 +14,9 @@
<FrameLayout
android:id="@+id/slidingPanel"
style="@style/Widget.BottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="code.name.monkey.retromusic.RetroBottomSheetBehavior">

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -236,4 +236,12 @@
<item name="android:paddingTop">@dimen/button_padding_vertical</item>
<item name="android:paddingBottom">@dimen/button_padding_vertical</item>
</style>
<style name="Widget.BottomSheet" parent="Widget.MaterialComponents.BottomSheet">
</style>
</resources>