Skip to content

Commit

Permalink
Add Spanish, Add Featured On in Artist Page, Add some thing new in Ho…
Browse files Browse the repository at this point in the history
…me Page
  • Loading branch information
maxrave-dev committed Nov 4, 2023
1 parent 3dde931 commit 3dc1714
Show file tree
Hide file tree
Showing 31 changed files with 736 additions and 67 deletions.
14 changes: 13 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ android {
arg("room.schemaLocation", "$projectDir/schemas")
}

resourceConfigurations += listOf("en", "vi", "it", "de", "ru", "tr", "fi", "pl", "pt", "fr")
resourceConfigurations += listOf(
"en",
"vi",
"it",
"de",
"ru",
"tr",
"fi",
"pl",
"pt",
"fr",
"es"
)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.maxrave.simpmusic.adapter.artist

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.maxrave.simpmusic.data.model.browse.artist.ResultPlaylist
import com.maxrave.simpmusic.databinding.ItemSinglesBinding

class FeaturedOnAdapter(private var playlistList: ArrayList<ResultPlaylist>) :
RecyclerView.Adapter<FeaturedOnAdapter.ViewHolder>() {
private lateinit var mListener: OnItemClickListener

interface OnItemClickListener {
fun onItemClick(position: Int, type: String = "playlist")
}

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


inner class ViewHolder(val binding: ItemSinglesBinding, listener: OnItemClickListener) :
RecyclerView.ViewHolder(binding.root) {
init {
binding.root.setOnClickListener {
listener.onItemClick(bindingAdapterPosition)
}
}
}

fun updateList(newList: ArrayList<ResultPlaylist>) {
playlistList.clear()
playlistList.addAll(newList)
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemSinglesBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
), mListener
)
}

override fun getItemCount(): Int {
return playlistList.size
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val album = playlistList[position]
with(holder.binding) {
tvAlbumName.text = album.title
tvAlbumYear.text = album.author
ivAlbumArt.load(album.thumbnails.lastOrNull()?.url)
}
}

fun getItem(position: Int): ResultPlaylist {
return playlistList[position]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.NavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.data.model.browse.album.Track
Expand Down Expand Up @@ -39,6 +41,32 @@ class HomeItemAdapter(private var homeItemList: ArrayList<HomeItem>, var context
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val homeItem = homeItemList[position]
holder.binding.tvTitle.text = homeItem.title
if (homeItem.subtitle == null) {
holder.binding.tvSubtitle.visibility = View.GONE
holder.binding.ivArtist.visibility = View.GONE
} else {
holder.binding.tvSubtitle.text = homeItem.subtitle
holder.binding.tvSubtitle.visibility = View.VISIBLE
}
if (!homeItem.thumbnail.isNullOrEmpty()) {
holder.binding.ivArtist.visibility = View.VISIBLE
holder.binding.ivArtist.load(homeItem.thumbnail.lastOrNull()?.url)
} else {
holder.binding.ivArtist.visibility = View.GONE
}
if (homeItem.channelId != null) {
holder.binding.tvTitle.isClickable = true
holder.binding.tvTitle.isFocusable = true
val attr =
context.obtainStyledAttributes(intArrayOf(android.R.attr.selectableItemBackgroundBorderless))
holder.binding.tvTitle.foreground = attr.getDrawable(0)
attr.recycle()
holder.binding.tvTitle.setOnClickListener {
val args = Bundle()
args.putString("channelId", homeItem.channelId)
navController.navigateSafe(R.id.action_global_artistFragment, args)
}
}
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
val tempContentList = homeItem.contents.toCollection(ArrayList())
tempContentList.removeIf { it == null }
Expand All @@ -47,7 +75,7 @@ class HomeItemAdapter(private var homeItemList: ArrayList<HomeItem>, var context
this.adapter = itemAdapter
this.layoutManager = layoutManager
}
itemAdapter.setOnSongClickListener(object : HomeItemContentAdapter.onSongItemClickListener{
itemAdapter.setOnSongClickListener(object : HomeItemContentAdapter.onSongItemClickListener {
override fun onSongItemClick(position: Int) {
val args = Bundle()
args.putString("videoId", homeItemList[holder.bindingAdapterPosition].contents[position]?.videoId)
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,32 @@ object SUPPORTED_LOCATION {
"TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "VE", "VN", "YE", "ZA", "ZW")
}
object SUPPORTED_LANGUAGE {
val items: Array<CharSequence> = arrayOf("English", "Tiếng Việt", "Italiano", "Deutsch", "Русский", "Türkçe", "Suomi", "Polski", "Português", "Français")
val codes: Array<String> = arrayOf("en-US", "vi-VN", "it-IT", "de-DE", "ru-RU", "tr-TR", "fi-FI", "pl-PL", "pt-PT", "fr-FR")
val items: Array<CharSequence> = arrayOf(
"English",
"Tiếng Việt",
"Italiano",
"Deutsch",
"Русский",
"Türkçe",
"Suomi",
"Polski",
"Português",
"Français",
"Español"
)
val codes: Array<String> = arrayOf(
"en-US",
"vi-VN",
"it-IT",
"de-DE",
"ru-RU",
"tr-TR",
"fi-FI",
"pl-PL",
"pt-PT",
"fr-FR",
"es-ES"
)
}
object QUALITY {
val items: Array<CharSequence> = arrayOf("Low - 66kps", "High - 129kps")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class ArtistBrowse(
val songs: Songs?,
@SerializedName("video")
val video: List<ResultVideo>?,
val featuredOn: List<ResultPlaylist>?,
val videoList: String?,
@SerializedName("subscribed")
val subscribed: Boolean?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.maxrave.simpmusic.data.model.browse.artist

import com.maxrave.simpmusic.data.model.searchResult.songs.Thumbnail

data class ResultPlaylist(
val id: String,
val author: String,
val thumbnails: List<Thumbnail>,
val title: String,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package com.maxrave.simpmusic.data.model.home


import com.google.gson.annotations.SerializedName
import com.maxrave.simpmusic.data.model.searchResult.songs.Thumbnail

data class HomeItem(
@SerializedName("contents")
val contents: List<Content?>,
@SerializedName("title")
val title: String
val title: String,
val subtitle: String? = null,
val thumbnail: List<Thumbnail>? = null,
val channelId: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.util.Log
import com.maxrave.kotlinytmusicscraper.models.AlbumItem
import com.maxrave.kotlinytmusicscraper.models.ArtistItem
import com.maxrave.kotlinytmusicscraper.models.PlaylistItem
import com.maxrave.kotlinytmusicscraper.models.SongItem
import com.maxrave.kotlinytmusicscraper.models.VideoItem
import com.maxrave.kotlinytmusicscraper.pages.ArtistPage
Expand All @@ -12,6 +13,7 @@ import com.maxrave.simpmusic.data.model.browse.artist.Albums
import com.maxrave.simpmusic.data.model.browse.artist.ArtistBrowse
import com.maxrave.simpmusic.data.model.browse.artist.Related
import com.maxrave.simpmusic.data.model.browse.artist.ResultAlbum
import com.maxrave.simpmusic.data.model.browse.artist.ResultPlaylist
import com.maxrave.simpmusic.data.model.browse.artist.ResultRelated
import com.maxrave.simpmusic.data.model.browse.artist.ResultSingle
import com.maxrave.simpmusic.data.model.browse.artist.ResultSong
Expand All @@ -29,14 +31,19 @@ fun parseArtistData(data: ArtistPage, context: Context): ArtistBrowse {
val songSection = data.sections.find { it.title == context.getString(R.string.songs_inArtist) }
val albumSection = data.sections.find { it.title == context.getString(R.string.albums_inArtist) }
val singleSection = data.sections.find { it.title == context.getString(R.string.singles_inArtist) }
val videoSection = data.sections.find {it.title == context.getString(R.string.videos_inArtist)}
val videoSection =
data.sections.find { it.title == context.getString(R.string.videos_inArtist) }
val featuredOnSection =
data.sections.find { it.title == context.getString(R.string.featured_inArtist) }
Log.w("ArtistParser", "videoSection: ${videoSection?.items}")
Log.w("ArtistParser", "featuredOnSection: ${featuredOnSection?.items}")
val relatedSection = data.sections.find { it.title == context.getString(R.string.fans_might_also_like_inArtist) }
val listSong : ArrayList<ResultSong> = arrayListOf()
val listAlbum: ArrayList<ResultAlbum> = arrayListOf()
val listSingle: ArrayList<ResultSingle> = arrayListOf()
val listRelated: ArrayList<ResultRelated> = arrayListOf()
val listVideo: ArrayList<ResultVideo> = arrayListOf()
val listFeaturedOn: ArrayList<ResultPlaylist> = arrayListOf()
albumSection?.items?.forEach { album->
listAlbum.add(
ResultAlbum(
Expand Down Expand Up @@ -73,11 +80,25 @@ fun parseArtistData(data: ArtistPage, context: Context): ArtistBrowse {
)
)
}
featuredOnSection?.items?.forEach {
val playlist = it as PlaylistItem
listFeaturedOn.add(
ResultPlaylist(
id = playlist.id,
author = playlist.author?.name ?: "",
thumbnails = listOf(Thumbnail(544, playlist.thumbnail, 544)),
title = playlist.title
)
)
}
relatedSection?.items?.forEach {
val artist = it as ArtistItem
listRelated.add(
ResultRelated(
browseId = artist.id, subscribers = artist.subscribers?:"", thumbnails = listOf(Thumbnail(544,artist.thumbnail,544)), title = artist.title
browseId = artist.id,
subscribers = artist.subscribers ?: "",
thumbnails = listOf(Thumbnail(544, artist.thumbnail, 544)),
title = artist.title
)
)
}
Expand Down Expand Up @@ -116,9 +137,10 @@ fun parseArtistData(data: ArtistPage, context: Context): ArtistBrowse {
songs = Songs(browseId = songSection?.moreEndpoint?.browseId, results = listSong),
subscribed = false,
subscribers = data.subscribers,
thumbnails = listOf(Thumbnail(2880, data.artist.thumbnail,1200)),
thumbnails = listOf(Thumbnail(2880, data.artist.thumbnail, 1200)),
views = data.view,
video = listVideo,
videoList = videoSection?.moreEndpoint?.browseId
videoList = videoSection?.moreEndpoint?.browseId,
featuredOn = listFeaturedOn
)
}
23 changes: 19 additions & 4 deletions app/src/main/java/com/maxrave/simpmusic/data/parser/HomeParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ fun parseMixedContent(data: List<SectionListRenderer.Content>?): List<HomeItem>
Log.w("parse_mixed_content", results1.toString())
val contentList = results1?.contents
Log.w("parse_mixed_content", results1?.contents?.size.toString())
val title = results1?.header?.musicCarouselShelfBasicHeaderRenderer?.title?.runs?.get(0)?.text ?: ""
val title =
results1?.header?.musicCarouselShelfBasicHeaderRenderer?.title?.runs?.get(0)?.text
?: ""
Log.w("parse_mixed_content", title)
val subtitle =
results1?.header?.musicCarouselShelfBasicHeaderRenderer?.strapline?.runs?.firstOrNull()?.text
val thumbnail =
results1?.header?.musicCarouselShelfBasicHeaderRenderer?.thumbnail?.musicThumbnailRenderer?.thumbnail?.thumbnails?.toListThumbnail()
val artistChannelId =
results1?.header?.musicCarouselShelfBasicHeaderRenderer?.title?.runs?.firstOrNull()?.navigationEndpoint?.browseEndpoint?.browseId
val listContent = mutableListOf<Content?>()
if (!contentList.isNullOrEmpty()) {
for (result1 in contentList) {
Expand Down Expand Up @@ -273,13 +281,20 @@ fun parseMixedContent(data: List<SectionListRenderer.Content>?): List<HomeItem>
)
listContent.add(content)
}
}
else {
} else {
break
}
}
}
list.add(HomeItem(contents = listContent, title = title))
list.add(
HomeItem(
contents = listContent,
title = title,
subtitle = subtitle,
thumbnail = thumbnail,
channelId = if (artistChannelId?.contains("UC") == true) artistChannelId else null
)
)
Log.w("parse_mixed_content", list.toString())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.maxrave.kotlinytmusicscraper.YouTube
import com.maxrave.kotlinytmusicscraper.models.MusicShelfRenderer
import com.maxrave.kotlinytmusicscraper.models.SearchSuggestions
import com.maxrave.kotlinytmusicscraper.models.SongItem
import com.maxrave.kotlinytmusicscraper.models.VideoItem
import com.maxrave.kotlinytmusicscraper.models.WatchEndpoint
import com.maxrave.kotlinytmusicscraper.models.musixmatch.MusixmatchCredential
import com.maxrave.kotlinytmusicscraper.models.musixmatch.MusixmatchTranslationLyricsResponse
Expand All @@ -18,7 +17,6 @@ import com.maxrave.kotlinytmusicscraper.models.youtube.YouTubeInitialPage
import com.maxrave.kotlinytmusicscraper.pages.BrowseResult
import com.maxrave.kotlinytmusicscraper.pages.PlaylistPage
import com.maxrave.kotlinytmusicscraper.pages.SearchPage
import com.maxrave.kotlinytmusicscraper.pages.SearchSuggestionPage
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.data.dataStore.DataStoreManager
import com.maxrave.simpmusic.data.db.LocalDataSource
Expand Down Expand Up @@ -74,7 +72,6 @@ import com.maxrave.simpmusic.data.parser.search.parseSearchSong
import com.maxrave.simpmusic.data.parser.search.parseSearchVideo
import com.maxrave.simpmusic.data.parser.toListThumbnail
import com.maxrave.simpmusic.extension.bestMatchingIndex
import com.maxrave.simpmusic.extension.removeDuplicateWords
import com.maxrave.simpmusic.extension.toListTrack
import com.maxrave.simpmusic.extension.toLyrics
import com.maxrave.simpmusic.extension.toTrack
Expand Down Expand Up @@ -506,8 +503,14 @@ class MainRepository @Inject constructor(private val localDataSource: LocalDataS
durationSeconds = 0,
id = radioId,
privacy = "PRIVATE",
thumbnails = listOf(Thumbnail(544, originalTrack?.thumbnails ?: artist?.thumbnails ?: "", 544)),
title = " ${originalTrack?.title ?: artist?.name} ${context.getString(R.string.radio)}",
thumbnails = listOf(
Thumbnail(
544,
originalTrack?.thumbnails ?: artist?.thumbnails ?: "",
544
)
),
title = "${originalTrack?.title ?: artist?.name} ${context.getString(R.string.radio)}",
trackCount = listTrackResult.size,
tracks = listTrackResult,
year = LocalDateTime.now().year.toString()
Expand Down
Loading

0 comments on commit 3dc1714

Please sign in to comment.