generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube - Spoof video streams): Fix error toast that is sometimes…
… shown (#4090)
- Loading branch information
1 parent
be72064
commit 4c46cb2
Showing
4 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...vanced/extension/youtube/settings/preference/SpoofStreamingDataSideEffectsPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package app.revanced.extension.youtube.settings.preference; | ||
|
||
import static app.revanced.extension.shared.StringRef.str; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceManager; | ||
import android.util.AttributeSet; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import app.revanced.extension.shared.Logger; | ||
import app.revanced.extension.shared.Utils; | ||
import app.revanced.extension.shared.settings.BaseSettings; | ||
import app.revanced.extension.shared.settings.Setting; | ||
import app.revanced.extension.shared.spoof.ClientType; | ||
|
||
@SuppressWarnings({"deprecation", "unused"}) | ||
public class SpoofStreamingDataSideEffectsPreference extends Preference { | ||
|
||
@Nullable | ||
private ClientType currentClientType; | ||
|
||
private final SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, str) -> { | ||
// Because this listener may run before the ReVanced settings fragment updates Settings, | ||
// this could show the prior config and not the current. | ||
// | ||
// Push this call to the end of the main run queue, | ||
// so all other listeners are done and Settings is up to date. | ||
Utils.runOnMainThread(this::updateUI); | ||
}; | ||
|
||
public SpoofStreamingDataSideEffectsPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
public SpoofStreamingDataSideEffectsPreference(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public SpoofStreamingDataSideEffectsPreference(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public SpoofStreamingDataSideEffectsPreference(Context context) { | ||
super(context); | ||
} | ||
|
||
private void addChangeListener() { | ||
Setting.preferences.preferences.registerOnSharedPreferenceChangeListener(listener); | ||
} | ||
|
||
private void removeChangeListener() { | ||
Setting.preferences.preferences.unregisterOnSharedPreferenceChangeListener(listener); | ||
} | ||
|
||
@Override | ||
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) { | ||
super.onAttachedToHierarchy(preferenceManager); | ||
updateUI(); | ||
addChangeListener(); | ||
} | ||
|
||
@Override | ||
protected void onPrepareForRemoval() { | ||
super.onPrepareForRemoval(); | ||
removeChangeListener(); | ||
} | ||
|
||
private void updateUI() { | ||
ClientType clientType = BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get(); | ||
if (currentClientType == clientType) { | ||
return; | ||
} | ||
|
||
Logger.printDebug(() -> "Updating spoof stream side effects preference"); | ||
setEnabled(BaseSettings.SPOOF_VIDEO_STREAMS.get()); | ||
|
||
String key = "revanced_spoof_video_streams_about_" | ||
+ clientType.name().toLowerCase(); | ||
setTitle(str(key + "_title")); | ||
setSummary(str(key + "_summary")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters