Skip to content

Commit 6959a80

Browse files
committed
本地歌词提示
1 parent 00cc1d1 commit 6959a80

File tree

11 files changed

+134
-98
lines changed

11 files changed

+134
-98
lines changed

app/src/main/java/remix/myplayer/misc/menu/AudioPopupListener.kt

+87-68
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import remix.myplayer.helper.EQHelper
1616
import remix.myplayer.helper.MusicServiceRemote.getCurrentSong
1717
import remix.myplayer.service.Command
1818
import remix.myplayer.theme.Theme.getBaseDialog
19+
import remix.myplayer.ui.ViewCommon
1920
import remix.myplayer.ui.activity.PlayerActivity
2021
import remix.myplayer.ui.dialog.AddtoPlayListDialog
2122
import remix.myplayer.ui.dialog.TimerDialog
@@ -43,74 +44,10 @@ class AudioPopupListener(activity: PlayerActivity, private val song: Song) :
4344
val activity = ref.get() ?: return true
4445
when (item.itemId) {
4546
R.id.menu_lyric -> {
46-
val alreadyIgnore = (SPUtil
47-
.getValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(),
48-
SPUtil.LYRIC_KEY.LYRIC_DEFAULT) == SPUtil.LYRIC_KEY.LYRIC_IGNORE)
49-
50-
val lyricFragment = ref.get()?.lyricFragment ?: return true
51-
getBaseDialog(ref.get())
52-
.items(
53-
getString(R.string.embedded_lyric),
54-
getString(R.string.local),
55-
getString(R.string.kugou),
56-
getString(R.string.netease),
57-
getString(R.string.qq),
58-
getString(R.string.select_lrc),
59-
getString(if (!alreadyIgnore) R.string.ignore_lrc else R.string.cancel_ignore_lrc),
60-
getString(R.string.lyric_adjust_font_size),
61-
getString(R.string.change_offset))
62-
.itemsCallback { dialog, itemView, position, text ->
63-
when (position) {
64-
0, 1, 2, 3, 4 -> { //0内嵌 1本地 2酷狗 3网易 4qq
65-
SPUtil.putValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(), position + 2)
66-
lyricFragment.updateLrc(song, true)
67-
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
68-
}
69-
5 -> { //手动选择歌词
70-
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
71-
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension("lrc")
72-
addCategory(Intent.CATEGORY_OPENABLE)
73-
}
74-
Util.startActivityForResultSafely(
75-
activity,
76-
intent,
77-
PlayerActivity.REQUEST_SELECT_LYRIC
78-
)
79-
}
80-
6 -> { //忽略或者取消忽略
81-
getBaseDialog(activity)
82-
.title(if (!alreadyIgnore) R.string.confirm_ignore_lrc else R.string.confirm_cancel_ignore_lrc)
83-
.negativeText(R.string.cancel)
84-
.positiveText(R.string.confirm)
85-
.onPositive { dialog1, which ->
86-
if (!alreadyIgnore) {//忽略
87-
SPUtil.putValue(activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
88-
SPUtil.LYRIC_KEY.LYRIC_IGNORE)
89-
lyricFragment.updateLrc(song)
90-
} else {//取消忽略
91-
SPUtil.putValue(activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
92-
SPUtil.LYRIC_KEY.LYRIC_DEFAULT)
93-
lyricFragment.updateLrc(song)
94-
}
95-
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
96-
}
97-
.show()
98-
}
99-
7 -> { //字体大小调整
100-
getBaseDialog(ref.get())
101-
.items(R.array.lyric_font_size)
102-
.itemsCallback { dialog, itemView, position, text ->
103-
lyricFragment.setLyricScalingFactor(position)
104-
}
105-
.show()
106-
}
107-
8 -> { //歌词时间轴调整
108-
activity.showLyricOffsetView()
109-
}
110-
}
111-
112-
}
113-
.show()
47+
ViewCommon.showLocalLyricTip(activity) {
48+
onClickLyric(activity)
49+
}
50+
return true
11451
}
11552
R.id.menu_edit -> {
11653
if (!song.isLocal()) {
@@ -204,4 +141,86 @@ class AudioPopupListener(activity: PlayerActivity, private val song: Song) :
204141
}
205142
return true
206143
}
144+
145+
private fun onClickLyric(activity: PlayerActivity) {
146+
val alreadyIgnore = (SPUtil
147+
.getValue(
148+
ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(),
149+
SPUtil.LYRIC_KEY.LYRIC_DEFAULT
150+
) == SPUtil.LYRIC_KEY.LYRIC_IGNORE)
151+
152+
val lyricFragment = ref.get()?.lyricFragment ?: return
153+
getBaseDialog(ref.get())
154+
.items(
155+
getString(R.string.embedded_lyric),
156+
getString(R.string.local),
157+
getString(R.string.kugou),
158+
getString(R.string.netease),
159+
getString(R.string.qq),
160+
getString(R.string.select_lrc),
161+
getString(if (!alreadyIgnore) R.string.ignore_lrc else R.string.cancel_ignore_lrc),
162+
getString(R.string.lyric_adjust_font_size),
163+
getString(R.string.change_offset)
164+
)
165+
.itemsCallback { dialog, itemView, position, text ->
166+
when (position) {
167+
0, 1, 2, 3, 4 -> { //0内嵌 1本地 2酷狗 3网易 4qq
168+
SPUtil.putValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(), position + 2)
169+
lyricFragment.updateLrc(song, true)
170+
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
171+
}
172+
173+
5 -> { //手动选择歌词
174+
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
175+
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension("lrc")
176+
addCategory(Intent.CATEGORY_OPENABLE)
177+
}
178+
Util.startActivityForResultSafely(
179+
activity,
180+
intent,
181+
PlayerActivity.REQUEST_SELECT_LYRIC
182+
)
183+
}
184+
185+
6 -> { //忽略或者取消忽略
186+
getBaseDialog(activity)
187+
.title(if (!alreadyIgnore) R.string.confirm_ignore_lrc else R.string.confirm_cancel_ignore_lrc)
188+
.negativeText(R.string.cancel)
189+
.positiveText(R.string.confirm)
190+
.onPositive { dialog1, which ->
191+
if (!alreadyIgnore) {//忽略
192+
SPUtil.putValue(
193+
activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
194+
SPUtil.LYRIC_KEY.LYRIC_IGNORE
195+
)
196+
lyricFragment.updateLrc(song)
197+
} else {//取消忽略
198+
SPUtil.putValue(
199+
activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
200+
SPUtil.LYRIC_KEY.LYRIC_DEFAULT
201+
)
202+
lyricFragment.updateLrc(song)
203+
}
204+
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
205+
}
206+
.show()
207+
}
208+
209+
7 -> { //字体大小调整
210+
getBaseDialog(ref.get())
211+
.items(R.array.lyric_font_size)
212+
.itemsCallback { dialog, itemView, position, text ->
213+
lyricFragment.setLyricScalingFactor(position)
214+
}
215+
.show()
216+
}
217+
218+
8 -> { //歌词时间轴调整
219+
activity.showLyricOffsetView()
220+
}
221+
}
222+
223+
}
224+
.show()
225+
}
207226
}

app/src/main/java/remix/myplayer/theme/Theme.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import androidx.annotation.FloatRange;
2222
import androidx.annotation.NonNull;
2323
import androidx.annotation.Nullable;
24-
import androidx.appcompat.app.AppCompatDelegate;
2524
import androidx.appcompat.content.res.AppCompatResources;
2625
import androidx.core.graphics.drawable.DrawableCompat;
2726
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
@@ -249,7 +248,7 @@ public static MaterialDialog.Builder getBaseDialog(Context context) {
249248

250249
}
251250

252-
public static void setLightNavigationbarAuto(Activity activity, boolean enabled) {
251+
public static void setLightNavigationBarAuto(Activity activity, boolean enabled) {
253252
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
254253
final View decorView = activity.getWindow().getDecorView();
255254
int systemUiVisibility = decorView.getSystemUiVisibility();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package remix.myplayer.ui
2+
3+
import android.content.Context
4+
import remix.myplayer.R
5+
import remix.myplayer.theme.Theme
6+
import remix.myplayer.util.SPUtil
7+
8+
object ViewCommon {
9+
fun showLocalLyricTip(context: Context, action: () -> Unit) {
10+
if (!SPUtil.getValue(
11+
context,
12+
SPUtil.LYRIC_KEY.NAME,
13+
SPUtil.LYRIC_KEY.LYRIC_LOCAL_TIP_SHOWN,
14+
false
15+
)
16+
) {
17+
SPUtil.putValue(context, SPUtil.LYRIC_KEY.NAME, SPUtil.LYRIC_KEY.LYRIC_LOCAL_TIP_SHOWN, true)
18+
Theme.getBaseDialog(context)
19+
.negativeText(R.string.cancel)
20+
.positiveText(R.string.confirm)
21+
.onPositive { dialog, which ->
22+
action.invoke()
23+
}
24+
.content(R.string.local_lyric_tip)
25+
.show()
26+
} else {
27+
action.invoke()
28+
}
29+
}
30+
31+
}

app/src/main/java/remix/myplayer/ui/activity/PlayerActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class PlayerActivity : BaseMusicActivity() {
186186
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ThemeStore.sColoredNavigation) {
187187
val navigationColor = ThemeStore.getBackgroundColorMain(this)
188188
window.navigationBarColor = navigationColor
189-
Theme.setLightNavigationbarAuto(this, ColorUtil.isColorLight(navigationColor))
189+
Theme.setLightNavigationBarAuto(this, ColorUtil.isColorLight(navigationColor))
190190
}
191191
}
192192

app/src/main/java/remix/myplayer/ui/activity/SettingActivity.kt

+8-26
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import remix.myplayer.theme.Theme
7070
import remix.myplayer.theme.Theme.getBaseDialog
7171
import remix.myplayer.theme.ThemeStore
7272
import remix.myplayer.theme.TintHelper
73+
import remix.myplayer.ui.ViewCommon
7374
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_LIBRARY
7475
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_RECREATE
7576
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_REFRESH_ADAPTER
@@ -112,16 +113,13 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,
112113

113114
//是否需要刷新library
114115
private var needRefreshLibrary: Boolean = false
115-
116-
// //是否从主题颜色选择对话框返回
117-
// private boolean mFromColorChoose = false;
116+
118117
//缓存大小
119118
private var cacheSize: Long = 0
120119
private val handler: MsgHandler by lazy {
121120
MsgHandler(this)
122121
}
123-
124-
122+
125123
private val scanSize = intArrayOf(0, 500 * KB, MB, 2 * MB, 5 * MB)
126124
private var originalAlbumChoice: String? = null
127125

@@ -130,25 +128,7 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,
130128
private var pendingExportPlaylist: String? = null
131129

132130
private var blackList: Set<String> = emptySet()
133-
134-
//尝试从uri获取文件夹absolutePath
135-
//fun getFolderPath(documentFile: DocumentFile?): String? {
136-
// if (documentFile == null) {
137-
// return null
138-
// }
139-
//
140-
// val name = documentFile.name ?: return null
141-
// val parent = documentFile.parentFile ?: return name
142-
//
143-
// val parentPath = getFolderPath(parent)
144-
// return if (parentPath != null) {
145-
// "$parentPath/$name"
146-
// } else {
147-
// name
148-
// }
149-
//}
150-
151-
131+
152132
override fun onCreate(savedInstanceState: Bundle?) {
153133
super.onCreate(savedInstanceState)
154134

@@ -920,9 +900,11 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,
920900
* 歌词搜索优先级
921901
*/
922902
private fun configLyricPriority() {
923-
LyricPriorityDialog.newInstance().show(
903+
ViewCommon.showLocalLyricTip(this) {
904+
LyricPriorityDialog.newInstance().show(
924905
supportFragmentManager, "configLyricPriority"
925-
)
906+
)
907+
}
926908
}
927909

928910
/**

app/src/main/java/remix/myplayer/ui/activity/base/BaseActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
117117
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && sColoredNavigation) {
118118
val navigationColor = navigationBarColor
119119
window.navigationBarColor = navigationColor
120-
Theme.setLightNavigationbarAuto(this, ColorUtil.isColorLight(navigationColor))
120+
Theme.setLightNavigationBarAuto(this, ColorUtil.isColorLight(navigationColor))
121121
}
122122
}
123123

app/src/main/java/remix/myplayer/util/SPUtil.java

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public interface LYRIC_KEY {
129129

130130
String LYRIC_FONT_SIZE = "lyric_font_size";
131131
String LYRIC_RESET_ON_16000 = "lyric_reset_on_16000";
132+
String LYRIC_LOCAL_TIP_SHOWN = "lyric_local_tip_shown";
132133
}
133134

134135
public interface COVER_KEY {

app/src/main/res/values-zh-rCN/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,5 @@
473473
<string name="connect">连接</string>
474474
<string name="edit">编辑</string>
475475
<string name="speed_at_2x">2x倍速播放中</string>
476+
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌词文件请确保放在公共目录中(如Downloads、Music等目录)</string>
476477
</resources>

app/src/main/res/values-zh-rHK/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,5 @@
472472
<string name="connect">連接</string>
473473
<string name="edit">編輯</string>
474474
<string name="speed_at_2x">2x倍速播放中</string>
475+
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
475476
</resources>

app/src/main/res/values-zh-rTW/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,5 @@
473473
<string name="connect">連接</string>
474474
<string name="edit">編輯</string>
475475
<string name="speed_at_2x">2x倍速播放中</string>
476+
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
476477
</resources>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,5 @@
473473
<string name="connect">Connect</string>
474474
<string name="edit">Edit</string>
475475
<string name="speed_at_2x">Playing at 2x speed</string>
476+
<string name="local_lyric_tip">If your Android version is 11 or above, please make sure the local lyrics files are placed in the public directory (such as Downloads, Music, etc. directories)</string>
476477
</resources>

0 commit comments

Comments
 (0)