diff --git a/app/build.gradle b/app/build.gradle index 6ae5d562..91235416 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/java/com/dirror/music/adapter/DetailPlaylistAdapter.kt b/app/src/main/java/com/dirror/music/adapter/DetailPlaylistAdapter.kt index 5008a9a9..16bceaa5 100644 --- a/app/src/main/java/com/dirror/music/adapter/DetailPlaylistAdapter.kt +++ b/app/src/main/java/com/dirror/music/adapter/DetailPlaylistAdapter.kt @@ -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 @@ -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 } } @@ -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) { diff --git a/app/src/main/java/com/dirror/music/manager/ActivityManager.kt b/app/src/main/java/com/dirror/music/manager/ActivityManager.kt index d0400429..41a531d8 100644 --- a/app/src/main/java/com/dirror/music/manager/ActivityManager.kt +++ b/app/src/main/java/com/dirror/music/manager/ActivityManager.kt @@ -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 */ diff --git a/app/src/main/java/com/dirror/music/manager/interfaces/ActivityManagerInterface.kt b/app/src/main/java/com/dirror/music/manager/interfaces/ActivityManagerInterface.kt index 90c36d51..28c796cf 100644 --- a/app/src/main/java/com/dirror/music/manager/interfaces/ActivityManagerInterface.kt +++ b/app/src/main/java/com/dirror/music/manager/interfaces/ActivityManagerInterface.kt @@ -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) diff --git a/app/src/main/java/com/dirror/music/music/local/MyFavorite.kt b/app/src/main/java/com/dirror/music/music/local/MyFavorite.kt index fa92c114..8465bba7 100644 --- a/app/src/main/java/com/dirror/music/music/local/MyFavorite.kt +++ b/app/src/main/java/com/dirror/music/music/local/MyFavorite.kt @@ -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 @@ -21,7 +22,7 @@ object MyFavorite { thread { val data = ArrayList() for (myFavorite in myFavoriteDao.loadAll()) { - data.add(myFavorite.songData) + data.add(0, myFavorite.songData) } success.invoke(data) } @@ -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("已经添加过了哦~") + } } } diff --git a/app/src/main/java/com/dirror/music/ui/activity/MainActivity.kt b/app/src/main/java/com/dirror/music/ui/activity/MainActivity.kt index 8ca8182a..191bc0f9 100644 --- a/app/src/main/java/com/dirror/music/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/dirror/music/ui/activity/MainActivity.kt @@ -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 { diff --git a/app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity.kt b/app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity.kt index a32cd462..6b632808 100644 --- a/app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity.kt +++ b/app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity.kt @@ -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 @@ -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) @@ -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) @@ -160,6 +164,7 @@ class PlaylistActivity : AppCompatActivity() { SOURCE_LOCAL -> { // 我喜欢 if (id == 0L) { + initPlaylistInfo(id) MyFavorite.read { initRecycleView(it, PLAYLIST_TAG_MY_FAVORITE) } @@ -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 @@ -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) { diff --git a/app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt b/app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt index 781f86cb..639d90cc 100644 --- a/app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt +++ b/app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt @@ -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) + } } diff --git a/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt index 1e854a22..829961e8 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt @@ -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 @@ -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() diff --git a/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt index e6e4564d..e6d183dc 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt @@ -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() } - - } /** diff --git a/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt index cea54a8b..8f7d3ce7 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt @@ -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) { diff --git a/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt index 835bd40a..4b01669f 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt @@ -1,25 +1,21 @@ package com.dirror.music.ui.dialog import android.app.Activity -import android.app.Dialog import android.content.Context -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.data.PLAYLIST_TAG_MY_FAVORITE 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.util.Secure import com.dirror.music.util.toast -import com.google.android.material.bottomsheet.BottomSheetDialog class SongMenuDialog @JvmOverloads - constructor(context: Context, private val tag: Int = PLAYLIST_TAG_NORMAL) : BaseBottomSheetDialog(context) { + constructor(context: Context, + private val activity: Activity, + private val songData: StandardSongData, + private val tag: Int = PLAYLIST_TAG_NORMAL) : BaseBottomSheetDialog(context) { private var binding = DialogSongMenuBinding.inflate(layoutInflater) @@ -27,18 +23,14 @@ class SongMenuDialog setContentView(binding.root) } - private lateinit var songData: StandardSongData - private lateinit var activity: Activity - - - override fun initView() { - super.initView() - - } - override fun initListener() { super.initListener() binding.apply { + // 添加到本地我喜欢 + itemAddLocalMyFavorite.setOnClickListener { + MyFavorite.addSong(songData) + dismiss() + } // 歌曲信息 itemSongInfo.setOnClickListener { // toast("歌曲信息 ${ songData.id }") @@ -56,17 +48,10 @@ class SongMenuDialog if (tag == PLAYLIST_TAG_MY_FAVORITE) { MyFavorite.deleteById(songData.id) toast("删除成功") + dismiss() } } } } - fun setSongData(standardSongData: StandardSongData) { - songData = standardSongData - } - - fun setActivity(activity: Activity) { - this.activity = activity - } - } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_web.xml b/app/src/main/res/layout/activity_web.xml index 10d2f819..d4bc21f5 100644 --- a/app/src/main/res/layout/activity_web.xml +++ b/app/src/main/res/layout/activity_web.xml @@ -20,6 +20,8 @@ android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="0dp" + android:scrollbars="none" + android:overScrollMode="never" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/dialog_song_menu.xml b/app/src/main/res/layout/dialog_song_menu.xml index 33c356bf..b434c021 100644 --- a/app/src/main/res/layout/dialog_song_menu.xml +++ b/app/src/main/res/layout/dialog_song_menu.xml @@ -16,6 +16,12 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> + +