mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Merge pull request #20 from le-firehawk/feature-lyrics-window-fix
feat: Fix lyric scrolling during playback, keep screen on while viewing
This commit is contained in:
commit
d7d25fb542
1 changed files with 19 additions and 4 deletions
|
|
@ -6,11 +6,13 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Layout;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -28,6 +30,7 @@ import com.cappielloantonio.tempo.subsonic.models.Line;
|
|||
import com.cappielloantonio.tempo.subsonic.models.LyricsList;
|
||||
import com.cappielloantonio.tempo.util.MusicUtil;
|
||||
import com.cappielloantonio.tempo.util.OpenSubsonicExtensionsUtil;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
|
|
@ -76,12 +79,16 @@ public class PlayerLyricsFragment extends Fragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
bindMediaController();
|
||||
requireActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
releaseHandler();
|
||||
if (!Preferences.isDisplayAlwaysOn()) {
|
||||
requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -281,10 +288,18 @@ public class PlayerLyricsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private int getScroll(List<Line> lines, Line toHighlight) {
|
||||
int lineHeight = bind.nowPlayingSongLyricsTextView.getLineHeight();
|
||||
int lineCount = getLineCount(lines, toHighlight);
|
||||
int scrollViewHeight = bind.nowPlayingSongLyricsSrollView.getHeight();
|
||||
int startIndex = getStartPosition(lines, toHighlight);
|
||||
Layout layout = bind.nowPlayingSongLyricsTextView.getLayout();
|
||||
if (layout == null) return 0;
|
||||
|
||||
return lineHeight * lineCount < scrollViewHeight / 2 ? 0 : lineHeight * lineCount - scrollViewHeight / 2 + lineHeight;
|
||||
int line = layout.getLineForOffset(startIndex);
|
||||
int lineTop = layout.getLineTop(line);
|
||||
int lineBottom = layout.getLineBottom(line);
|
||||
int lineCenter = (lineTop + lineBottom) / 2;
|
||||
|
||||
int scrollViewHeight = bind.nowPlayingSongLyricsSrollView.getHeight();
|
||||
int scroll = lineCenter - scrollViewHeight / 2;
|
||||
|
||||
return Math.max(scroll, 0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue