Skip to content

Commit

Permalink
Remove Coil, Fix long press home item, Add Click event to Library Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Nov 27, 2024
1 parent 581bd3c commit a92c926
Show file tree
Hide file tree
Showing 57 changed files with 937 additions and 364 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ dependencies {
implementation(libs.gson)

// Coil
implementation(libs.coil)
implementation(libs.coil.compose)
implementation(libs.coil.network.okhttp)
implementation(libs.kmpalette.core)
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/SimpMusicApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import cat.ereza.customactivityoncrash.config.CaocConfig
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import coil3.network.okhttp.OkHttpNetworkFetcherFactory
import coil3.request.CachePolicy
import coil3.request.crossfade
import coil3.util.DebugLogger
Expand All @@ -16,6 +17,7 @@ import com.maxrave.simpmusic.di.mediaServiceModule
import com.maxrave.simpmusic.di.viewModelModule
import com.maxrave.simpmusic.ui.MainActivity
import com.maxrave.simpmusic.ui.theme.newDiskCache
import okhttp3.OkHttpClient
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.workmanager.koin.workManagerFactory
Expand All @@ -29,6 +31,15 @@ class SimpMusicApplication :

override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(context)
.components {
add(
OkHttpNetworkFetcherFactory(
callFactory = {
OkHttpClient()
}
)
)
}
.logger(DebugLogger())
.diskCachePolicy(CachePolicy.ENABLED).networkCachePolicy(CachePolicy.ENABLED)
.diskCache(newDiskCache())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.account
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.data.db.entities.GoogleAccountEntity
import com.maxrave.simpmusic.databinding.ItemAccountBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.artist
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.artist.ResultAlbum
import com.maxrave.simpmusic.databinding.ItemSinglesBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.artist
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.artist.ResultPlaylist
import com.maxrave.simpmusic.databinding.ItemSinglesBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.kotlinytmusicscraper.models.AlbumItem
import com.maxrave.kotlinytmusicscraper.models.YTItem
import com.maxrave.simpmusic.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.data.db.entities.SongEntity
import com.maxrave.simpmusic.data.model.browse.artist.ResultSong
import com.maxrave.simpmusic.databinding.ItemPopularSongBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.artist.ResultRelated
import com.maxrave.simpmusic.databinding.ItemRelatedArtistBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.artist
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.artist.ResultSingle
import com.maxrave.simpmusic.databinding.ItemSinglesBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.artist
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.artist.ResultVideo
import com.maxrave.simpmusic.databinding.ItemVideoBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.DownloadState
import com.maxrave.simpmusic.data.db.entities.AlbumEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.maxrave.simpmusic.adapter.moodandgenre.mood
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.data.model.explore.mood.moodmoments.Content
import com.maxrave.simpmusic.databinding.ItemHomeContentPlaylistBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import coil.ImageLoader
import coil.request.ImageRequest
import coil3.load
import coil3.request.CachePolicy
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.db.entities.SongEntity
import com.maxrave.simpmusic.data.model.browse.album.Track
Expand Down Expand Up @@ -97,7 +98,12 @@ class PlaylistItemAdapter(private var playlistItemList: ArrayList<Any>): Recycle
fun bind (track: Track) {
binding.tvSongTitle.text = track.title
binding.tvSongArtist.text = track.artists.toListName().connectArtists()
binding.ivThumbnail.load(track.thumbnails?.last()?.url)
binding.ivThumbnail.load(track.thumbnails?.last()?.url) {
placeholder(R.drawable.holder)
crossfade(true)
diskCachePolicy(CachePolicy.ENABLED)
diskCacheKey(track.thumbnails?.last()?.url)
}
binding.tvSongTitle.isSelected = true
binding.tvSongArtist.isSelected = true
if (downloadedList.contains(track.videoId)) {
Expand Down Expand Up @@ -128,7 +134,12 @@ class PlaylistItemAdapter(private var playlistItemList: ArrayList<Any>): Recycle
binding.tvSongArtist.text = song.artistName?.connectArtists()
binding.tvSongTitle.isSelected = true
binding.tvSongArtist.isSelected = true
binding.ivThumbnail.load(song.thumbnails)
binding.ivThumbnail.load(song.thumbnails) {
placeholder(R.drawable.holder)
crossfade(true)
diskCachePolicy(CachePolicy.ENABLED)
diskCacheKey(song.thumbnails)
}
if (downloadedList.contains(song.videoId)) {
binding.ivDownloaded.visibility = View.VISIBLE
} else {
Expand Down Expand Up @@ -189,20 +200,6 @@ class PlaylistItemAdapter(private var playlistItemList: ArrayList<Any>): Recycle
private const val VIEW_TYPE_LOCAL_PLAYLIST_TRACK = 1
}

fun ImageView.load(url: String?) {
if (url != null) {
ImageLoader(context).enqueue(
ImageRequest.Builder(context)
.placeholder(R.drawable.holder)
.crossfade(true)
.data(url)
.diskCacheKey(url)
.target(this)
.build()
)
}
}

fun setLikedTrack(position: Int, like: Boolean) {
if (playlistItemList[position] is SongEntity) {
val track = playlistItemList[position] as SongEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.model.browse.album.Track
import com.maxrave.simpmusic.databinding.ItemSuggestItemYoutubePlaylistBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.data.model.podcast.PodcastBrowse
import com.maxrave.simpmusic.databinding.ItemPodcastBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config.ALBUM_CLICK
import com.maxrave.simpmusic.common.Config.PLAYLIST_CLICK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.kotlinytmusicscraper.models.AlbumItem
import com.maxrave.kotlinytmusicscraper.models.ArtistItem
import com.maxrave.kotlinytmusicscraper.models.PlaylistItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ data class AlbumEntity (
val downloadState: Int = DownloadState.STATE_NOT_DOWNLOADED,
): PlaylistType, RecentlyType {
override fun objectType(): RecentlyType.Type = RecentlyType.Type.ALBUM
override fun playlistType(): PlaylistType.Type = PlaylistType.Type.ALBUM
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class LocalPlaylistEntity(
// Only synced with YouTube playlist
// val listSetVideoId: List<String>? = null,
): PlaylistType, HomeContentType {
override fun playlistType(): PlaylistType.Type = PlaylistType.Type.LOCAL
object YouTubeSyncState {
const val NotSynced = 0
const val Syncing = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ data class PlaylistEntity (
val inLibrary: LocalDateTime = LocalDateTime.now(),
val downloadState: Int = DownloadState.STATE_NOT_DOWNLOADED,
): PlaylistType, RecentlyType {
override fun playlistType(): PlaylistType.Type =
if (id.startsWith("RDEM") || id.startsWith("RDAMVM") || id.startsWith("RDAT"))
PlaylistType.Type.RADIO
else PlaylistType.Type.YOUTUBE_PLAYLIST
override fun objectType(): RecentlyType.Type = RecentlyType.Type.PLAYLIST
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class LocalPlaylistManager(
localDataSource.deleteLocalPlaylist(id)
}

suspend fun updateTitleLocalPlaylist(
fun updateTitleLocalPlaylist(
id: Long,
newTitle: String,
): Flow<LocalResource<String>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ data class PlaylistsResult(
val thumbnails: List<Thumbnail>,
@SerializedName("title")
val title: String
): PlaylistType
): PlaylistType {
override fun playlistType(): PlaylistType.Type =
if (browseId.startsWith("RDEM") || browseId.startsWith("RDAMVM") || browseId.startsWith("RDAT"))
PlaylistType.Type.RADIO
else PlaylistType.Type.YOUTUBE_PLAYLIST
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,26 @@ fun parsePlaylistData(
?.get(0)
?.navigationEndpoint
?.browseEndpoint
?.browseId ?: "",
?.browseId ?:
header.facepile
?.avatarStackViewModel
?.rendererContext
?.commandContext
?.onTap
?.innertubeCommand
?.browseEndpoint
?.browseId
?: "",
name =
header.straplineTextOne
?.runs
?.get(0)
?.text ?: "",
?.text ?:
header.facepile
?.avatarStackViewModel
?.text
?.content
?: "",
)
listAuthor.add(author)
Log.d("PlaylistParser", "author: $author")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ interface LibraryType
* HomeContentType is used in Home screen, btw PlaylistType also used in Home screen, but PlaylistType is specific type for Playlist only
* In Library Screen, I reused Home Content Composable, so the PlaylistType is inherited from HomeContentType
*/
interface PlaylistType: HomeContentType, LibraryType
interface PlaylistType: HomeContentType, LibraryType {
enum class Type {
YOUTUBE_PLAYLIST,
RADIO,
LOCAL,
ALBUM
}
fun playlistType(): Type
}
interface RecentlyType: LibraryType {
enum class Type {
SONG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import android.view.ViewGroup
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil3.load
import coil3.request.crossfade
import coil3.request.placeholder
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.data.db.entities.AlbumEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.session.CommandButton
import androidx.media3.session.SessionCommand
import coil.ImageLoader
import coil.request.ImageRequest
import coil3.imageLoader
import coil3.request.ImageRequest
import coil3.request.placeholder
import coil3.toBitmap
import com.maxrave.kotlinytmusicscraper.models.sponsorblock.SkipSegments
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.ASC
Expand Down Expand Up @@ -328,7 +330,9 @@ class SimpleMediaServiceHandler(
_controlState.update { it.copy(isLiked = false) }
mainRepository.insertSong(
track?.toSongEntity() ?: mediaItem.toSongEntity()!!,
)
).singleOrNull()?.let {
Log.w(TAG, "getDataOfNowPlayingState: $it")
}
}
Log.w(TAG, "getDataOfNowPlayingState: $songEntity")
Log.w(TAG, "getDataOfNowPlayingState: $track")
Expand Down Expand Up @@ -1199,7 +1203,7 @@ class SimpleMediaServiceHandler(
}
},
).build()
ImageLoader(context).execute(imageRequest)
context.imageLoader.execute(imageRequest)
}
}

Expand Down
Loading

0 comments on commit a92c926

Please sign in to comment.