Skip to content

Commit

Permalink
Fix dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Jul 28, 2023
1 parent 85c6492 commit 365e670
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 212 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {

dependencies {

def youtube_extractor_version = '0.0.7'
implementation ("com.github.maxrave-dev:kotlin-youtubeExtractor:$youtube_extractor_version") {changing = true}
// def youtube_extractor_version = '0.0.7'
// implementation ("com.github.maxrave-dev:kotlin-youtubeExtractor:$youtube_extractor_version") {changing = true}

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.core:core-ktx:1.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ package com.maxrave.simpmusic.adapter.home

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.data.model.browse.album.Track
import com.maxrave.simpmusic.data.model.home.Content
import com.maxrave.simpmusic.data.model.home.homeItem
import com.maxrave.simpmusic.data.queue.Queue
import com.maxrave.simpmusic.databinding.ItemHomeBinding
import com.maxrave.simpmusic.extension.toTrack

class HomeItemAdapter(private var homeItemList: ArrayList<homeItem>, var context: Context, val navController: NavController): RecyclerView.Adapter<HomeItemAdapter.ViewHolder>() {
inner class ViewHolder(var binding: ItemHomeBinding) : RecyclerView.ViewHolder(binding.root) {
Expand Down Expand Up @@ -45,20 +51,30 @@ class HomeItemAdapter(private var homeItemList: ArrayList<homeItem>, var context
}
itemAdapter.setOnSongClickListener(object : HomeItemContentAdapter.onSongItemClickListener{
override fun onSongItemClick(position: Int) {
Toast.makeText(context, homeItemList[holder.bindingAdapterPosition].contents[position].toString(), Toast.LENGTH_SHORT).show()
val args = Bundle()
args.putString("videoId", homeItemList[holder.bindingAdapterPosition].contents[position]?.videoId)
args.putString("from", homeItem.title)
Queue.clear()
Log.d("HomeItemAdapter", "onSongItemClick: ${homeItemList[holder.bindingAdapterPosition].contents[position]}")
val firstQueue: Track = homeItemList[holder.bindingAdapterPosition].contents[position]!!.toTrack()
Queue.setNowPlaying(firstQueue)
args.putString("type", Config.SONG_CLICK)
navController.navigate(R.id.action_global_nowPlayingFragment, args)
}
})
itemAdapter.setOnPlaylistClickListener(object : HomeItemContentAdapter.onPlaylistItemClickListener{
override fun onPlaylistItemClick(position: Int) {
Toast.makeText(context, homeItemList[position].toString(), Toast.LENGTH_SHORT).show()
val args = Bundle()
args.putString("id", homeItemList[holder.bindingAdapterPosition].contents[position]?.playlistId)
navController.navigate(R.id.action_global_playlistFragment, args)
}
})
itemAdapter.setOnAlbumClickListener(object : HomeItemContentAdapter.onAlbumItemClickListener{
override fun onAlbumItemClick(position: Int) {
val args = Bundle()
args.putString("browseId", homeItemList[holder.bindingAdapterPosition].contents[position]?.browseId)
navController.navigate(R.id.action_global_albumFragment, args)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@ package com.maxrave.simpmusic.adapter.home

import android.util.Log
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.model.home.Content
import com.maxrave.simpmusic.databinding.ItemHomeContentPlaylistBinding
import com.maxrave.simpmusic.databinding.ItemHomeContentSongBinding
import com.maxrave.simpmusic.extension.connectArtists
import com.maxrave.simpmusic.extension.toListName

class HomeItemContentAdapter(private var listContent: ArrayList<Content>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private lateinit var mPlaylistListener: onPlaylistItemClickListener
private lateinit var mAlbumListener: onAlbumItemClickListener
private lateinit var mSongListener: onSongItemClickListener
interface onSongItemClickListener{
fun onSongItemClick(position: Int)
}
interface onPlaylistItemClickListener{
fun onPlaylistItemClick(position: Int)
}
interface onAlbumItemClickListener{
fun onAlbumItemClick(position: Int)
}
fun setOnSongClickListener(listener: onSongItemClickListener){
mSongListener = listener
}
fun setOnPlaylistClickListener(listener: onPlaylistItemClickListener){
mPlaylistListener = listener
}
fun setOnAlbumClickListener(listener: onAlbumItemClickListener){
mAlbumListener = listener
}
inner class SongViewHolder(var binding: ItemHomeContentSongBinding, var listener: onSongItemClickListener): RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener {listener.onSongItemClick(bindingAdapterPosition)}
Expand All @@ -38,15 +48,7 @@ class HomeItemContentAdapter(private var listContent: ArrayList<Content>): Recyc
}
tvSongName.text = content.title
tvSongName.isSelected = true
var artistName = ""
if (content.artists != null) {
for (artist in content.artists) {
artistName += artist.name + ", "
}
artistName = removeTrailingComma(artistName)
artistName = removeComma(artistName)
}
tvArtistName.text = artistName
tvArtistName.text = content.artists.toListName().connectArtists()
tvArtistName.isSelected = true
tvAlbumName.text = content.album?.name
tvAlbumName.isSelected = true
Expand All @@ -72,12 +74,31 @@ class HomeItemContentAdapter(private var listContent: ArrayList<Content>): Recyc
}
}
}
inner class AlbumViewHolder(var binding: ItemHomeContentPlaylistBinding, var listener: onAlbumItemClickListener): RecyclerView.ViewHolder(binding.root){
init {
binding.root.setOnClickListener {listener.onAlbumItemClick(bindingAdapterPosition)}
}
fun bind(content: Content){
with(binding){
if (content.thumbnails.size > 1) {
ivArt.load(content.thumbnails[1].url)
}
else{
ivArt.load(content.thumbnails[0].url)
}
tvTitle.text = content.title
tvTitle.isSelected = true
tvDescription.visibility = View.GONE
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val inflate = LayoutInflater.from(parent.context)
return when (viewType) {
SONG -> SongViewHolder(ItemHomeContentSongBinding.inflate(inflate, parent, false), mSongListener)
PLAYLIST -> PlaylistViewHolder(ItemHomeContentPlaylistBinding.inflate(inflate, parent, false), mPlaylistListener)
ALBUM -> AlbumViewHolder(ItemHomeContentPlaylistBinding.inflate(inflate, parent, false), mAlbumListener)
else -> throw IllegalArgumentException("Invalid view type")
}
}
Expand All @@ -86,6 +107,7 @@ class HomeItemContentAdapter(private var listContent: ArrayList<Content>): Recyc
when (holder){
is SongViewHolder -> holder.bind(listContent[position])
is PlaylistViewHolder -> holder.bind(listContent[position])
is AlbumViewHolder -> holder.bind(listContent[position])
}
}

Expand All @@ -94,34 +116,21 @@ class HomeItemContentAdapter(private var listContent: ArrayList<Content>): Recyc
val temp = listContent[position]
return if (temp.playlistId != null && temp.videoId == null) {
PLAYLIST
} else {
} else if (temp.browseId != null && temp.videoId == null) {
ALBUM
}
else{
SONG
}
}

override fun getItemCount(): Int {
return listContent.size
}
fun removeTrailingComma(sentence: String): String {
val trimmed = sentence.trimEnd()
return if (trimmed.endsWith(", ")) {
trimmed.dropLast(2)
} else {
trimmed
}
}


fun removeComma(string: String): String {
return if (string.endsWith(',')) {
string.substring(0, string.length - 1)
} else {
string
}
}

companion object {
private const val SONG = 1
private const val PLAYLIST = 2
private const val ALBUM = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import com.maxrave.simpmusic.data.model.searchResult.artists.ArtistsResult
import com.maxrave.simpmusic.data.model.searchResult.playlists.PlaylistsResult
import com.maxrave.simpmusic.data.model.searchResult.songs.SongsResult
import com.maxrave.simpmusic.data.model.searchResult.videos.VideosResult
import com.maxrave.simpmusic.data.model.streams.Streams
import com.maxrave.simpmusic.data.model.thumbnailUrl
import retrofit2.Response
import javax.inject.Inject

class RemoteDataSource @Inject constructor(private val searchService: SearchService, private val dataStoreManager: DataStoreManager) {
suspend fun getSong(videoId: String): Response<ArrayList<Streams>> = searchService.getSong(videoId)

suspend fun getThumbnails(songId: String): Response<ArrayList<thumbnailUrl>> = searchService.getThumbnails(songId)
suspend fun searchAll(query: String, regionCode: String): Response<ArrayList<Any>> = searchService.searchAll(query, regionCode)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.maxrave.simpmusic.data.model.searchResult.artists.ArtistsResult
import com.maxrave.simpmusic.data.model.searchResult.playlists.PlaylistsResult
import com.maxrave.simpmusic.data.model.searchResult.songs.SongsResult
import com.maxrave.simpmusic.data.model.searchResult.videos.VideosResult
import com.maxrave.simpmusic.data.model.streams.Streams
import com.maxrave.simpmusic.data.model.thumbnailUrl
import retrofit2.Response
import retrofit2.http.GET
Expand All @@ -25,6 +26,9 @@ interface SearchService {
//get_thumbnails
@GET("thumbnails")
suspend fun getThumbnails(@Query("songId") songId: String): Response<ArrayList<thumbnailUrl>>
//song
@GET("song")
suspend fun getSong(@Query("videoId") videoId: String): Response<ArrayList<Streams>>
//search
@GET("search")
suspend fun searchAll(@Query("q") query: String, @Query("r") region: String): Response<ArrayList<Any>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ data class Content(
val isExplicit: Boolean?,
@SerializedName("playlistId")
val playlistId: String?,
@SerializedName("browseId")
val browseId: String?,
@SerializedName("thumbnails")
val thumbnails: List<Thumbnail>,
@SerializedName("title")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.maxrave.simpmusic.data.model.streams


import com.google.gson.annotations.SerializedName

data class Streams(
@SerializedName("audioTrackId")
val audioTrackId: Any,
@SerializedName("audioTrackLocale")
val audioTrackLocale: Any,
@SerializedName("audioTrackName")
val audioTrackName: Any,
@SerializedName("audioTrackType")
val audioTrackType: Any,
@SerializedName("bitrate")
val bitrate: Int,
@SerializedName("codec")
val codec: String,
@SerializedName("contentLength")
val contentLength: Int,
@SerializedName("format")
val format: String,
@SerializedName("fps")
val fps: Int,
@SerializedName("height")
val height: Int,
@SerializedName("indexEnd")
val indexEnd: Int,
@SerializedName("indexStart")
val indexStart: Int,
@SerializedName("initEnd")
val initEnd: Int,
@SerializedName("initStart")
val initStart: Int,
@SerializedName("itag")
val itag: Int,
@SerializedName("mimeType")
val mimeType: String,
@SerializedName("quality")
val quality: String,
@SerializedName("url")
val url: String,
@SerializedName("videoOnly")
val videoOnly: Boolean,
@SerializedName("width")
val width: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.maxrave.simpmusic.data.model.searchResult.artists.ArtistsResult
import com.maxrave.simpmusic.data.model.searchResult.playlists.PlaylistsResult
import com.maxrave.simpmusic.data.model.searchResult.songs.SongsResult
import com.maxrave.simpmusic.data.model.searchResult.videos.VideosResult
import com.maxrave.simpmusic.data.model.streams.Streams
import com.maxrave.simpmusic.data.model.thumbnailUrl
import com.maxrave.simpmusic.utils.Resource
import dagger.hilt.android.scopes.ActivityRetainedScoped
Expand All @@ -36,8 +37,9 @@ import kotlinx.coroutines.withContext
import java.time.LocalDateTime
import javax.inject.Inject

@ActivityRetainedScoped
//@ActivityRetainedScoped
class MainRepository @Inject constructor(private val remoteDataSource: RemoteDataSource, private val localDataSource: LocalDataSource): BaseApiResponse() {
suspend fun getSong(videoId: String): Flow<Resource<ArrayList<Streams>>> = flow { emit(safeApiCall { remoteDataSource.getSong(videoId) }) }.flowOn(Dispatchers.IO)
suspend fun getThumbnails(songId: String): Flow<Resource<ArrayList<thumbnailUrl>>> = flow { emit(safeApiCall { remoteDataSource.getThumbnails(songId) }) }.flowOn(Dispatchers.IO)
//search
suspend fun searchAll(query: String, regionCode: String) = remoteDataSource.searchAll(query, regionCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.session.MediaLibraryService.MediaLibrarySession
import androidx.media3.session.MediaSession
import com.maxrave.simpmusic.data.repository.MainRepository
import com.maxrave.simpmusic.service.SimpleMediaNotificationManager
import com.maxrave.simpmusic.service.SimpleMediaService
import com.maxrave.simpmusic.service.SimpleMediaServiceHandler
Expand Down Expand Up @@ -166,8 +167,7 @@ object MusicServiceModule {
@Provides
@Singleton
fun provideMusicSource(
@ApplicationContext context: Context,
simpleMediaServiceHandler: SimpleMediaServiceHandler
simpleMediaServiceHandler: SimpleMediaServiceHandler, mainRepository: MainRepository
): MusicSource =
MusicSource(context, simpleMediaServiceHandler)
MusicSource(simpleMediaServiceHandler, mainRepository)
}
Loading

0 comments on commit 365e670

Please sign in to comment.