fix(YouTube - Settings): Misaligned icons and titles in RVX settings toolbar on Android 15 https://github.com/inotia00/ReVanced_Extended/issues/2602

This commit is contained in:
inotia00 2025-01-03 22:14:47 +09:00
parent f5834ab742
commit 574cd8410e
3 changed files with 30 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package app.revanced.extension.youtube.settings.preference; package app.revanced.extension.youtube.settings.preference;
import static com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity.setToolbarLayoutParams;
import static app.revanced.extension.shared.settings.preference.AbstractPreferenceFragment.showRestartDialog; import static app.revanced.extension.shared.settings.preference.AbstractPreferenceFragment.showRestartDialog;
import static app.revanced.extension.shared.settings.preference.AbstractPreferenceFragment.updateListPreferenceSummary; import static app.revanced.extension.shared.settings.preference.AbstractPreferenceFragment.updateListPreferenceSummary;
import static app.revanced.extension.shared.utils.ResourceUtils.getXmlIdentifier; import static app.revanced.extension.shared.utils.ResourceUtils.getXmlIdentifier;
@ -18,6 +19,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Insets;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
@ -31,6 +33,7 @@ import android.preference.PreferenceScreen;
import android.preference.SwitchPreference; import android.preference.SwitchPreference;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toolbar; import android.widget.Toolbar;
@ -202,6 +205,15 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
.findViewById(android.R.id.content) .findViewById(android.R.id.content)
.getParent(); .getParent();
// Fix required for Android 15
if (isSDKAbove(35)) {
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
Insets statusInsets = insets.getInsets(WindowInsets.Type.statusBars());
v.setPadding(0, statusInsets.top, 0, 0);
return insets;
});
}
Toolbar toolbar = new Toolbar(preferenceScreen.getContext()); Toolbar toolbar = new Toolbar(preferenceScreen.getContext());
toolbar.setTitle(preferenceScreen.getTitle()); toolbar.setTitle(preferenceScreen.getTitle());
@ -219,6 +231,8 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
toolbarTextView.setTextColor(ThemeUtils.getForegroundColor()); toolbarTextView.setTextColor(ThemeUtils.getForegroundColor());
} }
setToolbarLayoutParams(toolbar);
rootView.addView(toolbar, 0); rootView.addView(toolbar, 0);
return false; return false;
} }

View File

@ -88,17 +88,21 @@ public class VideoQualitySettingsActivity extends Activity {
fragment.filterPreferences(query); fragment.filterPreferences(query);
} }
private static ViewGroup.LayoutParams lp;
public static void setToolbarLayoutParams(Toolbar toolbar) {
if (lp != null) {
toolbar.setLayoutParams(lp);
}
}
private void setToolbar() { private void setToolbar() {
if (!(findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar_parent")) instanceof ViewGroup toolBarParent)) ViewGroup toolBarParent = findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar_parent"));
return;
// Remove dummy toolbar. // Remove dummy toolbar.
for (int i = 0; i < toolBarParent.getChildCount(); i++) { ViewGroup dummyToolbar = toolBarParent.findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar"));
View view = toolBarParent.getChildAt(i); lp = dummyToolbar.getLayoutParams();
if (view != null) { toolBarParent.removeView(dummyToolbar);
toolBarParent.removeView(view);
}
}
Toolbar toolbar = new Toolbar(toolBarParent.getContext()); Toolbar toolbar = new Toolbar(toolBarParent.getContext());
toolbar.setBackgroundColor(ThemeUtils.getToolbarBackgroundColor()); toolbar.setBackgroundColor(ThemeUtils.getToolbarBackgroundColor());
@ -112,6 +116,7 @@ public class VideoQualitySettingsActivity extends Activity {
if (toolbarTextView != null) { if (toolbarTextView != null) {
toolbarTextView.setTextColor(ThemeUtils.getForegroundColor()); toolbarTextView.setTextColor(ThemeUtils.getForegroundColor());
} }
setToolbarLayoutParams(toolbar);
toolBarParent.addView(toolbar, 0); toolBarParent.addView(toolbar, 0);
} }

View File

@ -16,10 +16,10 @@
android:background="@color/yt_white1" android:background="@color/yt_white1"
android:elevation="0dp"> android:elevation="0dp">
<android.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/revanced_toolbar" android:id="@+id/revanced_toolbar"
android:layout_width="0.0dip" android:layout_width="match_parent"
android:layout_height="0.0dip" android:layout_height="?attr/actionBarSize"
android:background="?attr/ytBrandBackgroundSolid" android:background="?attr/ytBrandBackgroundSolid"
app:navigationIcon="@drawable/yt_outline_arrow_left_black_24" app:navigationIcon="@drawable/yt_outline_arrow_left_black_24"
app:title="@string/revanced_extended_settings_title" /> app:title="@string/revanced_extended_settings_title" />