Fix some UI bugs
Add animations
This commit is contained in:
parent
6086011d8d
commit
ecdc9bb870
6 changed files with 64 additions and 41 deletions
|
|
@ -31,15 +31,15 @@ public abstract class AbsSynchronizedLyrics extends Lyrics {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
this.parse(true);
|
parse(true);
|
||||||
return this.valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
if (isValid()) {
|
parse(false);
|
||||||
parse(false);
|
|
||||||
|
|
||||||
|
if (valid) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ public class Lyrics {
|
||||||
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
||||||
try {
|
try {
|
||||||
Lyrics lyrics = format.newInstance().setData(song, data);
|
Lyrics lyrics = format.newInstance().setData(song, data);
|
||||||
if (lyrics.isValid()) return lyrics;
|
if (lyrics.isValid()) return lyrics.parse(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Lyrics().setData(song, data);
|
return new Lyrics().setData(song, data).parse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSynchronized(String data) {
|
public static boolean isSynchronized(String data) {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ import butterknife.Unbinder;
|
||||||
public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements ViewPager.OnPageChangeListener, MusicProgressViewUpdateHelper.Callback {
|
public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements ViewPager.OnPageChangeListener, MusicProgressViewUpdateHelper.Callback {
|
||||||
public static final String TAG = PlayerAlbumCoverFragment.class.getSimpleName();
|
public static final String TAG = PlayerAlbumCoverFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
public static final int LYRICS_ANIM_DURATION = 300;
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
|
|
||||||
@BindView(R.id.player_album_cover_viewpager)
|
@BindView(R.id.player_album_cover_viewpager)
|
||||||
|
|
@ -183,17 +185,25 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLyrics(Lyrics l) {
|
public void setLyrics(Lyrics l) {
|
||||||
if (l == null || !l.isSynchronized() || !l.isValid()) {
|
lyrics = l;
|
||||||
lyrics = null;
|
|
||||||
lyricsLayout.setVisibility(View.GONE);
|
if (!PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow() || l == null || !l.isSynchronized() || !l.isValid()) {
|
||||||
lyricsLine1.setText(null);
|
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
|
||||||
lyricsLine2.setText(null);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
lyricsLayout.setVisibility(View.GONE);
|
||||||
|
lyricsLine1.setText(null);
|
||||||
|
lyricsLine2.setText(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lyrics = l;
|
lyricsLine1.setText(null);
|
||||||
|
lyricsLine2.setText(null);
|
||||||
|
|
||||||
lyricsLayout.setVisibility(View.VISIBLE);
|
lyricsLayout.setVisibility(View.VISIBLE);
|
||||||
|
lyricsLayout.animate().alpha(1f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyColorChange(int color) {
|
private void notifyColorChange(int color) {
|
||||||
|
|
@ -206,10 +216,15 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateProgressViews(int progress, int total) {
|
public void onUpdateProgressViews(int progress, int total) {
|
||||||
if (lyrics == null || !lyrics.isSynchronized() || !lyrics.isValid() || !PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow()) {
|
if (!PreferenceUtil.getInstance(getActivity()).synchronizedLyricsShow() || lyrics == null || !lyrics.isSynchronized() || !lyrics.isValid()) {
|
||||||
lyricsLayout.setVisibility(View.GONE);
|
lyricsLayout.animate().alpha(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION).withEndAction(new Runnable() {
|
||||||
lyricsLine1.setText(null);
|
@Override
|
||||||
lyricsLine2.setText(null);
|
public void run() {
|
||||||
|
lyricsLayout.setVisibility(View.GONE);
|
||||||
|
lyricsLine1.setText(null);
|
||||||
|
lyricsLine2.setText(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +232,7 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
AbsSynchronizedLyrics synchronizedLyrics = (AbsSynchronizedLyrics) lyrics;
|
AbsSynchronizedLyrics synchronizedLyrics = (AbsSynchronizedLyrics) lyrics;
|
||||||
|
|
||||||
lyricsLayout.setVisibility(View.VISIBLE);
|
lyricsLayout.setVisibility(View.VISIBLE);
|
||||||
|
lyricsLayout.setAlpha(1f);
|
||||||
|
|
||||||
String oldLine = lyricsLine2.getText().toString();
|
String oldLine = lyricsLine2.getText().toString();
|
||||||
String line = synchronizedLyrics.getLine(progress);
|
String line = synchronizedLyrics.getLine(progress);
|
||||||
|
|
@ -231,13 +247,13 @@ public class PlayerAlbumCoverFragment extends AbsMusicServiceFragment implements
|
||||||
lyricsLine2.measure(View.MeasureSpec.makeMeasureSpec(lyricsLine2.getMeasuredWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.UNSPECIFIED);
|
lyricsLine2.measure(View.MeasureSpec.makeMeasureSpec(lyricsLine2.getMeasuredWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.UNSPECIFIED);
|
||||||
int h = lyricsLine2.getMeasuredHeight();
|
int h = lyricsLine2.getMeasuredHeight();
|
||||||
|
|
||||||
this.lyricsLine1.setAlpha(1f);
|
lyricsLine1.setAlpha(1f);
|
||||||
this.lyricsLine1.setTranslationY(0f);
|
lyricsLine1.setTranslationY(0f);
|
||||||
this.lyricsLine1.animate().alpha(0f).translationY(-h).setDuration(300);
|
lyricsLine1.animate().alpha(0f).translationY(-h).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
|
||||||
|
|
||||||
this.lyricsLine2.setAlpha(0f);
|
lyricsLine2.setAlpha(0f);
|
||||||
this.lyricsLine2.setTranslationY(h);
|
lyricsLine2.setTranslationY(h);
|
||||||
this.lyricsLine2.animate().alpha(1f).translationY(0f).setDuration(300);
|
lyricsLine2.animate().alpha(1f).translationY(0f).setDuration(PlayerAlbumCoverFragment.LYRICS_ANIM_DURATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
private void updateLyrics() {
|
private void updateLyrics() {
|
||||||
if (updateLyricsAsyncTask != null) updateLyricsAsyncTask.cancel(false);
|
if (updateLyricsAsyncTask != null) updateLyricsAsyncTask.cancel(false);
|
||||||
final Song song = MusicPlayerRemote.getCurrentSong();
|
final Song song = MusicPlayerRemote.getCurrentSong();
|
||||||
updateLyricsAsyncTask = new AsyncTask<Void, Void, String>() {
|
updateLyricsAsyncTask = new AsyncTask<Void, Void, Lyrics>() {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
|
|
@ -310,20 +310,23 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... params) {
|
protected Lyrics doInBackground(Void... params) {
|
||||||
return MusicUtil.getLyrics(song);
|
String data = MusicUtil.getLyrics(song);
|
||||||
|
if (TextUtils.isEmpty(data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Lyrics.parse(song, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String data) {
|
protected void onPostExecute(Lyrics l) {
|
||||||
if (TextUtils.isEmpty(data)) {
|
lyrics = l;
|
||||||
lyrics = null;
|
playerAlbumCoverFragment.setLyrics(lyrics);
|
||||||
|
if (lyrics == null) {
|
||||||
if (toolbar != null) {
|
if (toolbar != null) {
|
||||||
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
|
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lyrics = Lyrics.parse(song, data);
|
|
||||||
playerAlbumCoverFragment.setLyrics(lyrics);
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (toolbar != null && activity != null)
|
if (toolbar != null && activity != null)
|
||||||
if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
|
if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
|
||||||
|
|
@ -338,7 +341,7 @@ public class CardPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelled(String s) {
|
protected void onCancelled(Lyrics s) {
|
||||||
onPostExecute(null);
|
onPostExecute(null);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
private void updateLyrics() {
|
private void updateLyrics() {
|
||||||
if (updateLyricsAsyncTask != null) updateLyricsAsyncTask.cancel(false);
|
if (updateLyricsAsyncTask != null) updateLyricsAsyncTask.cancel(false);
|
||||||
final Song song = MusicPlayerRemote.getCurrentSong();
|
final Song song = MusicPlayerRemote.getCurrentSong();
|
||||||
updateLyricsAsyncTask = new AsyncTask<Void, Void, String>() {
|
updateLyricsAsyncTask = new AsyncTask<Void, Void, Lyrics>() {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
super.onPreExecute();
|
super.onPreExecute();
|
||||||
|
|
@ -306,20 +306,23 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... params) {
|
protected Lyrics doInBackground(Void... params) {
|
||||||
return MusicUtil.getLyrics(song);
|
String data = MusicUtil.getLyrics(song);
|
||||||
|
if (TextUtils.isEmpty(data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Lyrics.parse(song, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String data) {
|
protected void onPostExecute(Lyrics l) {
|
||||||
if (TextUtils.isEmpty(data)) {
|
lyrics = l;
|
||||||
lyrics = null;
|
playerAlbumCoverFragment.setLyrics(lyrics);
|
||||||
|
if (lyrics == null) {
|
||||||
if (toolbar != null) {
|
if (toolbar != null) {
|
||||||
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
|
toolbar.getMenu().removeItem(R.id.action_show_lyrics);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lyrics = Lyrics.parse(song, data);
|
|
||||||
playerAlbumCoverFragment.setLyrics(lyrics);
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (toolbar != null && activity != null)
|
if (toolbar != null && activity != null)
|
||||||
if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
|
if (toolbar.getMenu().findItem(R.id.action_show_lyrics) == null) {
|
||||||
|
|
@ -334,7 +337,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCancelled(String s) {
|
protected void onCancelled(Lyrics s) {
|
||||||
onPostExecute(null);
|
onPostExecute(null);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@
|
||||||
android:background="@drawable/shadow_up"
|
android:background="@drawable/shadow_up"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:visibility="gone">
|
android:visibility="gone"
|
||||||
|
android:alpha="0">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/player_lyrics_line1"
|
android:id="@+id/player_lyrics_line1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue