Fix circlar UI and lyrics
This commit is contained in:
commit
c5aa167c1c
10 changed files with 148 additions and 98 deletions
|
@ -150,8 +150,13 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
private fun showSyncedLyrics() {
|
||||
var content = ""
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
} catch (e2: Exception) {
|
||||
|
||||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
|
@ -161,7 +166,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
input(hint = getString(R.string.paste_lyrics_here),
|
||||
prefill = content,
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) { _, input ->
|
||||
LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString())
|
||||
LyricUtil.writeLrcToLoc(song.data, song.artistName, input.toString())
|
||||
}
|
||||
positiveButton(android.R.string.ok) {
|
||||
updateSong()
|
||||
|
@ -215,7 +220,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
return baseUrl
|
||||
}
|
||||
|
||||
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
|
||||
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
|
||||
class Tabs(@StringRes val title: Int,
|
||||
val fragment: Fragment)
|
||||
|
||||
|
@ -364,8 +369,12 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
|
||||
private fun loadLRCLyrics() {
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
||||
} else {
|
||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,4 +384,4 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,6 @@ import android.view.*
|
|||
import android.view.animation.DecelerateInterpolator
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.fistElement
|
||||
import code.name.monkey.retromusic.extensions.hide
|
||||
import code.name.monkey.retromusic.extensions.lastElement
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||
|
@ -96,7 +92,6 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
|||
override fun onServiceConnected() {
|
||||
updateSongTitle()
|
||||
updatePlayPauseDrawableState()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
|
@ -105,24 +100,8 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
|||
|
||||
override fun onPlayStateChanged() {
|
||||
updatePlayPauseDrawableState()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
private fun updateButtons() {
|
||||
if (PreferenceUtil.getInstance(requireContext()).isExtraControls) {
|
||||
if (MusicPlayerRemote.playingQueue.fistElement()) {
|
||||
actionPrevious.hide()
|
||||
} else {
|
||||
actionPrevious.show()
|
||||
}
|
||||
|
||||
if (MusicPlayerRemote.playingQueue.lastElement()) {
|
||||
actionNext.hide()
|
||||
} else {
|
||||
actionNext.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUpdateProgressViews(progress: Int, total: Int) {
|
||||
progressBar.max = total
|
||||
|
@ -146,7 +125,7 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(), MusicProgressViewUpda
|
|||
if (MusicPlayerRemote.isPlaying) {
|
||||
miniPlayerPlayPauseButton!!.setImageResource(R.drawable.ic_pause_white_24dp)
|
||||
} else {
|
||||
miniPlayerPlayPauseButton!!.setImageResource(R.drawable.ic_play_arrow_white_32dp)
|
||||
miniPlayerPlayPauseButton!!.setImageResource(R.drawable.ic_play_arrow_white_24dp)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,9 @@ import android.view.View
|
|||
import android.view.animation.AccelerateInterpolator
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.fistElement
|
||||
import code.name.monkey.retromusic.extensions.hidden
|
||||
import code.name.monkey.retromusic.extensions.lastElement
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.fragments.VolumeFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.*
|
||||
|
||||
|
||||
/**
|
||||
|
@ -78,27 +72,5 @@ abstract class AbsPlayerControlsFragment : AbsMusicServiceFragment(), MusicProgr
|
|||
const val SLIDER_ANIMATION_TIME: Long = 400
|
||||
}
|
||||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged()
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
private fun updateButtons() {
|
||||
if (MusicPlayerRemote.playingQueue.fistElement()) {
|
||||
previousButton?.hidden()
|
||||
} else {
|
||||
previousButton?.show()
|
||||
}
|
||||
|
||||
if (MusicPlayerRemote.playingQueue.lastElement()) {
|
||||
nextButton?.hidden()
|
||||
} else {
|
||||
nextButton?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
|||
|
||||
override fun doInBackground(vararg params: Song): Lyrics? {
|
||||
try {
|
||||
var data: String? = LyricUtil.getStringFromFile(params[0].title, params[0].artistName)
|
||||
var data: String? = LyricUtil.getStringFromFile(params[0].data, params[0].artistName)
|
||||
return if (TextUtils.isEmpty(data)) {
|
||||
data = MusicUtil.getLyrics(params[0])
|
||||
return if (TextUtils.isEmpty(data)) {
|
||||
|
|
|
@ -42,8 +42,8 @@ public class LrcHelper {
|
|||
|
||||
private static final String CHARSET = "utf-8";
|
||||
//[03:56.00][03:18.00][02:06.00][01:07.00]原谅我这一生不羁放纵爱自由
|
||||
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2}])+)(.*)";
|
||||
private static final String TIME_REGEX = "\\[(\\d{2}):(\\d{2})\\.(\\d{2})]";
|
||||
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2,3}])+)(.*)";
|
||||
private static final String TIME_REGEX = "\\[(\\d{2}):(\\d{2})\\.(\\d{2,3})]";
|
||||
|
||||
public static List<Lrc> parseLrcFromAssets(Context context, String fileName) {
|
||||
try {
|
||||
|
@ -127,8 +127,14 @@ public class LrcHelper {
|
|||
String mil = timeMatcher.group(3);
|
||||
Lrc lrc = new Lrc();
|
||||
if (content != null && content.length() != 0) {
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil) * 10);
|
||||
if(Integer.parseInt(mil)< 100){
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil) * 10);}
|
||||
else{
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil)
|
||||
);
|
||||
}
|
||||
lrc.setText(content);
|
||||
lrcs.add(lrc);
|
||||
}
|
||||
|
@ -148,4 +154,4 @@ public class LrcHelper {
|
|||
}
|
||||
return time + "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ package code.name.monkey.retromusic.util;
|
|||
|
||||
import android.util.Base64;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -25,8 +27,6 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Created by hefuyi on 2016/11/8.
|
||||
*/
|
||||
|
@ -40,11 +40,11 @@ public class LyricUtil {
|
|||
public static File writeLrcToLoc(@NonNull String title, @NonNull String artist, @NonNull String lrcContext) {
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
File file = new File(getLrcPath2(title, artist));
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
writer = new FileWriter(getLrcPath(title, artist));
|
||||
writer = new FileWriter(getLrcPath2(title, artist));
|
||||
writer.write(lrcContext);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
|
@ -70,17 +70,46 @@ public class LyricUtil {
|
|||
return file.exists();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
} else {
|
||||
return new File("lyric file not exist");
|
||||
}
|
||||
public static boolean isLrcFile2Exist(@NonNull String title, @NonNull String artist) {
|
||||
File file = new File(getLrcPath2(title, artist));
|
||||
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
private static String getLrcPath(String title, String artist) {
|
||||
@NonNull
|
||||
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
||||
try{
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
File file2 = new File(getLrcPath2(title, artist));
|
||||
if (file.exists()) {
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
public static String getLrcPath(String title, String artist) {
|
||||
return lrcRootPath + title + " - " + artist + ".lrc";
|
||||
}
|
||||
|
||||
|
@ -103,10 +132,18 @@ public class LyricUtil {
|
|||
|
||||
@NonNull
|
||||
public static String getStringFromFile(@NonNull String title, @NonNull String artist) throws Exception {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
File file;
|
||||
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);
|
||||
String ret = convertStreamToString(fin);
|
||||
fin.close();
|
||||
// Log.d("damn2",ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ object ViewUtil {
|
|||
background.setColorFilter(MaterialValueHelper.getPrimaryDisabledTextColor(progressSlider.context, ColorUtil.isColorLight(primaryColor)), PorterDuff.Mode.SRC_IN)
|
||||
|
||||
val secondaryProgress = ld.findDrawableByLayerId(android.R.id.secondaryProgress)
|
||||
secondaryProgress.setColorFilter(ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN)
|
||||
secondaryProgress?.setColorFilter(ColorUtil.withAlpha(newColor, 0.65f), PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
|
||||
private fun createColorAnimator(target: Any, propertyName: String, @ColorInt startColor: Int, @ColorInt endColor: Int): Animator {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue