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

Commit 92af6e6

Browse files
committed
3.11.4
修复 API 失效引起的拉取歌单 / 搜索失败的问题 当用户配置了网易云 API 时, 这些接口也会使用这个配置 优化横屏状态栏、导航栏显示区域适配 优化加载歌单失败提示语
1 parent 64fa057 commit 92af6e6

File tree

11 files changed

+104
-77
lines changed

11 files changed

+104
-77
lines changed

.idea/dictionaries/24568.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UPDATE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.11.4 2021年11月18日
2+
修复 API 失效引起的拉取歌单 / 搜索失败的问题
3+
当用户配置了网易云 API 时, 这些接口也会使用这个配置
4+
优化横屏状态栏、导航栏显示区域适配
5+
优化加载歌单失败提示语
6+
17
3.11.3 2021年11月13日
28
修复本地歌曲播放失败问题,感谢 kqwyf 的反馈
39
更新 Kotlin 版本至 1.5.31

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ android {
2929
applicationId "com.dirror.music"
3030
minSdkVersion 21
3131
targetSdkVersion 30
32-
versionCode 750
33-
versionName "3.11.3"
32+
versionCode 751
33+
versionName "3.11.4"
3434

3535
multiDexEnabled true
3636

app/release/output-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
{
1111
"type": "SINGLE",
1212
"filters": [],
13-
"versionCode": 750,
14-
"versionName": "3.11.3",
13+
"versionCode": 751,
14+
"versionName": "3.11.4",
1515
"outputFile": "app-release.apk"
1616
}
1717
]

app/src/main/java/com/dirror/music/App.kt

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* <https://www.gnu.org/licenses/why-not-lgpl.html>.
2323
*/
2424

25+
@file:Suppress("unused", "UNUSED_PARAMETER")
26+
2527
package com.dirror.music
2628

