Fix lyrics loading
This commit is contained in:
parent
598364b8e0
commit
1e2be0a69f
4 changed files with 56 additions and 94 deletions
|
@ -145,36 +145,30 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
||||||
private fun showSyncedLyrics() {
|
private fun showSyncedLyrics() {
|
||||||
var content = ""
|
var content = ""
|
||||||
try {
|
try {
|
||||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
try {
|
|
||||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
|
||||||
} catch (e2: Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
val materialDialog = MaterialDialog(
|
val materialDialog = MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT))
|
||||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
.show {
|
||||||
).show {
|
cornerRadius(PreferenceUtil.getInstance(this@LyricsActivity).dialogCorner)
|
||||||
title(R.string.add_time_framed_lryics)
|
title(R.string.add_time_framed_lryics)
|
||||||
negativeButton(R.string.action_search) {
|
negativeButton(R.string.action_search) {
|
||||||
RetroUtil.openUrl(
|
RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl)
|
||||||
this@LyricsActivity, googleSearchLrcUrl
|
}
|
||||||
)
|
input(
|
||||||
}
|
hint = getString(R.string.paste_lyrics_here),
|
||||||
input(
|
prefill = content,
|
||||||
hint = getString(R.string.paste_lyrics_here),
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||||
prefill = content,
|
) { _, input ->
|
||||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString())
|
||||||
) { _, input ->
|
}
|
||||||
LyricUtil.writeLrcToLoc(song.data, song.artistName, input.toString())
|
positiveButton(android.R.string.ok) {
|
||||||
}
|
updateSong()
|
||||||
positiveButton(android.R.string.ok) {
|
}
|
||||||
updateSong()
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +189,10 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
||||||
val materialDialog = MaterialDialog(
|
val materialDialog = MaterialDialog(
|
||||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||||
).show {
|
).show {
|
||||||
|
cornerRadius(PreferenceUtil.getInstance(this@LyricsActivity).dialogCorner)
|
||||||
title(R.string.add_lyrics)
|
title(R.string.add_lyrics)
|
||||||
negativeButton(R.string.action_search) {
|
negativeButton(R.string.action_search) {
|
||||||
RetroUtil.openUrl(
|
RetroUtil.openUrl(this@LyricsActivity, getGoogleSearchUrl())
|
||||||
this@LyricsActivity, getGoogleSearchUrl()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
input(
|
input(
|
||||||
hint = getString(R.string.paste_lyrics_here),
|
hint = getString(R.string.paste_lyrics_here),
|
||||||
|
@ -396,12 +389,8 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
||||||
|
|
||||||
private fun loadLRCLyrics() {
|
private fun loadLRCLyrics() {
|
||||||
val song = MusicPlayerRemote.currentSong
|
val song = MusicPlayerRemote.currentSong
|
||||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||||
} else {
|
|
||||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
|
||||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
||||||
|
|
||||||
override fun doInBackground(vararg params: Song): Lyrics? {
|
override fun doInBackground(vararg params: Song): Lyrics? {
|
||||||
try {
|
try {
|
||||||
var data: String? = LyricUtil.getStringFromFile(params[0].data, params[0].artistName)
|
var data: String? = LyricUtil.getStringFromFile(params[0].title, params[0].artistName)
|
||||||
return if (TextUtils.isEmpty(data)) {
|
return if (TextUtils.isEmpty(data)) {
|
||||||
data = MusicUtil.getLyrics(params[0])
|
data = MusicUtil.getLyrics(params[0])
|
||||||
return if (TextUtils.isEmpty(data)) {
|
return if (TextUtils.isEmpty(data)) {
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.util;
|
package code.name.monkey.retromusic.util;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -36,16 +36,17 @@ public class LyricUtil {
|
||||||
|
|
||||||
private static final String lrcRootPath = android.os.Environment
|
private static final String lrcRootPath = android.os.Environment
|
||||||
.getExternalStorageDirectory().toString() + "/RetroMusic/lyrics/";
|
.getExternalStorageDirectory().toString() + "/RetroMusic/lyrics/";
|
||||||
|
private static final String TAG = "LyricUtil";
|
||||||
|
|
||||||
@NonNull
|
@Nullable
|
||||||
public static File writeLrcToLoc(@NonNull String title, @NonNull String artist, @NonNull String lrcContext) {
|
public static File writeLrcToLoc(@NonNull String title, @NonNull String artist, @NonNull String lrcContext) {
|
||||||
FileWriter writer = null;
|
FileWriter writer = null;
|
||||||
try {
|
try {
|
||||||
File file = new File(getLrcPath2(title, artist));
|
File file = new File(getLrcPath(title, artist));
|
||||||
if (!file.exists()) {
|
if (!file.getParentFile().exists()) {
|
||||||
file.mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
writer = new FileWriter(getLrcPath2(title, artist));
|
writer = new FileWriter(getLrcPath(title, artist));
|
||||||
writer.write(lrcContext);
|
writer.write(lrcContext);
|
||||||
return file;
|
return file;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -71,48 +72,17 @@ public class LyricUtil {
|
||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLrcFile2Exist(@NonNull String title, @NonNull String artist) {
|
@Nullable
|
||||||
File file = new File(getLrcPath2(title, artist));
|
|
||||||
|
|
||||||
return file.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
||||||
try {
|
File file = new File(getLrcPath(title, artist));
|
||||||
File file = new File(getLrcPath(title, artist));
|
if (file.exists()) {
|
||||||
File file2 = new File(getLrcPath2(title, artist));
|
return file;
|
||||||
if (file.exists()) {
|
} else {
|
||||||
|
return null;
|
||||||
return file;
|
|
||||||
} else if (file2.exists()) {
|
|
||||||
|
|
||||||
return file2;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return new File("lyric file not exist");
|
|
||||||
}
|
|
||||||
} catch (Exception dfs) {
|
|
||||||
dfs.printStackTrace();
|
|
||||||
return new File("lyric file not exist");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLrcPath2(String title, String artist) {
|
private static String getLrcPath(String title, String artist) {
|
||||||
if (!TextUtils.isEmpty(title)) {
|
|
||||||
String x2;
|
|
||||||
if (title.endsWith(".flac") || title.endsWith(".mogg") || title.endsWith(".alac") || title.endsWith(".aiff") || title.endsWith(".webv")) {
|
|
||||||
x2 = title.substring(0, title.length() - 5) + ".lrc";
|
|
||||||
} else {
|
|
||||||
x2 = title.substring(0, title.length() - 4) + ".lrc";
|
|
||||||
}
|
|
||||||
return x2;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLrcPath(String title, String artist) {
|
|
||||||
return lrcRootPath + title + " - " + artist + ".lrc";
|
return lrcRootPath + title + " - " + artist + ".lrc";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,18 +105,10 @@ public class LyricUtil {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String getStringFromFile(@NonNull String title, @NonNull String artist) throws Exception {
|
public static String getStringFromFile(@NonNull String title, @NonNull String artist) throws Exception {
|
||||||
File file;
|
File file = new File(getLrcPath(title, artist));
|
||||||
File file2 = new File(getLrcPath(title, artist));
|
|
||||||
File file3 = new File(getLrcPath2(title, artist));
|
|
||||||
if (file2.exists()) {
|
|
||||||
file = file2;
|
|
||||||
} else {
|
|
||||||
file = file3;
|
|
||||||
}
|
|
||||||
FileInputStream fin = new FileInputStream(file);
|
FileInputStream fin = new FileInputStream(file);
|
||||||
String ret = convertStreamToString(fin);
|
String ret = convertStreamToString(fin);
|
||||||
fin.close();
|
fin.close();
|
||||||
// Log.d("damn2",ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package code.name.monkey.appthemehelper.util
|
package code.name.monkey.appthemehelper.util
|
||||||
|
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.PorterDuff
|
import androidx.appcompat.widget.AppCompatButton
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
|
import com.afollestad.materialdialogs.internal.button.DialogActionButton
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
|
|
||||||
|
@ -49,4 +46,18 @@ object MaterialUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTint(button: DialogActionButton, color: Int = ThemeStore.accentColor(button.context), background: Boolean = true) {
|
||||||
|
val temp = button as AppCompatButton
|
||||||
|
val context = temp.context
|
||||||
|
val colorState = ColorStateList.valueOf(color)
|
||||||
|
val textColor = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color)))
|
||||||
|
|
||||||
|
if (background) {
|
||||||
|
temp.backgroundTintList = colorState
|
||||||
|
temp.setTextColor(textColor)
|
||||||
|
} else {
|
||||||
|
temp.setTextColor(colorState)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue