fix(YouTube): Patched app crashes after first launch or clearing data

This commit is contained in:
inotia00 2025-01-03 22:06:48 +09:00
parent a10e400cfa
commit 1424d0b7a7
2 changed files with 18 additions and 14 deletions

View File

@ -206,8 +206,6 @@ public class GeneralPatch {
// region [Hide navigation bar components] patch // region [Hide navigation bar components] patch
private static final int fillBellCairoBlack = ResourceUtils.getDrawableIdentifier("yt_fill_bell_cairo_black_24");
private static final Map<NavigationButton, Boolean> shouldHideMap = new EnumMap<>(NavigationButton.class) { private static final Map<NavigationButton, Boolean> shouldHideMap = new EnumMap<>(NavigationButton.class) {
{ {
put(NavigationButton.HOME, Settings.HIDE_NAVIGATION_HOME_BUTTON.get()); put(NavigationButton.HOME, Settings.HIDE_NAVIGATION_HOME_BUTTON.get());
@ -231,6 +229,7 @@ public class GeneralPatch {
* @noinspection ALL * @noinspection ALL
*/ */
public static void setCairoNotificationFilledIcon(EnumMap enumMap, Enum tabActivityCairo) { public static void setCairoNotificationFilledIcon(EnumMap enumMap, Enum tabActivityCairo) {
final int fillBellCairoBlack = ResourceUtils.getDrawableIdentifier("yt_fill_bell_cairo_black_24");
if (fillBellCairoBlack != 0) { if (fillBellCairoBlack != 0) {
// It's very unlikely, but Google might fix this issue someday. // It's very unlikely, but Google might fix this issue someday.
// If so, [fillBellCairoBlack] might already be in enumMap. // If so, [fillBellCairoBlack] might already be in enumMap.
@ -240,7 +239,12 @@ public class GeneralPatch {
} }
public static boolean switchCreateWithNotificationButton(boolean original) { public static boolean switchCreateWithNotificationButton(boolean original) {
return Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get() || original; try {
return Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get() || original;
} catch (Exception ex) {
Logger.printException(() -> "switchCreateWithNotificationButton Failed", ex);
}
return original;
} }
public static void navigationTabCreated(NavigationButton button, View tabView) { public static void navigationTabCreated(NavigationButton button, View tabView) {
@ -322,9 +326,6 @@ public class GeneralPatch {
// region [Toolbar components] patch // region [Toolbar components] patch
private static final int generalHeaderAttributeId = ResourceUtils.getAttrIdentifier("ytWordmarkHeader");
private static final int premiumHeaderAttributeId = ResourceUtils.getAttrIdentifier("ytPremiumWordmarkHeader");
public static void setDrawerNavigationHeader(View lithoView) { public static void setDrawerNavigationHeader(View lithoView) {
final int headerAttributeId = getHeaderAttributeId(); final int headerAttributeId = getHeaderAttributeId();
@ -342,8 +343,8 @@ public class GeneralPatch {
public static int getHeaderAttributeId() { public static int getHeaderAttributeId() {
return Settings.CHANGE_YOUTUBE_HEADER.get() return Settings.CHANGE_YOUTUBE_HEADER.get()
? premiumHeaderAttributeId ? ResourceUtils.getAttrIdentifier("ytPremiumWordmarkHeader")
: generalHeaderAttributeId; : ResourceUtils.getAttrIdentifier("ytWordmarkHeader");
} }
public static boolean overridePremiumHeader() { public static boolean overridePremiumHeader() {
@ -355,11 +356,6 @@ public class GeneralPatch {
return ResourceUtils.getDrawable(""); return ResourceUtils.getDrawable("");
} }
private static final int searchBarId = ResourceUtils.getIdIdentifier("search_bar");
private static final int youtubeTextId = ResourceUtils.getIdIdentifier("youtube_text");
private static final int searchBoxId = ResourceUtils.getIdIdentifier("search_box");
private static final int searchIconId = ResourceUtils.getIdIdentifier("search_icon");
private static final boolean wideSearchbarEnabled = Settings.ENABLE_WIDE_SEARCH_BAR.get(); private static final boolean wideSearchbarEnabled = Settings.ENABLE_WIDE_SEARCH_BAR.get();
// Loads the search bar deprecated by Google. // Loads the search bar deprecated by Google.
private static final boolean wideSearchbarWithHeaderEnabled = Settings.ENABLE_WIDE_SEARCH_BAR_WITH_HEADER.get(); private static final boolean wideSearchbarWithHeaderEnabled = Settings.ENABLE_WIDE_SEARCH_BAR_WITH_HEADER.get();
@ -398,12 +394,18 @@ public class GeneralPatch {
public static void setWideSearchBarLayout(View view) { public static void setWideSearchBarLayout(View view) {
if (!wideSearchbarEnabled) if (!wideSearchbarEnabled)
return; return;
final int searchBarId = ResourceUtils.getIdIdentifier("search_bar");
if (!(view.findViewById(searchBarId) instanceof RelativeLayout searchBarView)) if (!(view.findViewById(searchBarId) instanceof RelativeLayout searchBarView))
return; return;
// When the deprecated search bar is loaded, two search bars overlap. // When the deprecated search bar is loaded, two search bars overlap.
// Manually hides another search bar. // Manually hides another search bar.
if (wideSearchbarWithHeaderEnabled) { if (wideSearchbarWithHeaderEnabled) {
final int youtubeTextId = ResourceUtils.getIdIdentifier("youtube_text");
final int searchBoxId = ResourceUtils.getIdIdentifier("search_box");
final int searchIconId = ResourceUtils.getIdIdentifier("search_icon");
final View searchIconView = searchBarView.findViewById(searchIconId); final View searchIconView = searchBarView.findViewById(searchIconId);
final View searchBoxView = searchBarView.findViewById(searchBoxId); final View searchBoxView = searchBarView.findViewById(searchBoxId);
final View textView = searchBarView.findViewById(youtubeTextId); final View textView = searchBarView.findViewById(youtubeTextId);

View File

@ -87,8 +87,10 @@ abstract class BaseGestureController(
distanceX: Float, distanceX: Float,
distanceY: Float, distanceY: Float,
): Boolean { ): Boolean {
if (from == null) return false
// submit to swipe detector // submit to swipe detector
submitForSwipe(from!!, to, distanceX, distanceY) submitForSwipe(from, to, distanceX, distanceY)
// call swipe callback if in a swipe // call swipe callback if in a swipe
return if (currentSwipe != SwipeDetector.SwipeDirection.NONE) { return if (currentSwipe != SwipeDetector.SwipeDirection.NONE) {