Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
fix: use try/catch to prevent taking down the app if something goes w…
Browse files Browse the repository at this point in the history
…rong
  • Loading branch information
LisoUseInAIKyrios committed Mar 6, 2024
1 parent 50b49c2 commit 16f9489
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import androidx.annotation.RequiresApi;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.settings.preference.AbstractPreferenceFragment;
import app.revanced.integrations.youtube.patches.DownloadsPatch;
import app.revanced.integrations.youtube.patches.playback.speed.CustomPlaybackSpeedPatch;
Expand All @@ -24,22 +25,26 @@ public class ReVancedPreferenceFragment extends AbstractPreferenceFragment {
protected void initialize() {
super.initialize();

// If the preference was included, then initialize it based on the available playback speed
Preference defaultSpeedPreference = findPreference(Settings.PLAYBACK_SPEED_DEFAULT.key);
if (defaultSpeedPreference instanceof ListPreference) {
CustomPlaybackSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference);
}
try {
// If the preference was included, then initialize it based on the available playback speed
Preference defaultSpeedPreference = findPreference(Settings.PLAYBACK_SPEED_DEFAULT.key);
if (defaultSpeedPreference instanceof ListPreference) {
CustomPlaybackSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference);
}

// Action button hook does not work on older versions.
// Remove the preference to make things simpler.
if (DownloadsPatch.shouldHideActionButtonOverridePreference()) {
Preference downloadActionButton = findPreference(Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.key);
if (downloadActionButton != null) {
PreferenceGroup group = downloadActionButton.getParent();
if (group != null) {
downloadActionButton.getParent().removePreference(downloadActionButton);
// Action button hook does not work on older versions.
// Remove the preference to make things simpler.
if (DownloadsPatch.shouldHideActionButtonOverridePreference()) {
Preference downloadActionButton = findPreference(Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.key);
if (downloadActionButton != null) {
PreferenceGroup group = downloadActionButton.getParent();
if (group != null) {
downloadActionButton.getParent().removePreference(downloadActionButton);
}
}
}
} catch (Exception ex) {
Logger.printException(() -> "initialize failure", ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.revanced.integrations.youtube.videoplayer;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
Expand All @@ -21,7 +20,6 @@ public abstract class BottomControlButton {
private static final Animation fadeOut;

private final WeakReference<ImageView> buttonRef;
private final WeakReference<Context> activityContextRef;
private final BooleanSetting setting;
protected boolean isVisible;

Expand Down Expand Up @@ -62,12 +60,6 @@ public BottomControlButton(@NonNull ViewGroup bottomControlsViewGroup, @NonNull
imageView.setVisibility(View.GONE);

buttonRef = new WeakReference<>(imageView);
activityContextRef = new WeakReference<>(imageView.getContext());
}

@Nullable
public Context getActivityContext() {
return activityContextRef.get();
}

public void setVisibility(boolean visible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public static void initializeButton(View view) {
}
}

@Nullable
public static ExternalDownloadButton getInstance() {
return instance;
}

/**
* Injection point.
*/
Expand Down

0 comments on commit 16f9489

Please sign in to comment.