Skip to content

Commit

Permalink
本地歌词提示
Browse files Browse the repository at this point in the history
  • Loading branch information
rRemix committed Jul 21, 2024
1 parent 00cc1d1 commit 6959a80
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 98 deletions.
155 changes: 87 additions & 68 deletions app/src/main/java/remix/myplayer/misc/menu/AudioPopupListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import remix.myplayer.helper.EQHelper
import remix.myplayer.helper.MusicServiceRemote.getCurrentSong
import remix.myplayer.service.Command
import remix.myplayer.theme.Theme.getBaseDialog
import remix.myplayer.ui.ViewCommon
import remix.myplayer.ui.activity.PlayerActivity
import remix.myplayer.ui.dialog.AddtoPlayListDialog
import remix.myplayer.ui.dialog.TimerDialog
Expand Down Expand Up @@ -43,74 +44,10 @@ class AudioPopupListener(activity: PlayerActivity, private val song: Song) :
val activity = ref.get() ?: return true
when (item.itemId) {
R.id.menu_lyric -> {
val alreadyIgnore = (SPUtil
.getValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_DEFAULT) == SPUtil.LYRIC_KEY.LYRIC_IGNORE)

val lyricFragment = ref.get()?.lyricFragment ?: return true
getBaseDialog(ref.get())
.items(
getString(R.string.embedded_lyric),
getString(R.string.local),
getString(R.string.kugou),
getString(R.string.netease),
getString(R.string.qq),
getString(R.string.select_lrc),
getString(if (!alreadyIgnore) R.string.ignore_lrc else R.string.cancel_ignore_lrc),
getString(R.string.lyric_adjust_font_size),
getString(R.string.change_offset))
.itemsCallback { dialog, itemView, position, text ->
when (position) {
0, 1, 2, 3, 4 -> { //0内嵌 1本地 2酷狗 3网易 4qq
SPUtil.putValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(), position + 2)
lyricFragment.updateLrc(song, true)
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
}
5 -> { //手动选择歌词
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension("lrc")
addCategory(Intent.CATEGORY_OPENABLE)
}
Util.startActivityForResultSafely(
activity,
intent,
PlayerActivity.REQUEST_SELECT_LYRIC
)
}
6 -> { //忽略或者取消忽略
getBaseDialog(activity)
.title(if (!alreadyIgnore) R.string.confirm_ignore_lrc else R.string.confirm_cancel_ignore_lrc)
.negativeText(R.string.cancel)
.positiveText(R.string.confirm)
.onPositive { dialog1, which ->
if (!alreadyIgnore) {//忽略
SPUtil.putValue(activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_IGNORE)
lyricFragment.updateLrc(song)
} else {//取消忽略
SPUtil.putValue(activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_DEFAULT)
lyricFragment.updateLrc(song)
}
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
}
.show()
}
7 -> { //字体大小调整
getBaseDialog(ref.get())
.items(R.array.lyric_font_size)
.itemsCallback { dialog, itemView, position, text ->
lyricFragment.setLyricScalingFactor(position)
}
.show()
}
8 -> { //歌词时间轴调整
activity.showLyricOffsetView()
}
}

}
.show()
ViewCommon.showLocalLyricTip(activity) {
onClickLyric(activity)
}
return true
}
R.id.menu_edit -> {
if (!song.isLocal()) {
Expand Down Expand Up @@ -204,4 +141,86 @@ class AudioPopupListener(activity: PlayerActivity, private val song: Song) :
}
return true
}

private fun onClickLyric(activity: PlayerActivity) {
val alreadyIgnore = (SPUtil
.getValue(
ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_DEFAULT
) == SPUtil.LYRIC_KEY.LYRIC_IGNORE)

val lyricFragment = ref.get()?.lyricFragment ?: return
getBaseDialog(ref.get())
.items(
getString(R.string.embedded_lyric),
getString(R.string.local),
getString(R.string.kugou),
getString(R.string.netease),
getString(R.string.qq),
getString(R.string.select_lrc),
getString(if (!alreadyIgnore) R.string.ignore_lrc else R.string.cancel_ignore_lrc),
getString(R.string.lyric_adjust_font_size),
getString(R.string.change_offset)
)
.itemsCallback { dialog, itemView, position, text ->
when (position) {
0, 1, 2, 3, 4 -> { //0内嵌 1本地 2酷狗 3网易 4qq
SPUtil.putValue(ref.get(), SPUtil.LYRIC_KEY.NAME, song.id.toString(), position + 2)
lyricFragment.updateLrc(song, true)
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
}

5 -> { //手动选择歌词
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension("lrc")
addCategory(Intent.CATEGORY_OPENABLE)
}
Util.startActivityForResultSafely(
activity,
intent,
PlayerActivity.REQUEST_SELECT_LYRIC
)
}

6 -> { //忽略或者取消忽略
getBaseDialog(activity)
.title(if (!alreadyIgnore) R.string.confirm_ignore_lrc else R.string.confirm_cancel_ignore_lrc)
.negativeText(R.string.cancel)
.positiveText(R.string.confirm)
.onPositive { dialog1, which ->
if (!alreadyIgnore) {//忽略
SPUtil.putValue(
activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_IGNORE
)
lyricFragment.updateLrc(song)
} else {//取消忽略
SPUtil.putValue(
activity, SPUtil.LYRIC_KEY.NAME, song.id.toString(),
SPUtil.LYRIC_KEY.LYRIC_DEFAULT
)
lyricFragment.updateLrc(song)
}
sendLocalBroadcast(MusicUtil.makeCmdIntent(Command.CHANGE_LYRIC))
}
.show()
}

7 -> { //字体大小调整
getBaseDialog(ref.get())
.items(R.array.lyric_font_size)
.itemsCallback { dialog, itemView, position, text ->
lyricFragment.setLyricScalingFactor(position)
}
.show()
}

8 -> { //歌词时间轴调整
activity.showLyricOffsetView()
}
}

}
.show()
}
}
3 changes: 1 addition & 2 deletions app/src/main/java/remix/myplayer/theme/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
Expand Down Expand Up @@ -249,7 +248,7 @@ public static MaterialDialog.Builder getBaseDialog(Context context) {

}

public static void setLightNavigationbarAuto(Activity activity, boolean enabled) {
public static void setLightNavigationBarAuto(Activity activity, boolean enabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final View decorView = activity.getWindow().getDecorView();
int systemUiVisibility = decorView.getSystemUiVisibility();
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/remix/myplayer/ui/ViewCommon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package remix.myplayer.ui

import android.content.Context
import remix.myplayer.R
import remix.myplayer.theme.Theme
import remix.myplayer.util.SPUtil

object ViewCommon {
fun showLocalLyricTip(context: Context, action: () -> Unit) {
if (!SPUtil.getValue(
context,
SPUtil.LYRIC_KEY.NAME,
SPUtil.LYRIC_KEY.LYRIC_LOCAL_TIP_SHOWN,
false
)
) {
SPUtil.putValue(context, SPUtil.LYRIC_KEY.NAME, SPUtil.LYRIC_KEY.LYRIC_LOCAL_TIP_SHOWN, true)
Theme.getBaseDialog(context)
.negativeText(R.string.cancel)
.positiveText(R.string.confirm)
.onPositive { dialog, which ->
action.invoke()
}
.content(R.string.local_lyric_tip)
.show()
} else {
action.invoke()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class PlayerActivity : BaseMusicActivity() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ThemeStore.sColoredNavigation) {
val navigationColor = ThemeStore.getBackgroundColorMain(this)
window.navigationBarColor = navigationColor
Theme.setLightNavigationbarAuto(this, ColorUtil.isColorLight(navigationColor))
Theme.setLightNavigationBarAuto(this, ColorUtil.isColorLight(navigationColor))
}
}

Expand Down
34 changes: 8 additions & 26 deletions app/src/main/java/remix/myplayer/ui/activity/SettingActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import remix.myplayer.theme.Theme
import remix.myplayer.theme.Theme.getBaseDialog
import remix.myplayer.theme.ThemeStore
import remix.myplayer.theme.TintHelper
import remix.myplayer.ui.ViewCommon
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_LIBRARY
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_RECREATE
import remix.myplayer.ui.activity.MainActivity.Companion.EXTRA_REFRESH_ADAPTER
Expand Down Expand Up @@ -112,16 +113,13 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,

//是否需要刷新library
private var needRefreshLibrary: Boolean = false

// //是否从主题颜色选择对话框返回
// private boolean mFromColorChoose = false;

//缓存大小
private var cacheSize: Long = 0
private val handler: MsgHandler by lazy {
MsgHandler(this)
}



private val scanSize = intArrayOf(0, 500 * KB, MB, 2 * MB, 5 * MB)
private var originalAlbumChoice: String? = null

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

private var blackList: Set<String> = emptySet()

//尝试从uri获取文件夹absolutePath
//fun getFolderPath(documentFile: DocumentFile?): String? {
// if (documentFile == null) {
// return null
// }
//
// val name = documentFile.name ?: return null
// val parent = documentFile.parentFile ?: return name
//
// val parentPath = getFolderPath(parent)
// return if (parentPath != null) {
// "$parentPath/$name"
// } else {
// name
// }
//}



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

Expand Down Expand Up @@ -920,9 +900,11 @@ class SettingActivity : ToolbarActivity(), ColorChooserDialog.ColorCallback,
* 歌词搜索优先级
*/
private fun configLyricPriority() {
LyricPriorityDialog.newInstance().show(
ViewCommon.showLocalLyricTip(this) {
LyricPriorityDialog.newInstance().show(
supportFragmentManager, "configLyricPriority"
)
)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ open class BaseActivity : AppCompatActivity(), CoroutineScope by MainScope() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && sColoredNavigation) {
val navigationColor = navigationBarColor
window.navigationBarColor = navigationColor
Theme.setLightNavigationbarAuto(this, ColorUtil.isColorLight(navigationColor))
Theme.setLightNavigationBarAuto(this, ColorUtil.isColorLight(navigationColor))
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/remix/myplayer/util/SPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public interface LYRIC_KEY {

String LYRIC_FONT_SIZE = "lyric_font_size";
String LYRIC_RESET_ON_16000 = "lyric_reset_on_16000";
String LYRIC_LOCAL_TIP_SHOWN = "lyric_local_tip_shown";
}

public interface COVER_KEY {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,5 @@
<string name="connect">连接</string>
<string name="edit">编辑</string>
<string name="speed_at_2x">2x倍速播放中</string>
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌词文件请确保放在公共目录中(如Downloads、Music等目录)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,5 @@
<string name="connect">連接</string>
<string name="edit">編輯</string>
<string name="speed_at_2x">2x倍速播放中</string>
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,5 @@
<string name="connect">連接</string>
<string name="edit">編輯</string>
<string name="speed_at_2x">2x倍速播放中</string>
<string name="local_lyric_tip">如果你的Android版本在11以及以上,本地歌詞檔案請確保放在公共目錄中(如Downloads、Music等目錄)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,5 @@
<string name="connect">Connect</string>
<string name="edit">Edit</string>
<string name="speed_at_2x">Playing at 2x speed</string>
<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>
</resources>

0 comments on commit 6959a80

Please sign in to comment.