2729
import android.annotation.SuppressLint
@@ -52,36 +54,8 @@ import kotlin.coroutines.EmptyCoroutineContext
5254
* @since 2021-7-13
5355
*/
5456
@Keep
55-
@SuppressLint("StaticFieldLeak")
5657
class App : Application() {
5758

58-
companion object {
59-
60-
private val TAG = this::class.java.simpleName
61-
62-
const val UM_APP_KEY = "5fb38e09257f6b73c0961382"
63-
64-
lateinit var mmkv: MMKV
65-
66-
lateinit var context: Context
67-
68-
var musicController = MutableLiveData<MusicService.MusicController?>()
69-
70-
val musicServiceConnection by lazy { MusicServiceConnection() } // 音乐服务连接
71-
72-
@Deprecated("过时,使用 StartActivity")
73-
lateinit var activityManager: ActivityManager
74-
75-
lateinit var cloudMusicManager: CloudMusicManager
76-
77-
val coroutineScope = CoroutineScope(EmptyCoroutineContext)
78-
79-
/** 数据库 */
80-
lateinit var appDatabase: AppDatabase
81-
82-
lateinit var realIP: String
83-
}
84-
8559
override fun onCreate() {
8660
super.onCreate()
8761
// 全局 context
@@ -150,4 +124,32 @@ class App : Application() {
150124
bindService(intent, musicServiceConnection, BIND_AUTO_CREATE)
151125
}
152126

127+
companion object {
128+
129+
private val TAG = this::class.java.simpleName
130+
131+
const val UM_APP_KEY = "5fb38e09257f6b73c0961382"
132+
133+
lateinit var mmkv: MMKV
134+
135+
@SuppressLint("StaticFieldLeak")
136+
lateinit var context: Context
137+
138+
var musicController = MutableLiveData<MusicService.MusicController?>()
139+
140+
val musicServiceConnection by lazy { MusicServiceConnection() } // 音乐服务连接
141+
142+
@Deprecated("过时,使用 StartActivity")
143+
lateinit var activityManager: ActivityManager
144+
145+
lateinit var cloudMusicManager: CloudMusicManager
146+
147+
val coroutineScope = CoroutineScope(EmptyCoroutineContext)
148+
149+
/** 数据库 */
150+
lateinit var appDatabase: AppDatabase
151+
152+
lateinit var realIP: String
153+
}
154+
153155
}

app/src/main/java/com/dirror/music/ui/player/PlayerActivity.kt

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ import com.dso.ext.colorMix
7979
*/
8080
class PlayerActivity : SlideBackActivity() {
8181

82-
companion object {
83-
private const val MUSIC_BROADCAST_ACTION = "com.dirror.music.MUSIC_BROADCAST"
84-
private const val DELAY_MILLIS = 500L
85-
86-
// Handle 消息,播放进度
87-
private const val MSG_PROGRESS = 0
88-
89-
// 动画循环时长
90-
private const val DURATION_CD = 27_500L
91-
private const val ANIMATION_REPEAT_COUNTS = -1
92-
private const val ANIMATION_PROPERTY_NAME = "rotation"
93-
}
94-
9582
private lateinit var binding: ActivityPlayerBinding
9683

9784
// 是否是横屏状态
@@ -129,7 +116,10 @@ class PlayerActivity : SlideBackActivity() {
129116
override fun initBinding() {
130117
binding = ActivityPlayerBinding.inflate(layoutInflater)
131118
binding.root.setOnApplyWindowInsetsListener { _, insets ->
132-
playViewModel.navigationBarHeight.value = insets.systemWindowInsetBottom
119+
playViewModel.systemWindowInsetTop.value = insets.systemWindowInsetTop
120+
playViewModel.systemWindowInsetLeft.value = insets.systemWindowInsetLeft
121+
playViewModel.systemWindowInsetRight.value = insets.systemWindowInsetRight
122+
playViewModel.systemWindowInsetBottom.value = insets.systemWindowInsetBottom
133123
insets
134124
}
135125
setContentView(binding.root)
@@ -153,19 +143,13 @@ class PlayerActivity : SlideBackActivity() {
153143
val configuration = this.resources.configuration //获取设置的配置信息
154144
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
155145
isLandScape = true
156-
// 横屏隐藏状态栏
157-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
158-
window.insetsController?.hide(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE)
159-
}
160-
}
161-
// 页面状态栏适配
162-
binding.titleBar?.let {
163-
(it.layoutParams as ConstraintLayout.LayoutParams).apply {
164-
topToTop = ConstraintLayout.LayoutParams.PARENT_ID
165-
topMargin = getStatusBarHeight(window, this@PlayerActivity)
166-
}
146+
// // 横屏隐藏状态栏
147+
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
148+
// window.insetsController?.hide(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE)
149+
// }
167150
}
168151

152+
169153
binding.apply {
170154
// 时长右对齐
171155
ttvDuration.setAlignRight()
@@ -527,11 +511,6 @@ class PlayerActivity : SlideBackActivity() {
527511
// 颜色观察
528512
color.observe(this@PlayerActivity, {
529513
binding.apply {
530-
// if (heart.value == true) {
531-
// ivLike.setColorFilter(R.color.colorAppThemeColor.asColor(this@PlayerActivity))
532-
// } else {
533-
// ivLike.setColorFilter(it)
534-
// }
535514
val darkMode = DarkThemeUtil.isDarkTheme(this@PlayerActivity)
536515
val secondColor = if (darkMode) {
537516
Color.rgb(45, 45, 45)
@@ -544,11 +523,6 @@ class PlayerActivity : SlideBackActivity() {
544523
it.colorMix(Color.WHITE, Color.WHITE, Color.WHITE)
545524
}
546525

547-
548-
// ivLyricsBackground.setImageDrawable(GradientDrawable().apply{
549-
// this.gradientType = GradientDrawable.LINEAR_GRADIENT // 指定渲染角度
550-
// this.colors = intArrayOf(mixColor, secondColor, secondColor, secondColor) // 指定渐变色
551-
// })
552526
}
553527

554528
})
@@ -603,13 +577,35 @@ class PlayerActivity : SlideBackActivity() {
603577
playViewModel.normalColor.value?.let { it1 -> binding.ivLike.setColorFilter(it1) }
604578
}
605579
})
606-
607-
navigationBarHeight.observe(this@PlayerActivity, {
608-
binding.clBottom.updateLayoutParams<ConstraintLayout.LayoutParams> {
609-
bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
610-
bottomMargin = it
580+
systemWindowInsetTop.observe(this@PlayerActivity, { top ->
581+
// 页面状态栏适配
582+
binding.titleBar?.let {
583+
(it.layoutParams as ConstraintLayout.LayoutParams).apply {
584+
topToTop = ConstraintLayout.LayoutParams.PARENT_ID
585+
topMargin = top
586+
}
587+
}
588+
binding.llBase?.let {
589+
it.updateLayoutParams<ConstraintLayout.LayoutParams> {
590+
topMargin = top
591+
}
611592
}
612593
})
594+
systemWindowInsetBottom.observe(this@PlayerActivity, { bottom ->
595+
if (isLandScape) {
596+
binding.llBase?.let {
597+
it.updateLayoutParams<ConstraintLayout.LayoutParams> {
598+
bottomMargin = bottom
599+
}
600+
}
601+
} else {
602+
binding.clBottom.updateLayoutParams<ConstraintLayout.LayoutParams> {
603+
bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
604+
bottomMargin = bottom
605+
}
606+
}
607+
608+
})
613609
}
614610
}
615611

@@ -671,4 +667,17 @@ class PlayerActivity : SlideBackActivity() {
671667
return super.onKeyDown(keyCode, event)
672668
}
673669

670+
companion object {
671+
private const val MUSIC_BROADCAST_ACTION = "com.dirror.music.MUSIC_BROADCAST"
672+
private const val DELAY_MILLIS = 500L
673+
674+
// Handle 消息,播放进度
675+
private const val MSG_PROGRESS = 0
676+
677+
// 动画循环时长
678+
private const val DURATION_CD = 27_500L
679+
private const val ANIMATION_REPEAT_COUNTS = -1
680+
private const val ANIMATION_PROPERTY_NAME = "rotation"
681+
}
682+
674683
}

app/src/main/java/com/dirror/music/ui/player/PlayerViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class PlayerViewModel: ViewModel() {
3030
var rotation = 0f
3131
var rotationBackground = 0f
3232

33-
/** 状态栏高度 */
34-
var navigationBarHeight = MutableLiveData<Int>()
33+
val systemWindowInsetTop = MutableLiveData<Int>()
34+
val systemWindowInsetLeft = MutableLiveData<Int>()
35+
val systemWindowInsetRight = MutableLiveData<Int>()
36+
val systemWindowInsetBottom = MutableLiveData<Int>()
3537

3638
// 播放模式
3739
var playMode = MutableLiveData<Int>().also {

app/src/main/java/com/dirror/music/ui/playlist/SongPlaylistViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.dirror.music.ui.playlist
33
import android.util.Log
44
import androidx.lifecycle.MutableLiveData
55
import androidx.lifecycle.ViewModel
6+
import androidx.lifecycle.viewModelScope
67
import com.dirror.music.data.SearchType
78
import com.dirror.music.manager.User
89
import com.dirror.music.music.local.MyFavorite
@@ -136,11 +137,11 @@ class SongPlaylistViewModel : ViewModel() {
136137
}
137138

138139
private fun getPlaylist(id: Long, useCache: Boolean) {
139-
GlobalScope.launch {
140+
viewModelScope.launch {
140141
Api.getPlayList(id, useCache).let { packed ->
141142
withContext(Dispatchers.Main) {
142143
if (packed.songs.isEmpty()) {
143-
toast("歌单内容获取失败")
144+
toast("歌单内容获取失败,尝试更换 NeteaseCloudMusicApi")
144145
}
145146
songList.value = packed.songs
146147
Log.d(TAG, "getPlaylist finished, isCache:${packed.isCache}, size:${packed.songs.size}")

0 commit comments

Comments
 (0)