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

Commit

Permalink
2021年1月23日11:45:14
Browse files Browse the repository at this point in the history
  • Loading branch information
Moriafly committed Jan 23, 2021
1 parent 766a0ab commit 8d61e08
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 39 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 286
versionCode 287
versionName "2.4.0-alpha"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ 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
import com.dirror.music.ui.dialog.SongMenuDialog
Expand All @@ -20,7 +22,11 @@ import com.dirror.music.util.parseArtist
/**
* 歌单适配器
*/
class DetailPlaylistAdapter(private val songDataList: ArrayList<StandardSongData>, private val activity: Activity): RecyclerView.Adapter<DetailPlaylistAdapter.ViewHolder>() {
class DetailPlaylistAdapter
@JvmOverloads
constructor(private val songDataList: ArrayList<StandardSongData>,
private val activity: Activity,
private val tag: Int = PLAYLIST_TAG_NORMAL): RecyclerView.Adapter<DetailPlaylistAdapter.ViewHolder>() {

inner class ViewHolder(view: View): RecyclerView.ViewHolder(view) {
val tvNumber: TextView = view.findViewById(R.id.tvNumber)
Expand Down Expand Up @@ -58,15 +64,15 @@ class DetailPlaylistAdapter(private val songDataList: ArrayList<StandardSongData
}
// 更多点击,每首歌右边的三点菜单
ivMore.setOnClickListener {
SongMenuDialog(it.context).apply {
SongMenuDialog(it.context, tag).apply {
setSongData(song)
setActivity(activity)
show()
}
}
// 长按
clSong.setOnLongClickListener {
SongMenuDialog(it.context).apply {
SongMenuDialog(it.context, tag).apply {
setSongData(song)
setActivity(activity)
show()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/dirror/music/data/PlaylistTag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.dirror.music.data

const val PLAYLIST_TAG_NORMAL = 0
const val PLAYLIST_TAG_MY_FAVORITE = 1
19 changes: 19 additions & 0 deletions app/src/main/java/com/dirror/music/music/local/MyFavorite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ object MyFavorite {
}
}

/**
* 删除一首歌
*/
@TestOnly
fun delete(songData: StandardSongData) {
thread {
myFavoriteDao.delete(MyFavoriteData(songData))
}
}

/**
* 通过 id 删除一首歌
*/
fun deleteById(id: String) {
thread {
myFavoriteDao.deleteById(id)
}
}

}
6 changes: 4 additions & 2 deletions app/src/main/java/com/dirror/music/room/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(version = 1, entities = [MyFavoriteData::class])
@Database(version = AppDatabase.DATABASE_VERSION, entities = [MyFavoriteData::class])
abstract class AppDatabase: RoomDatabase() {

abstract fun myFavoriteDao(): MyFavoriteDao

companion object {

const val DATABASE_VERSION = 1

private var instance: AppDatabase? = null

@Synchronized
Expand All @@ -21,7 +23,7 @@ abstract class AppDatabase: RoomDatabase() {
}
return Room.databaseBuilder(context.applicationContext,
AppDatabase::class.java, "app_database")
.fallbackToDestructiveMigration() // 上线移除
// .fallbackToDestructiveMigration() // 上线移除
.build().apply {
instance = this
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/dirror/music/room/MyFavoriteDao.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dirror.music.room

import androidx.room.*
import com.dirror.music.music.standard.data.StandardSongData

@Dao
interface MyFavoriteDao {
Expand All @@ -18,4 +17,7 @@ interface MyFavoriteDao {
@Delete
fun delete(myFavoriteData: MyFavoriteData)

@Query("delete from MyFavoriteData where id = :id")
fun deleteById(id: String): Int

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.databinding.ActivityAbout2Binding
import com.dirror.music.ui.dialog.AppInfoDialog
import com.dirror.music.util.Secure
import com.dirror.music.util.UpdateUtil
import com.dirror.music.util.getVisionCode
Expand Down Expand Up @@ -64,6 +65,11 @@ class AboutActivity2 : AppCompatActivity() {
itemHistoryVersion.setOnClickListener { MyApplication.activityManager.startWebActivity(this@AboutActivity2, HISTORY_VERSION) }
// 使用开源项目
itemOpenSourceCode.setOnClickListener { startActivity(Intent(this@AboutActivity2, OpenSourceActivity::class.java)) }
// ivLogo
ivLogo.setOnLongClickListener {
AppInfoDialog(this@AboutActivity2).show()
return@setOnLongClickListener true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.bumptech.glide.request.RequestOptions
import com.dirror.music.MyApplication
import com.dirror.music.R
import com.dirror.music.adapter.DetailPlaylistAdapter
import com.dirror.music.data.PLAYLIST_TAG_MY_FAVORITE
import com.dirror.music.data.PLAYLIST_TAG_NORMAL
import com.dirror.music.databinding.ActivityPlaylistBinding
import com.dirror.music.music.local.MyFavorite
import com.dirror.music.music.netease.Playlist
Expand Down Expand Up @@ -159,7 +161,7 @@ class PlaylistActivity : AppCompatActivity() {
// 我喜欢
if (id == 0L) {
MyFavorite.read {
initRecycleView(it)
initRecycleView(it, PLAYLIST_TAG_MY_FAVORITE)
}
}
}
Expand Down Expand Up @@ -236,12 +238,12 @@ class PlaylistActivity : AppCompatActivity() {
}

@SuppressLint("SetTextI18n")
private fun initRecycleView(songList: ArrayList<StandardSongData>) {
private fun initRecycleView(songList: ArrayList<StandardSongData>, tag: Int = PLAYLIST_TAG_NORMAL) {
runOnMainThread {
binding.clLoading.visibility = View.GONE
binding.rvPlaylist.layoutManager = LinearLayoutManager(this@PlaylistActivity)
// 改变全局变量
detailPlaylistAdapter = DetailPlaylistAdapter(songList, this@PlaylistActivity)
detailPlaylistAdapter = DetailPlaylistAdapter(songList, this@PlaylistActivity, tag)
binding.rvPlaylist.adapter = detailPlaylistAdapter
binding.tvPlayAll.text = "播放全部(${songList.size})"
binding.lottieLoading.pauseAnimation()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/dirror/music/ui/activity/WebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import com.dirror.music.databinding.ActivityWebBinding

class WebActivity : AppCompatActivity() {

companion object {
const val EXTRA_TITLE = "extra_title"
}

private lateinit var binding: ActivityWebBinding

@SuppressLint("SetJavaScriptEnabled")
Expand All @@ -21,6 +25,7 @@ class WebActivity : AppCompatActivity() {
setContentView(binding.root)

val extraWebUrlStr = intent.getStringExtra("extra_webUrlStr")
val extraTitle = intent.getStringExtra(EXTRA_TITLE)

binding.webView.settings.javaScriptEnabled = true // 禁用 JavaScript
binding.webView.settings.allowFileAccess = false // 禁止访问私有文件数据
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/dirror/music/ui/dialog/AppInfoDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.dirror.music.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
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.util.Secure
import com.dirror.music.util.defaultTypeface
import com.dirror.music.util.getVisionCode
import com.dirror.music.util.getVisionName

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

val binding = DialogTextInfoBinding.inflate(layoutInflater)

init {
setContentView(binding.root)
}

@SuppressLint("SetTextI18n")
override fun initView() {
super.initView()
binding.apply {
tvText.typeface = defaultTypeface(MyApplication.context)
tvText.text = """
[app.ver ] ${getVisionName()}
[app.build ] ${getVisionCode()}
[is debug ] ${Secure.isDebug()}
[foyou.ver ] ${FoyouLibrary.VERSION}
[database.ver] ${AppDatabase.DATABASE_VERSION}
[model ] ${Build.MODEL}
[android.ver ] ${Build.VERSION.RELEASE}
[android.sdk ] ${Build.VERSION.SDK_INT}
""".trimIndent()
}
}

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

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.ViewGroup
import com.dirror.music.R
import com.google.android.material.bottomsheet.BottomSheetDialog

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

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window?.setGravity(Gravity.BOTTOM)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
window?.setWindowAnimations(R.style.dialog_animation)
initView()
initListener()
}

open fun initView() {

}

open fun initListener() {

}

}
17 changes: 4 additions & 13 deletions app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ import com.dirror.music.adapter.PlaylistDialogAdapter
import com.dirror.music.databinding.DialogPlayListBinding
import com.google.android.material.bottomsheet.BottomSheetDialog

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

private var binding: DialogPlayListBinding = DialogPlayListBinding.inflate(layoutInflater)

constructor(context: Context) : this(context, 0)

constructor(context: Context, themeResId: Int) : super(context, R.style.style_default_dialog) {
init {
setContentView(binding.root)
// 设置显示位置
window?.setGravity(Gravity.BOTTOM)
// 设置大小
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
window?.setWindowAnimations(R.style.dialog_animation)
}

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

override fun initView() {
super.initView()
binding.rvPlaylist.layoutManager = LinearLayoutManager(context)
MyApplication.musicBinderInterface?.getPlaylist()?.let {
binding.rvPlaylist.adapter = PlaylistDialogAdapter(it)
binding.tvPlaylist.text = this.context.getString(R.string.playlist_number, it.size)
}

}
}
27 changes: 16 additions & 11 deletions app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,36 @@ 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(context: Context) : Dialog(context, R.style.style_default_dialog) {
class SongMenuDialog
@JvmOverloads
constructor(context: Context, private val tag: Int = PLAYLIST_TAG_NORMAL) : BaseBottomSheetDialog(context) {

private var binding = DialogSongMenuBinding.inflate(layoutInflater)

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

private lateinit var songData: StandardSongData
private lateinit var activity: Activity

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

override fun initView() {
super.initView()

}

private fun initListener() {
override fun initListener() {
super.initListener()
binding.apply {
// 歌曲信息
itemSongInfo.setOnClickListener {
Expand All @@ -47,10 +53,9 @@ class SongMenuDialog(context: Context) : Dialog(context, R.style.style_default_d
}
// 歌曲删除
itemDeleteSong.setOnClickListener {
if (Secure.isDebug()) {
toast("开发中")
} else {
toast("测试")
if (tag == PLAYLIST_TAG_MY_FAVORITE) {
MyFavorite.deleteById(songData.id)
toast("删除成功")
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/dirror/music/util/TopLevelFuncation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.os.Handler
Expand Down Expand Up @@ -163,4 +164,8 @@ fun openJim(context: Context) {
} catch (e: Exception) {
toast("失败")
}
}

fun defaultTypeface(context: Context): Typeface {
return Typeface.createFromAsset(context.assets, "fonts/Moriafly-Regular.ttf")
}
6 changes: 1 addition & 5 deletions app/src/main/res/layout/dialog_song_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_dialog">
android:background="@drawable/bg_slide_layout">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="vertical"
android:paddingTop="16dp"
android:paddingBottom="16dp"
Expand Down
Loading

0 comments on commit 8d61e08

Please sign in to comment.