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:
eddyizm 2025-08-05 21:57:35 -07:00 committed by GitHub
commit d7d25fb542
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,11 +6,13 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Layout;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; 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.subsonic.models.LyricsList;
import com.cappielloantonio.tempo.util.MusicUtil; import com.cappielloantonio.tempo.util.MusicUtil;
import com.cappielloantonio.tempo.util.OpenSubsonicExtensionsUtil; import com.cappielloantonio.tempo.util.OpenSubsonicExtensionsUtil;
import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel; import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
@ -76,12 +79,16 @@ public class PlayerLyricsFragment extends Fragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
bindMediaController(); bindMediaController();
requireActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
releaseHandler(); releaseHandler();
if (!Preferences.isDisplayAlwaysOn()) {
requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
} }
@Override @Override
@ -281,10 +288,18 @@ public class PlayerLyricsFragment extends Fragment {
} }
private int getScroll(List<Line> lines, Line toHighlight) { private int getScroll(List<Line> lines, Line toHighlight) {
int lineHeight = bind.nowPlayingSongLyricsTextView.getLineHeight(); int startIndex = getStartPosition(lines, toHighlight);
int lineCount = getLineCount(lines, toHighlight); Layout layout = bind.nowPlayingSongLyricsTextView.getLayout();
int scrollViewHeight = bind.nowPlayingSongLyricsSrollView.getHeight(); 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);
} }
} }