Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
v1.4.0-beta-290
Browse files Browse the repository at this point in the history
  • Loading branch information
Moriafly committed Jan 24, 2021
1 parent a95f409 commit 695e8d0
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
applicationId "com.dirror.music"
minSdkVersion 23
targetSdkVersion 30
versionCode 289
versionCode 290
versionName "2.4.0-beta"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<activity
android:name=".ui.activity.PlaylistActivity"
android:theme="@style/AppTheme.FullScreen.Translucent" />
<activity
android:name=".ui.activity.PlaylistActivity2"
android:theme="@style/AppTheme.FullScreen.Translucent" />
<activity android:name=".ui.activity.LoginByUidActivity" />
<activity android:name=".ui.activity.LoginByPhoneActivity" />
<activity
Expand Down
59 changes: 18 additions & 41 deletions app/src/main/java/com/dirror/music/ui/activity/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.Intent
import android.content.IntentFilter
import android.content.res.Configuration
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
Expand All @@ -17,7 +16,6 @@ import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.SeekBar
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.palette.graphics.Palette
import com.bumptech.glide.Glide
Expand All @@ -29,6 +27,7 @@ import com.dirror.music.databinding.ActivityPlayerBinding
import com.dirror.music.music.standard.SongPicture
import com.dirror.music.music.standard.data.SOURCE_NETEASE
import com.dirror.music.service.MusicService
import com.dirror.music.ui.base.BaseActivity
import com.dirror.music.ui.dialog.PlayerMenuMoreDialog
import com.dirror.music.ui.dialog.PlaylistDialog
import com.dirror.music.ui.viewmodel.PlayerViewModel
Expand All @@ -44,7 +43,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation
* @author Moriafly
* @since 2020年12月15日18:35:46
*/
class PlayerActivity : AppCompatActivity() {
class PlayerActivity : BaseActivity() {

companion object {
private const val MUSIC_BROADCAST_ACTION = "com.dirror.music.MUSIC_BROADCAST"
Expand Down Expand Up @@ -150,17 +149,19 @@ class PlayerActivity : AppCompatActivity() {
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun initBinding() {
binding = ActivityPlayerBinding.inflate(layoutInflater)
setContentView(binding.root)
}

override fun initView() {
// 设置 SlideBackLayout
slideBackLayout = SlideBackLayout(this, binding.clBase)
slideBackLayout.bind()
// 屏幕旋转
val configuration = this.resources.configuration //获取设置的配置信息
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//横屏
// 横屏
val decorView = window.decorView
// TODO 解决方法过时问题
val uiOptions = (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
Expand All @@ -169,33 +170,6 @@ class PlayerActivity : AppCompatActivity() {
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
decorView.systemUiVisibility = uiOptions
}
// 初始化广播接受者
initBroadcastReceiver()
// 初始化视图
initView()
// 初始化监听
initListener()
// 初始化 ViewModel 观察
initViewModelObserve()
}

/**
* 初始化广播接受者
*/
private fun initBroadcastReceiver() {
// Intent 过滤器,只接收 "com.dirror.foyou.MUSIC_BROADCAST" 标识广播
val intentFilter = IntentFilter()
intentFilter.addAction(MUSIC_BROADCAST_ACTION)
musicBroadcastReceiver = MusicBroadcastReceiver()
// 注册接收器
registerReceiver(musicBroadcastReceiver, intentFilter)
}

/**
* 初始化视图
*/
private fun initView() {

// 页面状态栏适配
(binding.titleBar.layoutParams as ConstraintLayout.LayoutParams).apply {
topToTop = ConstraintLayout.LayoutParams.PARENT_ID
Expand Down Expand Up @@ -224,11 +198,8 @@ class PlayerActivity : AppCompatActivity() {
}
}

/**
* 初始化监听
*/
@SuppressLint("ClickableViewAccessibility")
private fun initListener() {
override fun initListener() {
binding.apply {
// 返回按钮
ivBack.setOnClickListener { finish() }
Expand Down Expand Up @@ -349,10 +320,16 @@ class PlayerActivity : AppCompatActivity() {
}
}

/**
* 初始化观察者
*/
private fun initViewModelObserve() {
override fun initBroadcastReceiver() {
// Intent 过滤器,只接收 "com.dirror.foyou.MUSIC_BROADCAST" 标识广播
val intentFilter = IntentFilter()
intentFilter.addAction(MUSIC_BROADCAST_ACTION)
musicBroadcastReceiver = MusicBroadcastReceiver()
// 注册接收器
registerReceiver(musicBroadcastReceiver, intentFilter)
}

override fun initObserver() {
playViewModel.apply {
// 播放模式的观察
playMode.observe(this@PlayerActivity, {
Expand Down
167 changes: 167 additions & 0 deletions app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity2.kt
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 app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt
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() { }

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dirror.music.ui.dialog
package com.dirror.music.ui.base

import android.content.Context
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.dirror.music.MyApplication
import com.dirror.music.databinding.DialogTextInfoBinding
import com.dirror.music.foyou.sentence.foyoulibrary.FoyouLibrary
import com.dirror.music.room.AppDatabase
import com.dirror.music.ui.base.BaseBottomSheetDialog
import com.dirror.music.util.Secure
import com.dirror.music.util.defaultTypeface
import com.dirror.music.util.getVisionCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dirror.music.ui.dialog
import android.content.Context
import com.dirror.music.databinding.DialogCreateLocalPlaylistBinding
import com.dirror.music.music.local.LocalPlaylist
import com.dirror.music.ui.base.BaseBottomSheetDialog
import com.dirror.music.util.toast

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.dirror.music.music.local.MyFavorite
import com.dirror.music.music.standard.data.StandardSongData
import com.dirror.music.ui.activity.FeedbackActivity
import com.dirror.music.ui.activity.PlayHistoryActivity
import com.dirror.music.util.toast
import com.dirror.music.ui.base.BaseBottomSheetDialog

class PlayerMenuMoreDialog(context: Context) : BaseBottomSheetDialog(context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.adapter.PlaylistDialogAdapter
import com.dirror.music.databinding.DialogPlayListBinding
import com.dirror.music.ui.base.BaseBottomSheetDialog

class PlaylistDialog(context: Context): BaseBottomSheetDialog(context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.dirror.music.data.PLAYLIST_TAG_NORMAL
import com.dirror.music.databinding.DialogSongMenuBinding
import com.dirror.music.music.local.MyFavorite
import com.dirror.music.music.standard.data.StandardSongData
import com.dirror.music.ui.base.BaseBottomSheetDialog
import com.dirror.music.util.toast

class SongMenuDialog
Expand Down
Loading

0 comments on commit 695e8d0

Please sign in to comment.