This repository has been archived by the owner on Aug 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
289 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package com.dirror.music.ui.activity | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.dirror.music.MyApplication | ||
import com.dirror.music.R | ||
import com.dirror.music.adapter.DetailPlaylistAdapter | ||
import com.dirror.music.data.PLAYLIST_TAG_NORMAL | ||
import com.dirror.music.databinding.ActivityPlaylistBinding | ||
import com.dirror.music.music.standard.SongPicture | ||
import com.dirror.music.music.standard.data.SOURCE_NETEASE | ||
import com.dirror.music.ui.base.BaseActivity | ||
import com.dirror.music.ui.dialog.PlaylistDialog | ||
import com.dirror.music.ui.viewmodel.PlaylistViewModel | ||
import com.dirror.music.util.* | ||
|
||
/** | ||
* 新版 Playlist | ||
*/ | ||
class PlaylistActivity2: BaseActivity() { | ||
|
||
companion object { | ||
const val EXTRA_PLAYLIST_SOURCE = "int_playlist_source" | ||
const val EXTRA_LONG_PLAYLIST_ID = "int_playlist_id" | ||
const val EXTRA_INT_TAG = "int_tag" | ||
} | ||
|
||
private lateinit var binding: ActivityPlaylistBinding | ||
|
||
// 音乐广播接收 | ||
private lateinit var musicBroadcastReceiver: MusicBroadcastReceiver | ||
|
||
private var detailPlaylistAdapter = DetailPlaylistAdapter(ArrayList(), this) | ||
|
||
private val playlistViewModel: PlaylistViewModel by viewModels() | ||
|
||
override fun initBinding() { | ||
binding = ActivityPlaylistBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
} | ||
|
||
override fun initView() { | ||
// 屏幕适配 | ||
(binding.titleBar.layoutParams as ConstraintLayout.LayoutParams).apply { | ||
topMargin = getStatusBarHeight(window, this@PlaylistActivity2) | ||
} | ||
(binding.includePlay.root.layoutParams as ConstraintLayout.LayoutParams).apply { | ||
bottomMargin = getNavigationBarHeight(this@PlaylistActivity2) | ||
} | ||
// 色彩 | ||
binding.ivPlayAll.setColorFilter(getColor(R.color.colorAppThemeColor)) | ||
|
||
// 获取歌单来源 | ||
playlistViewModel.source = intent.getIntExtra(EXTRA_PLAYLIST_SOURCE, SOURCE_NETEASE) | ||
// 获取歌单 id | ||
playlistViewModel.id = intent.getLongExtra(EXTRA_LONG_PLAYLIST_ID, 0L) | ||
// 获取 tag | ||
playlistViewModel.tag = intent.getIntExtra(EXTRA_INT_TAG, PLAYLIST_TAG_NORMAL) | ||
|
||
binding.lottieLoading.repeatCount = -1 | ||
binding.lottieLoading.playAnimation() | ||
|
||
// 请求更新 | ||
playlistViewModel.updatePlaylist() | ||
|
||
binding.rvPlaylist.layoutManager = LinearLayoutManager(this@PlaylistActivity2) | ||
} | ||
|
||
override fun initBroadcastReceiver() { | ||
val intentFilter = IntentFilter() // Intent 过滤器 | ||
intentFilter.addAction("com.dirror.music.MUSIC_BROADCAST") // 只接收 "com.dirror.foyou.MUSIC_BROADCAST" 标识广播 | ||
musicBroadcastReceiver = MusicBroadcastReceiver() // | ||
registerReceiver(musicBroadcastReceiver, intentFilter) // 注册接收器 | ||
} | ||
|
||
override fun initListener() { | ||
binding.apply { | ||
includePlay.root.setOnClickListener { | ||
startActivity(Intent(this@PlaylistActivity2, PlayerActivity::class.java)) | ||
overridePendingTransition( | ||
R.anim.anim_slide_enter_bottom, | ||
R.anim.anim_no_anim | ||
) | ||
} | ||
includePlay.ivPlay.setOnClickListener { | ||
MyApplication.musicBinderInterface?.changePlayState() | ||
} | ||
includePlay.ivPlaylist.setOnClickListener { | ||
PlaylistDialog(this@PlaylistActivity2).show() | ||
} | ||
// 全部播放 播放第一首歌 | ||
clNav.setOnClickListener { | ||
if (detailPlaylistAdapter.itemCount != 0) { | ||
detailPlaylistAdapter.playFirst() | ||
} | ||
} | ||
ivShare.setOnClickListener { | ||
toast("歌单 ID 已经成功复制到剪贴板") | ||
copyToClipboard(this@PlaylistActivity2, playlistViewModel.id.toString()) | ||
} | ||
} | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
override fun initObserver() { | ||
playlistViewModel.apply { | ||
playlist.observe(this@PlaylistActivity2, { | ||
detailPlaylistAdapter = DetailPlaylistAdapter(it, this@PlaylistActivity2, tag) | ||
binding.rvPlaylist.adapter = detailPlaylistAdapter | ||
binding.tvPlayAll.text = "播放全部(${it.size})" | ||
binding.clLoading.visibility = View.GONE | ||
binding.lottieLoading.pauseAnimation() | ||
}) | ||
} | ||
} | ||
|
||
inner class MusicBroadcastReceiver: BroadcastReceiver() { | ||
// 接收 | ||
override fun onReceive(context: Context, intent: Intent) { | ||
refreshLayoutPlay() | ||
refreshPlayState() | ||
} | ||
} | ||
|
||
private fun refreshPlayState() { | ||
if (MyApplication.musicBinderInterface?.getPlayState() == true) { | ||
binding.includePlay.ivPlay.setImageResource(R.drawable.ic_bq_control_pause) | ||
} else { | ||
binding.includePlay.ivPlay.setImageResource(R.drawable.ic_bq_control_play) | ||
} | ||
} | ||
|
||
/** | ||
* 刷新下方播放框 | ||
* 可能导致 stick 丢失 | ||
*/ | ||
private fun refreshLayoutPlay() { | ||
MyApplication.musicBinderInterface?.getNowSongData()?.let { standardSongData -> | ||
binding.includePlay.tvName.text = standardSongData.name | ||
binding.includePlay.tvArtist.text = standardSongData.artists?.let { parseArtist(it) } | ||
SongPicture.getSongPicture(standardSongData, SongPicture.TYPE_LARGE) { | ||
binding.includePlay.ivCover.setImageBitmap(it) | ||
} | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
refreshLayoutPlay() | ||
refreshPlayState() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
// 解绑 | ||
unregisterReceiver(musicBroadcastReceiver) | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.dirror.music.ui.base | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
abstract class BaseActivity: AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
initBinding() | ||
initView() | ||
initListener() | ||
initObserver() | ||
initBroadcastReceiver() | ||
} | ||
|
||
protected open fun initBinding() { } | ||
|
||
protected open fun initView() { } | ||
|
||
protected open fun initListener() { } | ||
|
||
protected open fun initObserver() { } | ||
|
||
protected open fun initBroadcastReceiver() { } | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../music/ui/dialog/BaseBottomSheetDialog.kt → ...or/music/ui/base/BaseBottomSheetDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.