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