This commit is contained in:
ocean 2024-05-17 18:03:28 +08:00
parent d14b11fac6
commit ac26183890
13 changed files with 237 additions and 39 deletions

View File

@ -103,7 +103,6 @@ class MoPlayDetailsActivity : MoBaseActivity(), Player.Listener {
}
}
onReceive()
}

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.graphics.Color
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.player.musicoo.App
@ -88,9 +89,22 @@ class DetailsListAdapter(
if (meController.currentMediaItem?.mediaId == bean.videoId) {
binding.title.setTextColor(context.getColor(R.color.green))
binding.name.setTextColor(context.getColor(R.color.green_60))
binding.listPlayView.visibility = View.VISIBLE
binding.sortTv.visibility = View.GONE
if (image.visibility == View.GONE) {
binding.listPlayView.setBackgroundColor(context.getColor(R.color.transparent))
} else {
binding.listPlayView.setBackgroundColor(context.getColor(R.color.black_60))
}
} else {
binding.title.setTextColor(context.getColor(R.color.white))
binding.name.setTextColor(context.getColor(R.color.white_60))
binding.listPlayView.visibility = View.GONE
if (image.visibility == View.GONE) {
binding.sortTv.visibility = View.VISIBLE
}
}
}
}

View File

@ -67,11 +67,13 @@ class PlayListAdapter(
val meController = MediaControllerManager.getController()
if (meController != null && meController.currentMediaItem != null) {
if (meController.currentMediaItem?.mediaId == bean.mediaId) {
binding.listPlayView.visibility = View.VISIBLE
binding.title.setTextColor(context.getColor(R.color.green))
binding.name.setTextColor(context.getColor(R.color.green_60))
} else {
binding.title.setTextColor(context.getColor(R.color.white))
binding.name.setTextColor(context.getColor(R.color.white_60))
binding.listPlayView.visibility = View.GONE
}
}
}

View File

@ -3,13 +3,16 @@ package com.player.musicoo.adapter
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.player.musicoo.R
import com.player.musicoo.activity.MoPlayDetailsActivity
import com.player.musicoo.databinding.MusicResponsiveItemBinding
import com.player.musicoo.innertube.models.MusicCarouselShelfRenderer
import com.player.musicoo.innertube.models.bodies.NextBody
import com.player.musicoo.media.MediaControllerManager
class ResponsiveListAdapter(
private val context: Context,
@ -63,7 +66,7 @@ class ResponsiveListAdapter(
val playlistSetVideoId = watchEndpoint?.playlistSetVideoId
val params = watchEndpoint?.params
holder.bind(url, name, desc)
holder.bind(url, name, desc, videoId)
holder.itemView.setOnClickListener {
val intent = Intent(context, MoPlayDetailsActivity::class.java)
@ -87,7 +90,7 @@ class ResponsiveListAdapter(
inner class ViewHolder(private val binding: MusicResponsiveItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(url: String?, name: String?, desc: String?) {
fun bind(url: String?, name: String?, desc: String?, videoID: String?) {
binding.apply {
Glide.with(context)
@ -95,6 +98,20 @@ class ResponsiveListAdapter(
.into(image)
nameTv.text = name
descTv.text = desc
val meController = MediaControllerManager.getController()
if (meController != null && meController.currentMediaItem != null) {
if (meController.currentMediaItem?.mediaId == videoID) {
binding.listPlayView.visibility = View.VISIBLE
binding.nameTv.setTextColor(context.getColor(R.color.green))
binding.descTv.setTextColor(context.getColor(R.color.green_60))
} else {
binding.nameTv.setTextColor(context.getColor(R.color.white))
binding.descTv.setTextColor(context.getColor(R.color.white_60))
binding.listPlayView.visibility = View.GONE
}
}
}
}
}

View File

@ -6,20 +6,25 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.player.musicoo.databinding.FragmentMoHomeBinding
import com.player.musicoo.activity.MoBaseActivity
import com.player.musicoo.sp.AppStore
import com.player.musicoo.util.LogTag
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
abstract class MoBaseFragment<T : ViewBinding> : Fragment(), CoroutineScope by MainScope() {
enum class Event {
FragmentOnResume,
}
protected abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> T
protected lateinit var binding: T
protected val TAG = LogTag.VO_FRAGMENT_LOG
protected val appStore by lazy { AppStore(requireContext()) }
protected val events = Channel<Event>(Channel.UNLIMITED)
protected abstract suspend fun onViewCreated()
@ -44,4 +49,9 @@ abstract class MoBaseFragment<T : ViewBinding> : Fragment(), CoroutineScope by M
super.onDestroy()
cancel()
}
override fun onResume() {
super.onResume()
events.trySend(Event.FragmentOnResume)
}
}

View File

@ -3,6 +3,7 @@ package com.player.musicoo.fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.allViews
import com.gyf.immersionbar.ktx.immersionBar
import com.player.musicoo.databinding.FragmentMoHomeBinding
import com.player.musicoo.innertube.Innertube
@ -50,6 +51,13 @@ class MoHomeFragment : MoBaseFragment<FragmentMoHomeBinding>() {
}
}
}
events.onReceive {
when (it) {
Event.FragmentOnResume -> {
fragmentOnResume()
}
}
}
}
}
}
@ -104,12 +112,9 @@ class MoHomeFragment : MoBaseFragment<FragmentMoHomeBinding>() {
for (home: Innertube.HomePage in it.homePage) {
for (content: MusicCarouselShelfRenderer.Content in home.contents) {
if (content.musicResponsiveListItemRenderer != null) {
binding.contentLayout.addView(
MusicResponsiveListView(
requireActivity(),
home
)
)
val musicResponsiveListView =
MusicResponsiveListView(requireActivity(), home)
binding.contentLayout.addView(musicResponsiveListView)
break
}
if (content.musicTwoRowItemRenderer != null) {
@ -130,6 +135,18 @@ class MoHomeFragment : MoBaseFragment<FragmentMoHomeBinding>() {
}
}
private fun fragmentOnResume(){
refreshAdapters()
}
private fun refreshAdapters() {//刷新home的单曲ui
for (i in 0 until binding.contentLayout.childCount) {
val child = binding.contentLayout.getChildAt(i)
if (child is MusicResponsiveListView) {
child.updateAdapter()
}
}
}
override fun onResume() {
super.onResume()
initImmersionBar()

View File

@ -0,0 +1,84 @@
package com.player.musicoo.view
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
class MusicBarsView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
// 用于绘制柱子的 Paint 对象
private val barPaint = Paint().apply {
color = Color.parseColor("#FF80F988")
style = Paint.Style.FILL
}
// 每个柱子的宽度
private val barWidth = dpToPx(context,4f)
// 柱子之间的间距
private val barSpacing = dpToPx(context,2f)
// 柱子的圆角半径
private val cornerRadius = dpToPx(context,16f)
// 保存每个柱子高度的列表
private val barHeights = mutableListOf<Float>()
// 保存每个柱子动画的列表
private val animators = mutableListOf<ValueAnimator>()
init {
// 初始化柱子的高度并启动动画
for (i in 0 until 3) {
barHeights.add(0f)
startAnimation(i)
}
}
// 启动动画
private fun startAnimation(index: Int) {
val animator = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 500 // 动画持续时间为 500 毫秒
repeatCount = ValueAnimator.INFINITE // 无限重复动画
repeatMode = ValueAnimator.REVERSE // 反向重复
addUpdateListener { animation ->
// 更新柱子的高度
barHeights[index] = (animation.animatedValue as Float) * height
invalidate() // 重绘 View
}
startDelay = index * 200L // 设置动画的开始延迟时间
}
animators.add(animator)
animator.start() // 启动动画
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
val barCount = barHeights.size
val totalWidth = barCount * barWidth + (barCount - 1) * barSpacing
val startX = (width - totalWidth) / 2
// 绘制每个柱子
barHeights.forEachIndexed { index, barHeight ->
val left = startX + index * (barWidth + barSpacing)
val top = height - barHeight
val right = left + barWidth
val bottom = height.toFloat()
canvas.drawRoundRect(left, top, right, bottom, cornerRadius, cornerRadius, barPaint)
}
}
fun dpToPx(context: Context, dp: Float): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.resources.displayMetrics)
}
}

View File

@ -11,10 +11,14 @@ import com.player.musicoo.adapter.ResponsiveListAdapter
import com.player.musicoo.adapter.SoundsOfNatureAdapter
import com.player.musicoo.innertube.Innertube
import com.player.musicoo.util.GridSpacingItemDecoration
import com.player.musicoo.util.LogTag
@SuppressLint("ViewConstructor")
class MusicResponsiveListView(context: Context, homePage: Innertube.HomePage) :
ModuleView(context) {
private var adapter: ResponsiveListAdapter? = null
init {
contentView = inflate(getContext(), R.layout.music_list_layout, this)
val title = contentView?.findViewById<TextView>(R.id.title)
@ -22,9 +26,15 @@ class MusicResponsiveListView(context: Context, homePage: Innertube.HomePage) :
val rv = contentView?.findViewById<RecyclerView>(R.id.rv)
val adapter = ResponsiveListAdapter(context, homePage.contents)
adapter = ResponsiveListAdapter(context, homePage.contents)
rv?.layoutManager = GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false)
rv?.adapter = adapter
}
@SuppressLint("NotifyDataSetChanged")
fun updateAdapter() {
if (adapter != null) {
adapter?.notifyDataSetChanged()
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#FF80F988"
android:pathData="m171.2,440a35.37,35.37 0,0 1,-17.5 -4.67c-12,-6.8 -19.46,-20 -19.46,-34.33v-290c0,-14.37 7.46,-27.53 19.46,-34.33a35.13,35.13 0,0 1,35.77 0.45l247.85,148.36a36,36 0,0 1,0 61l-247.89,148.4a35.5,35.5 0,0 1,-18.23 5.12z"/>
</vector>

View File

@ -10,12 +10,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="12dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:paddingTop="12dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="16dp">
<androidx.cardview.widget.CardView
@ -38,26 +38,26 @@
<TextView
android:id="@+id/sort_tv"
android:layout_width="22dp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="@font/medium_font"
android:gravity="center"
android:text="1"
android:textColor="@color/white"
android:textSize="16dp" />
<RelativeLayout
android:id="@+id/currentPlayingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black_60"
android:layout_centerInParent="true"
android:id="@+id/listPlayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<ImageView
<com.player.musicoo.view.MusicBarsView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/playing_small_green_icon" />
android:layout_height="16dp"
android:layout_centerInParent="true" />
</RelativeLayout>
</RelativeLayout>

View File

@ -12,10 +12,15 @@
android:orientation="horizontal"
android:paddingTop="12dp">
<RelativeLayout
android:layout_width="48dp"
android:layout_height="48dp">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="0dp"
android:visibility="visible"
app:cardCornerRadius="4dp"
app:cardElevation="0dp">
@ -28,6 +33,22 @@
</androidx.cardview.widget.CardView>
<RelativeLayout
android:id="@+id/listPlayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_60"
android:visibility="gone">
<com.player.musicoo.view.MusicBarsView
android:layout_width="wrap_content"
android:layout_height="16dp"
android:layout_centerInParent="true" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -39,8 +60,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:maxLines="1"
android:fontFamily="@font/regular_font"
android:maxLines="1"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="14dp" />
@ -50,8 +71,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:maxLines="1"
android:fontFamily="@font/regular_font"
android:maxLines="1"
android:text="@string/app_name"
android:textColor="@color/white_60"
android:textSize="12dp" />

View File

@ -37,6 +37,20 @@
android:scaleType="centerCrop"
android:src="@mipmap/musicoo_logo_img" />
<RelativeLayout
android:id="@+id/listPlayView"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_60">
<com.player.musicoo.view.MusicBarsView
android:layout_width="wrap_content"
android:layout_height="16dp"
android:layout_centerInParent="true" />
</RelativeLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>

View File

@ -10,4 +10,5 @@
<color name="green">#FF80F988</color>
<color name="green_60">#9980F988</color>
<color name="bottom_layout_bg_color">#1A1A1A</color>
<color name="transparent">#00000000</color>
</resources>