Skip to content

Commit

Permalink
fix(YouTube - Settings): Misaligned icons and titles in RVX settings …
Browse files Browse the repository at this point in the history
…toolbar on Android 15 inotia00/ReVanced_Extended#2602
  • Loading branch information
inotia00 committed Jan 3, 2025
1 parent f5834ab commit 574cd84
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.updateListPreferenceSummary;
import static app.revanced.extension.shared.utils.ResourceUtils.getXmlIdentifier;
Expand All @@ -18,6 +19,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Insets;
import android.net.Uri;
import android.os.Bundle;
import android.preference.EditTextPreference;
Expand All @@ -31,6 +33,7 @@
import android.preference.SwitchPreference;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.TextView;
import android.widget.Toolbar;

Expand Down Expand Up @@ -202,6 +205,15 @@ private void setPreferenceScreenToolbar() {
.findViewById(android.R.id.content)
.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.setTitle(preferenceScreen.getTitle());
Expand All @@ -219,6 +231,8 @@ private void setPreferenceScreenToolbar() {
toolbarTextView.setTextColor(ThemeUtils.getForegroundColor());
}

setToolbarLayoutParams(toolbar);

rootView.addView(toolbar, 0);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ private void filterPreferences(String query) {
fragment.filterPreferences(query);
}

private static ViewGroup.LayoutParams lp;

public static void setToolbarLayoutParams(Toolbar toolbar) {
if (lp != null) {
toolbar.setLayoutParams(lp);
}
}

private void setToolbar() {
if (!(findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar_parent")) instanceof ViewGroup toolBarParent))
return;
ViewGroup toolBarParent = findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar_parent"));

// Remove dummy toolbar.
for (int i = 0; i < toolBarParent.getChildCount(); i++) {
View view = toolBarParent.getChildAt(i);
if (view != null) {
toolBarParent.removeView(view);
}
}
ViewGroup dummyToolbar = toolBarParent.findViewById(ResourceUtils.getIdIdentifier("revanced_toolbar"));
lp = dummyToolbar.getLayoutParams();
toolBarParent.removeView(dummyToolbar);

Toolbar toolbar = new Toolbar(toolBarParent.getContext());
toolbar.setBackgroundColor(ThemeUtils.getToolbarBackgroundColor());
Expand All @@ -112,6 +116,7 @@ private void setToolbar() {
if (toolbarTextView != null) {
toolbarTextView.setTextColor(ThemeUtils.getForegroundColor());
}
setToolbarLayoutParams(toolbar);
toolBarParent.addView(toolbar, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
android:background="@color/yt_white1"
android:elevation="0dp">

<android.widget.Toolbar
<android.support.v7.widget.Toolbar
android:id="@+id/revanced_toolbar"
android:layout_width="0.0dip"
android:layout_height="0.0dip"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/ytBrandBackgroundSolid"
app:navigationIcon="@drawable/yt_outline_arrow_left_black_24"
app:title="@string/revanced_extended_settings_title" />
Expand Down

0 comments on commit 574cd84

Please sign in to comment.