Skip to content

Commit

Permalink
Fixed #229 Without Proxy, Add "Add to YouTube Liked" feature, Improve…
Browse files Browse the repository at this point in the history
… completed Spotify Canvas
  • Loading branch information
maxrave-dev committed Feb 11, 2024
1 parent 1a142cf commit 070d7dd
Show file tree
Hide file tree
Showing 35 changed files with 1,049 additions and 128 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.7.3")
//Navigation
implementation("androidx.navigation:navigation-fragment-ktx:2.7.6")
implementation("androidx.navigation:navigation-ui-ktx:2.7.6")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")

implementation("com.google.code.gson:gson:2.10.1")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxrave.simpmusic.adapter.album

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.maxrave.simpmusic.data.db.entities.SongEntity
Expand All @@ -9,32 +10,100 @@ import com.maxrave.simpmusic.databinding.ItemAlbumTrackBinding
import com.maxrave.simpmusic.extension.connectArtists
import com.maxrave.simpmusic.extension.toListName
import com.maxrave.simpmusic.extension.toTrack
import com.maxrave.simpmusic.extension.toVideoIdList


class TrackAdapter(private var trackList: ArrayList<Any>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private lateinit var mListener: OnItemClickListener
interface OnItemClickListener{
fun onItemClick(position: Int)
}
fun setOnClickListener(listener: OnItemClickListener){

fun setOnClickListener(listener: OnItemClickListener) {
mListener = listener
}
fun updateList(newList: ArrayList<Any>){

fun updateList(newList: ArrayList<Any>) {
trackList.clear()
trackList.addAll(newList)
notifyDataSetChanged()
}
inner class TrackViewHolder(val binding: ItemAlbumTrackBinding, rootListener: OnItemClickListener): RecyclerView.ViewHolder(binding.root) {

private var downloadedList = arrayListOf<SongEntity>()
private var playingTrackVideoId: String? = null
fun setDownloadedList(downloadedList: ArrayList<SongEntity>?) {
val oldList = arrayListOf<SongEntity>()
oldList.addAll(this.downloadedList)
this.downloadedList = downloadedList ?: arrayListOf()
trackList.mapIndexed { index, result ->
if (result is Track || result is SongEntity) {
val videoId = when (result) {
is Track -> result.videoId
is SongEntity -> result.videoId
else -> null
}
if (downloadedList != null) {
if (downloadedList.toVideoIdList().contains(videoId) && !oldList.toVideoIdList()
.contains(videoId)
) {
notifyItemChanged(index)
} else if (!downloadedList.toVideoIdList()
.contains(videoId) && oldList.toVideoIdList().contains(videoId)
) {
notifyItemChanged(index)
}
}
}
}
}

fun setNowPlaying(it: String?) {
val oldPlayingTrackVideoId = playingTrackVideoId
playingTrackVideoId = it
trackList.mapIndexed { index, result ->
if (result is Track || result is SongEntity) {
val videoId = when (result) {
is Track -> result.videoId
is SongEntity -> result.videoId
else -> null
}
if (videoId == playingTrackVideoId) {
notifyItemChanged(index)
} else if (videoId == oldPlayingTrackVideoId) {
notifyItemChanged(index)
}

}
}
}

inner class TrackViewHolder(
val binding: ItemAlbumTrackBinding,
rootListener: OnItemClickListener
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.rootLayout.setOnClickListener {
rootListener.onItemClick(bindingAdapterPosition)
}
}
fun bind(track: Track){
with(binding){

fun bind(track: Track) {
with(binding) {
tvSongName.text = track.title
tvArtistName.text = track.artists.toListName().connectArtists()
tvPosition.text = (bindingAdapterPosition + 1).toString()
if (downloadedList.toVideoIdList().contains(track.videoId)) {
ivDownloaded.visibility = View.VISIBLE
} else {
ivDownloaded.visibility = View.GONE
}
if (track.videoId == playingTrackVideoId) {
ivPlaying.visibility = View.VISIBLE
tvPosition.visibility = View.GONE
} else {
ivPlaying.visibility = View.GONE
tvPosition.visibility = View.VISIBLE
}
}
}
}
Expand All @@ -49,6 +118,18 @@ class TrackAdapter(private var trackList: ArrayList<Any>): RecyclerView.Adapter<
tvSongName.text = songEntity.title
tvArtistName.text = songEntity.artistName?.connectArtists()
tvPosition.text = (bindingAdapterPosition + 1).toString()
if (downloadedList.toVideoIdList().contains(songEntity.videoId)) {
ivDownloaded.visibility = View.VISIBLE
} else {
ivDownloaded.visibility = View.GONE
}
if (songEntity.videoId == playingTrackVideoId) {
ivPlaying.visibility = View.VISIBLE
tvPosition.visibility = View.GONE
} else {
ivPlaying.visibility = View.GONE
tvPosition.visibility = View.VISIBLE
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.maxrave.simpmusic.adapter.artist

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.maxrave.simpmusic.data.db.entities.SongEntity
import com.maxrave.simpmusic.data.model.browse.artist.ResultSong
import com.maxrave.simpmusic.databinding.ItemPopularSongBinding
import com.maxrave.simpmusic.extension.connectArtists
import com.maxrave.simpmusic.extension.toListName
import com.maxrave.simpmusic.extension.toVideoIdList

class PopularAdapter(private var popularList: ArrayList<ResultSong>): RecyclerView.Adapter<PopularAdapter.ViewHolder>() {
private lateinit var mListener: OnItemClickListener
Expand All @@ -19,17 +22,60 @@ class PopularAdapter(private var popularList: ArrayList<ResultSong>): RecyclerVi
fun onOptionsClick(position: Int)
}

fun setOnClickListener(listener: OnItemClickListener){
fun setOnClickListener(listener: OnItemClickListener) {
mListener = listener
}
fun setOnOptionsClickListener(listener: OnOptionsClickListener){

fun setOnOptionsClickListener(listener: OnOptionsClickListener) {
mOptionsListener = listener
}

fun getCurrentList(): ArrayList<ResultSong> {
return popularList
}

inner class ViewHolder(val binding: ItemPopularSongBinding, listener: OnItemClickListener, optionListener: OnOptionsClickListener): RecyclerView.ViewHolder(binding.root) {
private var downloadedList = arrayListOf<SongEntity>()
private var playingTrackVideoId: String? = null

fun setDownloadedList(downloadedList: ArrayList<SongEntity>?) {
val oldList = arrayListOf<SongEntity>()
oldList.addAll(this.downloadedList)
this.downloadedList = downloadedList ?: arrayListOf()
popularList.mapIndexed { index, result ->
val videoId = result.videoId
if (downloadedList != null) {
if (downloadedList.toVideoIdList().contains(videoId) && !oldList.toVideoIdList()
.contains(videoId)
) {
notifyItemChanged(index)
} else if (!downloadedList.toVideoIdList()
.contains(videoId) && oldList.toVideoIdList().contains(videoId)
) {
notifyItemChanged(index)
}
}
}
}

fun setNowPlaying(it: String?) {
val oldPlayingTrackVideoId = playingTrackVideoId
playingTrackVideoId = it
popularList.mapIndexed { index, result ->
val videoId = result.videoId
if (videoId == playingTrackVideoId) {
notifyItemChanged(index)
} else if (videoId == oldPlayingTrackVideoId) {
notifyItemChanged(index)
}
}
}


inner class ViewHolder(
val binding: ItemPopularSongBinding,
listener: OnItemClickListener,
optionListener: OnOptionsClickListener
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener {
listener.onItemClick(bindingAdapterPosition)
Expand Down Expand Up @@ -65,6 +111,18 @@ class PopularAdapter(private var popularList: ArrayList<ResultSong>): RecyclerVi
crossfade(true)
placeholder(com.maxrave.simpmusic.R.drawable.holder)
}
if (downloadedList.toVideoIdList().contains(song.videoId)) {
ivDownloaded.visibility = View.VISIBLE
} else {
ivDownloaded.visibility = View.GONE
}
if (playingTrackVideoId == song.videoId) {
ivPlaying.visibility = View.VISIBLE
ivThumbnail.visibility = View.GONE
} else {
ivPlaying.visibility = View.GONE
ivThumbnail.visibility = View.VISIBLE
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.maxrave.simpmusic.adapter.playlist

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.maxrave.simpmusic.data.db.entities.LocalPlaylistEntity
import com.maxrave.simpmusic.databinding.ItemLocalPlaylistBinding
import com.maxrave.simpmusic.extension.setEnabledAll

class AddToAPlaylistAdapter(private val list: ArrayList<LocalPlaylistEntity>): RecyclerView.Adapter<AddToAPlaylistAdapter.ViewHolder>() {

lateinit var mListener: OnItemClickListener

private var videoId: String? = null

interface OnItemClickListener {
fun onItemClick(position: Int)
}
Expand All @@ -18,7 +22,25 @@ class AddToAPlaylistAdapter(private val list: ArrayList<LocalPlaylistEntity>): R
mListener = listener
}

inner class ViewHolder(val binding: ItemLocalPlaylistBinding, val listener: OnItemClickListener): RecyclerView.ViewHolder(binding.root) {
fun setVideoId(videoId: String) {
val oldVideoId = videoId
this.videoId = videoId
list.forEach { playlist ->
if (playlist.tracks?.contains(videoId) == true && !playlist.tracks.contains(oldVideoId)) {
notifyItemChanged(list.indexOf(playlist))
} else if (playlist.tracks?.contains(oldVideoId) == true && !playlist.tracks.contains(
videoId
)
) {
notifyItemChanged(list.indexOf(playlist))
}
}
}

inner class ViewHolder(
val binding: ItemLocalPlaylistBinding,
val listener: OnItemClickListener
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener {
listener.onItemClick(bindingAdapterPosition)
Expand All @@ -27,6 +49,13 @@ class AddToAPlaylistAdapter(private val list: ArrayList<LocalPlaylistEntity>): R

fun bind(item: LocalPlaylistEntity) {
binding.tvLocalPlaylistTitle.text = item.title
if (item.tracks?.contains(videoId) == true) {
binding.ivAdded.visibility = View.VISIBLE
setEnabledAll(binding.root, false)
} else {
binding.ivAdded.visibility = View.GONE
setEnabledAll(binding.root, true)
}
}
}

Expand Down
Loading

0 comments on commit 070d7dd

Please sign in to comment.