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

Commit

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

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.data.PLAYLIST_TAG_MY_FAVORITE
import com.dirror.music.data.PLAYLIST_TAG_NORMAL
import com.dirror.music.music.standard.data.StandardSongData
import com.dirror.music.ui.activity.PlayerActivity
Expand Down Expand Up @@ -64,19 +63,11 @@ class DetailPlaylistAdapter
}
// 更多点击,每首歌右边的三点菜单
ivMore.setOnClickListener {
SongMenuDialog(it.context, tag).apply {
setSongData(song)
setActivity(activity)
show()
}
SongMenuDialog(it.context, activity, song, tag).show()
}
// 长按
clSong.setOnLongClickListener {
SongMenuDialog(it.context, tag).apply {
setSongData(song)
setActivity(activity)
show()
}
SongMenuDialog(it.context, activity, song, tag).show()
return@setOnLongClickListener true
}
}
Expand All @@ -97,13 +88,8 @@ class DetailPlaylistAdapter
* 播放音乐
*/
private fun playMusic(position: Int, view: View?) {
// 空歌单跳出
// if (MyApplication.musicBinderInterface?.getPlaylist() == null) {
// return
// }
// 歌单相同
if (MyApplication.musicBinderInterface?.getPlaylist() == songDataList) {
// toast("歌单相同")
// position 相同
if (position == MyApplication.musicBinderInterface?.getNowPosition()) {
if (view != null) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/dirror/music/manager/ActivityManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class ActivityManager: ActivityManagerInterface {
activity.startActivity(intent)
}

override fun startWebActivity(activity: Activity, url: String, title: String) {
val intent = Intent(activity, WebActivity::class.java)
intent.putExtra("extra_webUrlStr", url)
intent.putExtra(WebActivity.EXTRA_TITLE, title)
activity.startActivity(intent)
}

/**
* 启动评论 activity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ interface ActivityManagerInterface {

fun startWebActivity(activity: Activity, url: String)

fun startWebActivity(activity: Activity, url: String, title: String)

fun startCommentActivity(activity: Activity, source: Int, id: String)

fun startUserActivity(activity: Activity, userId: Long)
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/com/dirror/music/music/local/MyFavorite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.dirror.music.music.local
import com.dirror.music.MyApplication
import com.dirror.music.music.standard.data.StandardSongData
import com.dirror.music.room.MyFavoriteData
import com.dirror.music.util.toast
import org.jetbrains.annotations.TestOnly
import kotlin.concurrent.thread

Expand All @@ -21,7 +22,7 @@ object MyFavorite {
thread {
val data = ArrayList<StandardSongData>()
for (myFavorite in myFavoriteDao.loadAll()) {
data.add(myFavorite.songData)
data.add(0, myFavorite.songData)
}
success.invoke(data)
}
Expand All @@ -33,7 +34,13 @@ object MyFavorite {
@TestOnly
fun addSong(songData: StandardSongData) {
thread {
myFavoriteDao.insert(MyFavoriteData(songData))
val myFavoriteData = MyFavoriteData(songData)
if (myFavoriteData !in myFavoriteDao.loadAll()) {
myFavoriteDao.insert(myFavoriteData)
toast("添加成功")
} else {
toast("已经添加过了哦~")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class MainActivity : AppCompatActivity() {
}

binding.menuMain.itemSourceCode.setOnClickListener {
MyApplication.activityManager.startWebActivity(this, "https://github.com/Moriafly/DsoMusic")
MyApplication.activityManager.startWebActivity(this, "https://github.com/Moriafly/DsoMusic", getString(R.string.source_code))
}

binding.menuMain.itemAbout.setOnClickListener {
Expand Down
37 changes: 27 additions & 10 deletions app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.graphics.drawable.toBitmap
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
Expand Down Expand Up @@ -49,6 +51,8 @@ class PlaylistActivity : AppCompatActivity() {

private var playlistId: Long = -1L

private var playlistSource: Int = SOURCE_NETEASE

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPlaylistBinding.inflate(layoutInflater)
Expand Down Expand Up @@ -78,7 +82,7 @@ class PlaylistActivity : AppCompatActivity() {
// 色彩
binding.ivPlayAll.setColorFilter(getColor(R.color.colorAppThemeColor))
// 获取歌单来源
val playlistSource = intent.getIntExtra(EXTRA_PLAYLIST_SOURCE, 0)
playlistSource = intent.getIntExtra(EXTRA_PLAYLIST_SOURCE, SOURCE_NETEASE)
// 获取歌单 id
playlistId = intent.getLongExtra(EXTRA_LONG_PLAYLIST_ID, -1)

Expand Down Expand Up @@ -160,6 +164,7 @@ class PlaylistActivity : AppCompatActivity() {
SOURCE_LOCAL -> {
// 我喜欢
if (id == 0L) {
initPlaylistInfo(id)
MyFavorite.read {
initRecycleView(it, PLAYLIST_TAG_MY_FAVORITE)
}
Expand All @@ -171,20 +176,21 @@ class PlaylistActivity : AppCompatActivity() {
/**
* 初始化歌单信息
*/
@SuppressLint("UseCompatLoadingForDrawables")
private fun initPlaylistInfo(id: Long) {
if (playlistSource == SOURCE_LOCAL && playlistId == 0L) {
getDrawable(R.drawable.ic_bq_love_music_filter)?.let {
binding.ivCover.setImageBitmap(it.toBitmap())
binding.tvName.text = getString(R.string.my_favorite_songs)
setBackground(it.toBitmap())
}
return
}
PlaylistUtil.getPlaylistInfo(id) {
it.coverImgUrl?.let { url ->
GlideUtil.load(url) { bitmap ->
runOnMainThread {
binding.ivCover.setImageBitmap(bitmap)
Glide.with(MyApplication.context)
.load(bitmap)
.placeholder(binding.ivBackground.drawable)
.apply(RequestOptions.bitmapTransform(BlurTransformation(50, 10)))
.into(binding.ivBackground)
}
setBackground(bitmap)
}

}
runOnMainThread {
binding.tvName.text = it.name
Expand All @@ -193,6 +199,17 @@ class PlaylistActivity : AppCompatActivity() {
}
}

private fun setBackground(bitmap: Bitmap) {
runOnMainThread {
binding.ivCover.setImageBitmap(bitmap)
Glide.with(MyApplication.context)
.load(bitmap)
.placeholder(binding.ivBackground.drawable)
.apply(RequestOptions.bitmapTransform(BlurTransformation(50, 10)))
.into(binding.ivBackground)
}
}

inner class MusicBroadcastReceiver: BroadcastReceiver() {
// 接收
override fun onReceive(context: Context, intent: Intent) {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ class WebActivity : AppCompatActivity() {
binding.webView.webChromeClient = object : WebChromeClient() {
override fun onReceivedTitle(view: WebView, title: String) {
super.onReceivedTitle(view, title)
var titleStr = title
titleStr = titleStr.replace("_百度百科", "")
binding.titleBar.setTitleBarText(titleStr)
if (extraTitle.isNullOrEmpty()) {
binding.titleBar.setTitleBarText(title)
} else {
binding.titleBar.setTitleBarText(extraTitle)
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.dirror.music.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import com.dirror.music.R
import com.dirror.music.databinding.DialogCreateLocalPlaylistBinding
import com.dirror.music.music.local.LocalPlaylist
import com.dirror.music.util.toast
Expand All @@ -14,18 +9,15 @@ import com.dirror.music.util.toast
* 创建本地歌单 Dialog
* @author Moriafly
*/
class CreateLocalPlaylistDialog(context: Context) : Dialog(context, R.style.style_default_dialog) {
class CreateLocalPlaylistDialog(context: Context) : BaseBottomSheetDialog(context) {

private var binding = DialogCreateLocalPlaylistBinding.inflate(layoutInflater)

init {
setContentView(binding.root)
window?.setGravity(Gravity.BOTTOM)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
override fun initListener() {
binding.apply {
btnConfirm.setOnClickListener {
val name = etName.text.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,73 @@ package com.dirror.music.ui.dialog

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.databinding.DialogPlayMoreBinding
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.google.android.material.bottomsheet.BottomSheetDialog

class PlayerMenuMoreDialog(context: Context) : BottomSheetDialog(context, R.style.style_default_dialog) {
class PlayerMenuMoreDialog(context: Context) : BaseBottomSheetDialog(context) {

private var binding: DialogPlayMoreBinding = DialogPlayMoreBinding.inflate(layoutInflater)
private val binding: DialogPlayMoreBinding = DialogPlayMoreBinding.inflate(layoutInflater)

init {
setContentView(binding.root)
window?.setGravity(Gravity.BOTTOM)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
window?.setWindowAnimations(R.style.dialog_animation)
}

private var speed = 1f
private var song: StandardSongData? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

override fun initView() {
speed = MyApplication.musicBinderInterface?.getSpeed() ?: 1f

refreshPitch()

MyApplication.musicBinderInterface?.getNowSongData()?.let { it ->
binding.tvSongName.text = it.name
song = it
}
}

// 添加到本地我喜欢
binding.itemAddLocalMyFavorite.setOnClickListener {
song?.let { data ->
MyFavorite.addSong(data)
toast("添加成功")
override fun initListener() {
binding.apply {
// 添加到本地我喜欢
itemAddLocalMyFavorite.setOnClickListener {
song?.let { data ->
MyFavorite.addSong(data)
dismiss()
}
}
}

// 歌曲信息
binding.itemSongInfo.setOnClickListener {
MyApplication.musicBinderInterface?.getNowSongData()?.let { it1 ->
SongInfoDialog(context, it1).show()
// 歌曲信息
itemSongInfo.setOnClickListener {
MyApplication.musicBinderInterface?.getNowSongData()?.let { it1 ->
SongInfoDialog(context, it1).show()
}
// 自己消失
dismiss()
}
ivIncreasePitch.setOnClickListener {
MyApplication.musicBinderInterface?.increasePitchLevel()
refreshPitch()
}
ivDecreasePitch.setOnClickListener {
MyApplication.musicBinderInterface?.decreasePitchLevel()
refreshPitch()
}
// 播放历史
itemPlayHistory.setOnClickListener {
it.context.startActivity(Intent(it.context, PlayHistoryActivity::class.java))
}
// 反馈
itemFeedback.setOnClickListener {
val intent = Intent(MyApplication.context, FeedbackActivity::class.java)
// 从 Content 跳转 Activity 要加 FLAG
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MyApplication.context.startActivity(intent)
// 隐藏 Dialog
dismiss()
}
// 自己消失
dismiss()
}

binding.ivIncreasePitch.setOnClickListener {
MyApplication.musicBinderInterface?.increasePitchLevel()
refreshPitch()
}

binding.ivDecreasePitch.setOnClickListener {
MyApplication.musicBinderInterface?.decreasePitchLevel()
refreshPitch()
}
// 播放历史
binding.itemPlayHistory.setOnClickListener {
it.context.startActivity(Intent(it.context, PlayHistoryActivity::class.java))
}

// 反馈
binding.itemFeedback.setOnClickListener {
val intent = Intent(MyApplication.context, FeedbackActivity::class.java)
// 从 Content 跳转 Activity 要加 FLAG
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MyApplication.context.startActivity(intent)
// 隐藏 Dialog
dismiss()
}


}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.dirror.music.ui.dialog

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.adapter.PlaylistDialogAdapter
import com.dirror.music.databinding.DialogPlayListBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

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

Expand Down
Loading

0 comments on commit a95f409

Please sign in to comment.