Fix API 28+ GridLayoutManager navigation is totally broken

This commit is contained in:
Yuriy Liskov
2026-03-12 18:02:09 +02:00
parent 1bb3bc0434
commit 9929dce76b
4 changed files with 25 additions and 5 deletions

View File

@@ -57,8 +57,8 @@ android {
applicationId "app.smarttube"
minSdkVersion project.properties.minSdkVersion
targetSdkVersion project.properties.targetSdkVersion
versionCode 2293
versionName "31.03"
versionCode 2296
versionName "31.06"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L"
@@ -127,11 +127,11 @@ android {
productFlavors {
stbeta {
applicationId "org.smarttube.beta"
targetSdkVersion 27 // Since 28+ GridLayoutManager navigation is totally broken
targetSdkVersion project.properties.compileSdkVersion
}
ststable {
applicationId "org.smarttube.stable"
targetSdkVersion 27 // Since 28+ GridLayoutManager navigation is totally broken
targetSdkVersion project.properties.compileSdkVersion
}
stfdroid {
applicationId "app.smarttube.fdroid"

View File

@@ -18,6 +18,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import com.liskovsoft.smartyoutubetv2.tv.R;
import com.liskovsoft.smartyoutubetv2.tv.util.ViewUtil;
@SuppressLint("AppCompatCustomView")
public class MarqueeTextViewCompat extends TextView {
@@ -126,6 +127,8 @@ public class MarqueeTextViewCompat extends TextView {
mTextView.setEllipsize(TruncateAt.END);
super.setEllipsize(TruncateAt.END); // Important: disable marquee on the container view
ViewUtil.fixApi28BrokenGridNavigation(this);
}
@Override

View File

@@ -244,4 +244,21 @@ public class ViewUtil {
frameLayout.setLayoutParams(flp);
}
}
/**
* Fix SDK 28+ GridLayoutManager broken navigation when using Japanese fonts
*/
public static void fixApi28BrokenGridNavigation(TextView textView) {
if (VERSION.SDK_INT >= 28) {
// 1. Disable dynamic line spacing for special characters (prevents expansion for CJK glyphs)
textView.setFallbackLineSpacing(false);
}
// 2. Remove system font padding to ensure consistent baseline and height
textView.setIncludeFontPadding(false);
// 3. Add fixed internal padding to create a "safe zone" for both Latin and Japanese text
int paddingExtra = (int) (4 * textView.getResources().getDisplayMetrics().density);
textView.setPadding(textView.getPaddingLeft(), paddingExtra, textView.getPaddingRight(), paddingExtra);
}
}