Refactoring
This commit is contained in:
parent
aabd0367b9
commit
8a57d32214
3 changed files with 30 additions and 26 deletions
|
|
@ -5,8 +5,8 @@ import android.util.SparseArray;
|
||||||
public abstract class AbsSynchronizedLyrics extends Lyrics {
|
public abstract class AbsSynchronizedLyrics extends Lyrics {
|
||||||
private static final int TIME_OFFSET_MS = 500; // time adjustment to display line before it actually starts
|
private static final int TIME_OFFSET_MS = 500; // time adjustment to display line before it actually starts
|
||||||
|
|
||||||
public final SparseArray<String> lines = new SparseArray<>();
|
protected final SparseArray<String> lines = new SparseArray<>();
|
||||||
public int offset = 0;
|
protected int offset = 0;
|
||||||
|
|
||||||
public String getLine(int time) {
|
public String getLine(int time) {
|
||||||
time += offset + AbsSynchronizedLyrics.TIME_OFFSET_MS;
|
time += offset + AbsSynchronizedLyrics.TIME_OFFSET_MS;
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ public class Lyrics {
|
||||||
public Song song;
|
public Song song;
|
||||||
public String data;
|
public String data;
|
||||||
|
|
||||||
boolean parsed = false;
|
protected boolean parsed = false;
|
||||||
boolean valid = false;
|
protected boolean valid = false;
|
||||||
|
|
||||||
public Lyrics setData(Song song, String data) {
|
public Lyrics setData(Song song, String data) {
|
||||||
this.song = song;
|
this.song = song;
|
||||||
|
|
|
||||||
|
|
@ -184,21 +184,33 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isLyricsLayoutVisible() {
|
||||||
|
return lyrics != null && lyrics.isSynchronized() && lyrics.isValid() && PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLyricsLayoutBound() {
|
||||||
|
return lyricsLayout != null && lyricsLine1 != null && lyricsLine2 != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideLyricsLayout() {
|
||||||
|
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!isLyricsLayoutBound()) return;
|
||||||
|
lyricsLayout.setVisibility(View.GONE);
|
||||||
|
lyricsLine1.setText(null);
|
||||||
|
lyricsLine2.setText(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void setLyrics(Lyrics l) {
|
public void setLyrics(Lyrics l) {
|
||||||
lyrics = l;
|
lyrics = l;
|
||||||
|
|
||||||
if (lyricsLayout == null || lyricsLine1 == null || lyricsLine2 == null) return;
|
if (!isLyricsLayoutBound()) return;
|
||||||
|
|
||||||
if (!PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow() || l == null || !l.isSynchronized() || !l.isValid()) {
|
if (!isLyricsLayoutVisible()) {
|
||||||
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
|
hideLyricsLayout();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (lyricsLayout == null || lyricsLine1 == null || lyricsLine2 == null) return;
|
|
||||||
lyricsLayout.setVisibility(View.GONE);
|
|
||||||
lyricsLine1.setText(null);
|
|
||||||
lyricsLine2.setText(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,18 +231,10 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateProgressViews(int progress, int total) {
|
public void onUpdateProgressViews(int progress, int total) {
|
||||||
if (lyricsLayout == null || lyricsLine1 == null || lyricsLine2 == null) return;
|
if (!isLyricsLayoutBound()) return;
|
||||||
|
|
||||||
if (!PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow() || lyrics == null || !lyrics.isSynchronized() || !lyrics.isValid()) {
|
if (!isLyricsLayoutVisible()) {
|
||||||
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
|
hideLyricsLayout();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (lyricsLayout == null || lyricsLine1 == null || lyricsLine2 == null) return;
|
|
||||||
lyricsLayout.setVisibility(View.GONE);
|
|
||||||
lyricsLine1.setText(null);
|
|
||||||
lyricsLine2.setText(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue