You've already forked revanced-integrations
mirror of
https://github.com/revanced/revanced-integrations
synced 2025-11-19 03:23:27 +01:00
Compare commits
10 Commits
v0.94.0-de
...
v0.94.0-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af105dd03 | ||
|
|
d12d74747a | ||
|
|
42346ee3cf | ||
|
|
dbf1f3f0ce | ||
|
|
a70e80dfa0 | ||
|
|
7551f0104c | ||
|
|
d8bd27251c | ||
|
|
04147c17c9 | ||
|
|
32dc8a846c | ||
|
|
03764bcc65 |
35
CHANGELOG.md
35
CHANGELOG.md
@@ -1,3 +1,38 @@
|
||||
# [0.94.0-dev.7](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.6...v0.94.0-dev.7) (2023-01-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **youtube/sponsorblock:** fix saving and loading settings ([#304](https://github.com/revanced/revanced-integrations/issues/304)) ([d12d747](https://github.com/revanced/revanced-integrations/commit/d12d74747aacd98edee929d84dc9cf7f49f56a52))
|
||||
|
||||
# [0.94.0-dev.6](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.5...v0.94.0-dev.6) (2023-01-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **youtube:** show toasts along exceptions ([#293](https://github.com/revanced/revanced-integrations/issues/293)) ([dbf1f3f](https://github.com/revanced/revanced-integrations/commit/dbf1f3f0ce0500752e5d6c4ce49d7d2b27cc6dc4))
|
||||
|
||||
# [0.94.0-dev.5](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.4...v0.94.0-dev.5) (2023-01-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **youtube/return-youtube-dislike:** do not fetch voting stats when watching shorts ([#302](https://github.com/revanced/revanced-integrations/issues/302)) ([7551f01](https://github.com/revanced/revanced-integrations/commit/7551f0104c463714749acc6abedbea5cd7afb52f))
|
||||
|
||||
# [0.94.0-dev.4](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.3...v0.94.0-dev.4) (2023-01-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **youtube/general-ads:** remove hiding video shelf ([04147c1](https://github.com/revanced/revanced-integrations/commit/04147c17c98bccea27e0293a71ffccc97f5a155d))
|
||||
|
||||
# [0.94.0-dev.3](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.2...v0.94.0-dev.3) (2023-01-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **youtube/return-youtube-dislike:** gracefully exit if Vanced MicroG is missing or not running ([#303](https://github.com/revanced/revanced-integrations/issues/303)) ([03764bc](https://github.com/revanced/revanced-integrations/commit/03764bcc651c6b723a999a58ed9cc9d253075905))
|
||||
|
||||
# [0.94.0-dev.2](https://github.com/revanced/revanced-integrations/compare/v0.94.0-dev.1...v0.94.0-dev.2) (2023-01-22)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package app.revanced.integrations.patches;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import app.revanced.integrations.adremover.AdRemoverAPI;
|
||||
import app.revanced.integrations.settings.SettingsEnum;
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
@@ -32,7 +31,6 @@ public final class GeneralAdsPatch extends Filter {
|
||||
var paidContent = new BlockRule(SettingsEnum.ADREMOVER_PAID_CONTENT_REMOVAL, "paid_content_overlay");
|
||||
var merchandise = new BlockRule(SettingsEnum.ADREMOVER_MERCHANDISE_REMOVAL, "product_carousel");
|
||||
var infoPanel = new BlockRule(SettingsEnum.ADREMOVER_INFO_PANEL_REMOVAL, "publisher_transparency_panel", "single_item_information_panel");
|
||||
var suggestions = new BlockRule(SettingsEnum.ADREMOVER_SUGGESTIONS_REMOVAL, "horizontal_video_shelf");
|
||||
var latestPosts = new BlockRule(SettingsEnum.ADREMOVER_HIDE_LATEST_POSTS, "post_shelf");
|
||||
var channelGuidelines = new BlockRule(SettingsEnum.ADREMOVER_HIDE_CHANNEL_GUIDELINES, "channel_guidelines_entry_banner");
|
||||
var artistCard = new BlockRule(SettingsEnum.HIDE_ARTIST_CARD, "official_card");
|
||||
@@ -69,7 +67,6 @@ public final class GeneralAdsPatch extends Filter {
|
||||
buttonedAd,
|
||||
communityPosts,
|
||||
paidContent,
|
||||
suggestions,
|
||||
latestPosts,
|
||||
movieAds,
|
||||
chapterTeaser,
|
||||
@@ -115,7 +112,7 @@ public final class GeneralAdsPatch extends Filter {
|
||||
else
|
||||
result = BlockResult.UNBLOCKED;
|
||||
|
||||
log(String.format("%s (ID: %s): %s", result.message, identifier, path));
|
||||
LogHelper.printDebug(() -> String.format("%s (ID: %s): %s", result.message, identifier, path));
|
||||
|
||||
return result.filter;
|
||||
}
|
||||
@@ -144,7 +141,7 @@ public final class GeneralAdsPatch extends Filter {
|
||||
private static void hideView(SettingsEnum condition, View view) {
|
||||
if (!condition.getBoolean()) return;
|
||||
|
||||
log("Hiding view with setting: " + condition);
|
||||
LogHelper.printDebug(() -> "Hiding view with setting: " + condition);
|
||||
|
||||
AdRemoverAPI.HideViewWithLayout1dp(view);
|
||||
}
|
||||
@@ -167,7 +164,4 @@ public final class GeneralAdsPatch extends Filter {
|
||||
hideView(SettingsEnum.ADREMOVER_SHORTS_REMOVAL, view);
|
||||
}
|
||||
|
||||
private static void log(String message) {
|
||||
LogHelper.printDebug(() -> message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ public class HideCreateButtonPatch {
|
||||
//Used by app.revanced.patches.youtube.layout.createbutton.patch.CreateButtonRemoverPatch
|
||||
public static void hideCreateButton(View view) {
|
||||
boolean hidden = SettingsEnum.HIDE_CREATE_BUTTON.getBoolean();
|
||||
String message = "Create button: " + (hidden ? "hidden" : "shown");
|
||||
LogHelper.printDebug(() -> message);
|
||||
LogHelper.printDebug(() -> "Create button: " + (hidden ? "hidden" : "shown"));
|
||||
view.setVisibility(hidden ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,9 @@ public class HideShortsButtonPatch {
|
||||
public static void hideShortsButton(View view) {
|
||||
if (lastPivotTab != null && lastPivotTab.name() == "TAB_SHORTS") {
|
||||
boolean hide = SettingsEnum.HIDE_SHORTS_BUTTON.getBoolean();
|
||||
String message = hide ? "Shorts button: hidden" : "Shorts button: shown";
|
||||
LogHelper.printDebug(() -> message);
|
||||
LogHelper.printDebug(() -> hide ? "Shorts button: hidden" : "Shorts button: shown");
|
||||
if (hide) {
|
||||
view.setVisibility(hide ? View.GONE : View.VISIBLE);
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,16 @@ public class MicroGSupport {
|
||||
try {
|
||||
context.getPackageManager().getPackageInfo(MICROG_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
|
||||
} catch (PackageManager.NameNotFoundException exception) {
|
||||
LogHelper.printException(() -> ("Vanced MicroG was not found"), exception);
|
||||
LogHelper.printInfo(() -> "Vanced MicroG was not found", exception);
|
||||
startIntent(context, VANCED_MICROG_DOWNLOAD_LINK, str("microg_not_installed_warning"));
|
||||
|
||||
// Gracefully exit the app, so it does not crash.
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
try (var client = context.getContentResolver().acquireContentProviderClient(VANCED_MICROG_PROVIDER)) {
|
||||
if (client != null) return;
|
||||
LogHelper.printException(() -> ("Vanced MicroG is not running in the background"));
|
||||
LogHelper.printInfo(() -> "Vanced MicroG is not running in the background");
|
||||
startIntent(context, DONT_KILL_MY_APP_LINK, str("microg_not_running_warning"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package app.revanced.integrations.patches;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.shared.PlayerType;
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
|
||||
/**
|
||||
* Hook receiver class for 'player-type-hook' patch
|
||||
@@ -24,7 +24,9 @@ public class PlayerTypeHookPatch {
|
||||
|
||||
// update current player type
|
||||
final PlayerType newType = PlayerType.safeParseFromString(type.toString());
|
||||
if (newType != null) {
|
||||
if (newType == null) {
|
||||
LogHelper.printException(() -> "Unknown PlayerType encountered: " + type);
|
||||
} else {
|
||||
PlayerType.setCurrent(newType);
|
||||
LogHelper.printDebug(() -> "YouTubePlayerOverlaysLayout player type was updated to " + newType);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class VideoInformation {
|
||||
seekMethod = thisRef.getClass().getMethod(SEEK_METHOD_NAME, Long.TYPE);
|
||||
seekMethod.setAccessible(true);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
LogHelper.printDebug(() -> "Failed to initialize: " + ex.getMessage());
|
||||
LogHelper.printException(() -> "Failed to initialize", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class VideoInformation {
|
||||
LogHelper.printDebug(() -> "Seeking to " + millisecond);
|
||||
seekMethod.invoke(playerController.get(), millisecond);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printDebug(() -> "Failed to seek: " + ex.getMessage());
|
||||
LogHelper.printException(() -> "Failed to seek", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package app.revanced.integrations.patches.playback.quality;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
@@ -26,24 +27,25 @@ public class RememberVideoQualityPatch {
|
||||
if (isConnectedWifi(context)) {
|
||||
try {
|
||||
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality + "");
|
||||
String message = "Changing default Wi-Fi quality to: " + defaultQuality;
|
||||
LogHelper.printDebug(() -> message);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Failed to change default WI-FI quality:" + ex));
|
||||
Toast.makeText(context, "Failed to change default WI-FI quality:", Toast.LENGTH_SHORT).show();
|
||||
LogHelper.printException(() -> "Failed to change default WI-FI quality", ex);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Changing default Wi-Fi quality to: " + defaultQuality);
|
||||
Toast.makeText(context, "Changing default Wi-Fi quality to: " + defaultQuality, Toast.LENGTH_SHORT).show();
|
||||
} else if (isConnectedMobile(context)) {
|
||||
try {
|
||||
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality + "");
|
||||
String message = "Changing default mobile data quality to:" + defaultQuality;
|
||||
LogHelper.printDebug(() -> message);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printDebug(() -> "Failed to change default mobile data quality" + ex);
|
||||
Toast.makeText(context, "Failed to change default mobile data quality", Toast.LENGTH_SHORT).show();
|
||||
LogHelper.printException(() -> "Failed to change default mobile data quality", ex);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Changing default mobile data quality to:" + defaultQuality);
|
||||
Toast.makeText(context, "Changing default mobile data quality to:" + defaultQuality, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
LogHelper.printDebug(() -> "No internet connection.");
|
||||
Toast.makeText(context, "No internet connection.", Toast.LENGTH_SHORT).show();
|
||||
String message = "No internet connection.";
|
||||
LogHelper.printDebug(() -> message);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
userChangedQuality = false;
|
||||
}
|
||||
@@ -88,7 +90,7 @@ public class RememberVideoQualityPatch {
|
||||
LogHelper.printDebug(() -> "Quality: " + qualityToLog);
|
||||
Context context = ReVancedUtils.getContext();
|
||||
if (context == null) {
|
||||
LogHelper.printException(() -> ("Context is null or settings not initialized, returning quality: " + qualityToLog));
|
||||
LogHelper.printException(() -> "Context is null or settings not initialized, returning quality: " + qualityToLog);
|
||||
return quality;
|
||||
}
|
||||
if (isConnectedWifi(context)) {
|
||||
@@ -129,8 +131,7 @@ public class RememberVideoQualityPatch {
|
||||
LogHelper.printDebug(() -> "Quality changed to: " + qualityIndex);
|
||||
return qualityIndex;
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Failed to set quality"), ex);
|
||||
Toast.makeText(context, "Failed to set quality", Toast.LENGTH_SHORT).show();
|
||||
LogHelper.printException(() -> "Failed to set quality", ex);
|
||||
return qualityIndex;
|
||||
}
|
||||
}
|
||||
@@ -147,6 +148,7 @@ public class RememberVideoQualityPatch {
|
||||
newVideo = true;
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private static NetworkInfo getNetworkInfo(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getActiveNetworkInfo();
|
||||
|
||||
@@ -2,7 +2,6 @@ package app.revanced.integrations.returnyoutubedislike;
|
||||
|
||||
import static app.revanced.integrations.sponsorblock.StringRef.str;
|
||||
|
||||
import android.content.Context;
|
||||
import android.icu.text.CompactDecimalFormat;
|
||||
import android.os.Build;
|
||||
import android.text.Spannable;
|
||||
@@ -13,7 +12,6 @@ import android.text.style.CharacterStyle;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.ScaleXSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import androidx.annotation.GuardedBy;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -31,6 +29,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import app.revanced.integrations.returnyoutubedislike.requests.RYDVoteData;
|
||||
import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
|
||||
import app.revanced.integrations.settings.SettingsEnum;
|
||||
import app.revanced.integrations.shared.PlayerType;
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import app.revanced.integrations.utils.SharedPrefHelper;
|
||||
@@ -96,7 +95,16 @@ public class ReturnYouTubeDislike {
|
||||
private static NumberFormat dislikePercentageFormatter;
|
||||
|
||||
public static void onEnabledChange(boolean enabled) {
|
||||
isEnabled = enabled;
|
||||
synchronized (videoIdLockObject) {
|
||||
isEnabled = enabled;
|
||||
if (!enabled) {
|
||||
// must clear old values, to protect against using stale data
|
||||
// if the user re-enables RYD while watching a video
|
||||
LogHelper.printDebug(() -> "Clearing previously fetched RYD vote data");
|
||||
currentVideoId = null;
|
||||
voteFetchFuture = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCurrentVideoId() {
|
||||
@@ -117,8 +125,12 @@ public class ReturnYouTubeDislike {
|
||||
if (!isEnabled) return;
|
||||
try {
|
||||
Objects.requireNonNull(videoId);
|
||||
LogHelper.printDebug(() -> "New video loaded: " + videoId);
|
||||
|
||||
PlayerType currentPlayerType = PlayerType.getCurrent();
|
||||
if (currentPlayerType == PlayerType.INLINE_MINIMAL) {
|
||||
LogHelper.printDebug(() -> "Ignoring inline playback of video: "+ videoId);
|
||||
return;
|
||||
}
|
||||
LogHelper.printDebug(() -> " new video loaded: " + videoId + " playerType: " + currentPlayerType);
|
||||
synchronized (videoIdLockObject) {
|
||||
currentVideoId = videoId;
|
||||
// no need to wrap the call in a try/catch,
|
||||
@@ -157,6 +169,10 @@ public class ReturnYouTubeDislike {
|
||||
long fetchStartTime = 0;
|
||||
try {
|
||||
Future<RYDVoteData> fetchFuture = getVoteFetchFuture();
|
||||
if (fetchFuture == null) {
|
||||
LogHelper.printDebug(() -> "fetch future not available (user enabled RYD while video was playing?)");
|
||||
return;
|
||||
}
|
||||
if (SettingsEnum.DEBUG.getBoolean() && !fetchFuture.isDone()) {
|
||||
fetchStartTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -175,8 +191,7 @@ public class ReturnYouTubeDislike {
|
||||
if (updateDislike(textRef, isSegmentedButton, votingData)) {
|
||||
LogHelper.printDebug(() -> "Updated dislike span to: " + textRef.get());
|
||||
} else {
|
||||
LogHelper.printDebug(() -> "Ignoring dislike span: " + textRef.get()
|
||||
+ " that appears to already show voting data: " + votingData);
|
||||
LogHelper.printDebug(() -> "Ignoring already updated dislike span: " + textRef.get());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "Error while trying to update dislikes", ex);
|
||||
@@ -187,12 +202,24 @@ public class ReturnYouTubeDislike {
|
||||
if (!isEnabled) return;
|
||||
try {
|
||||
Objects.requireNonNull(vote);
|
||||
|
||||
if (PlayerType.getCurrent() == PlayerType.NONE) { // should occur if shorts is playing
|
||||
LogHelper.printDebug(() -> "Ignoring vote during Shorts playback");
|
||||
return;
|
||||
}
|
||||
if (SharedPrefHelper.getBoolean(SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true)) {
|
||||
LogHelper.printDebug(() -> "User is logged out, ignoring voting");
|
||||
return;
|
||||
}
|
||||
|
||||
// Must make a local copy of videoId, since it may change between now and when the vote thread runs
|
||||
String videoIdToVoteFor = getCurrentVideoId();
|
||||
if (videoIdToVoteFor == null) {
|
||||
// user enabled RYD after starting playback of a video
|
||||
LogHelper.printException(() -> "Cannot vote, current video is is null (user enabled RYD while video was playing?)",
|
||||
null, str("revanced_ryd_failure_ryd_enabled_while_playing_video_then_user_voted"));
|
||||
return;
|
||||
}
|
||||
|
||||
voteSerialExecutor.execute(() -> {
|
||||
// must wrap in try/catch to properly log exceptions
|
||||
@@ -278,9 +305,6 @@ public class ReturnYouTubeDislike {
|
||||
//
|
||||
// Change the "Likes" string to show that likes and dislikes are hidden
|
||||
//
|
||||
LogHelper.printDebug(() -> "Like count is hidden by video creator. "
|
||||
+ "RYD does not provide data for videos with hidden likes.");
|
||||
|
||||
String hiddenMessageString = str("revanced_ryd_video_likes_hidden_by_video_owner");
|
||||
if (hiddenMessageString.equals(oldLikesString)) {
|
||||
return false;
|
||||
@@ -449,7 +473,6 @@ public class ReturnYouTubeDislike {
|
||||
|
||||
private static String formatDislikeCount(long dislikeCount) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
String formatted;
|
||||
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
||||
if (dislikeCountFormatter == null) {
|
||||
// Note: Java number formatters will use the locale specific number characters.
|
||||
@@ -460,18 +483,15 @@ public class ReturnYouTubeDislike {
|
||||
LogHelper.printDebug(() -> "Locale: " + locale);
|
||||
dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT);
|
||||
}
|
||||
formatted = dislikeCountFormatter.format(dislikeCount);
|
||||
return dislikeCountFormatter.format(dislikeCount);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Dislike count: " + dislikeCount + " formatted as: " + formatted);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
// never will be reached, as the oldest supported YouTube app requires Android N or greater
|
||||
// will never be reached, as the oldest supported YouTube app requires Android N or greater
|
||||
return String.valueOf(dislikeCount);
|
||||
}
|
||||
|
||||
private static String formatDislikePercentage(float dislikePercentage) {
|
||||
String formatted;
|
||||
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
||||
if (dislikePercentageFormatter == null) {
|
||||
Locale locale = ReVancedUtils.getContext().getResources().getConfiguration().locale;
|
||||
@@ -483,10 +503,8 @@ public class ReturnYouTubeDislike {
|
||||
} else {
|
||||
dislikePercentageFormatter.setMaximumFractionDigits(1); // show up to 1 digit precision
|
||||
}
|
||||
formatted = dislikePercentageFormatter.format(dislikePercentage);
|
||||
return dislikePercentageFormatter.format(dislikePercentage);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Dislike percentage: " + dislikePercentage + " formatted as: " + formatted);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
|
||||
@@ -500,6 +518,7 @@ public class ReturnYouTubeDislike {
|
||||
*/
|
||||
private static volatile long totalTimeUIWaitedOnNetworkCalls;
|
||||
|
||||
@SuppressWarnings("NonAtomicOperationOnVolatileField")
|
||||
private static void recordTimeUISpentWaitingForNetworkCall(long timeUIWaitStarted) {
|
||||
if (timeUIWaitStarted == 0 || !SettingsEnum.DEBUG.getBoolean()) {
|
||||
return;
|
||||
|
||||
@@ -185,11 +185,15 @@ public class ReturnYouTubeDislikeApi {
|
||||
lastTimeRateLimitWasHit = System.currentTimeMillis();
|
||||
LogHelper.printDebug(() -> "API rate limit was hit. Stopping API calls for the next "
|
||||
+ RATE_LIMIT_BACKOFF_SECONDS + " seconds");
|
||||
ReVancedUtils.runOnMainThread(() -> { // must show toasts on main thread
|
||||
Toast.makeText(ReVancedUtils.getContext(), str("revanced_ryd_failure_client_rate_limit_requested"), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NonAtomicOperationOnVolatileField") // do not want to pay performance cost of full synchronization for debug fields that are only estimates anyways
|
||||
private static void updateStatistics(long timeNetworkCallStarted, long timeNetworkCallEnded, boolean connectionError, boolean rateLimitHit) {
|
||||
if (connectionError && rateLimitHit) {
|
||||
throw new IllegalArgumentException("both connection error and rate limit parameter were true");
|
||||
@@ -202,11 +206,9 @@ public class ReturnYouTubeDislikeApi {
|
||||
if (connectionError) {
|
||||
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
||||
fetchCallNumberOfFailures++;
|
||||
showToast("revanced_ryd_failure_connection_timeout");
|
||||
} else if (rateLimitHit) {
|
||||
fetchCallResponseTimeLast = FETCH_CALL_RESPONSE_TIME_VALUE_RATE_LIMIT;
|
||||
numberOfRateLimitRequestsEncountered++;
|
||||
showToast("revanced_ryd_failure_client_rate_limit_requested");
|
||||
} else {
|
||||
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
||||
}
|
||||
@@ -226,6 +228,7 @@ public class ReturnYouTubeDislikeApi {
|
||||
LogHelper.printDebug(() -> "Fetching votes for: " + videoId);
|
||||
final long timeNetworkCallStarted = System.currentTimeMillis();
|
||||
|
||||
String connectionErrorMessageStringKey = "revanced_ryd_failure_connection_timeout";
|
||||
try {
|
||||
HttpURLConnection connection = getRYDConnectionFromRoute(ReturnYouTubeDislikeRoutes.GET_DISLIKES, videoId);
|
||||
// request headers, as per https://returnyoutubedislike.com/docs/fetching
|
||||
@@ -261,12 +264,12 @@ public class ReturnYouTubeDislikeApi {
|
||||
// fall thru to update statistics
|
||||
}
|
||||
} else {
|
||||
LogHelper.printDebug(() -> "Failed to fetch votes for video: " + videoId
|
||||
+ " response code was: " + responseCode);
|
||||
LogHelper.printException(() -> "Failed to fetch votes for video: " + videoId
|
||||
+ " response code was: " + responseCode, null, str(connectionErrorMessageStringKey));
|
||||
connection.disconnect(); // something went wrong, might as well disconnect
|
||||
}
|
||||
} catch (Exception ex) { // connection timed out, response timeout, or some other network error
|
||||
LogHelper.printException(() -> "Failed to fetch votes", ex);
|
||||
LogHelper.printException(() -> "Failed to fetch votes", ex, str(connectionErrorMessageStringKey));
|
||||
}
|
||||
|
||||
updateStatistics(timeNetworkCallStarted, System.currentTimeMillis(), true, false);
|
||||
@@ -304,13 +307,12 @@ public class ReturnYouTubeDislikeApi {
|
||||
String solution = solvePuzzle(challenge, difficulty);
|
||||
return confirmRegistration(userId, solution);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Failed to register new user: " + userId
|
||||
LogHelper.printException(() -> "Failed to register new user: " + userId
|
||||
+ " response code was: " + responseCode);
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "Failed to register user", ex);
|
||||
}
|
||||
showToast("revanced_ryd_failure_register_user");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -344,10 +346,10 @@ public class ReturnYouTubeDislikeApi {
|
||||
LogHelper.printDebug(() -> "Registration confirmation successful for user: " + userId);
|
||||
return userId;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Failed to confirm registration for user: " + userId
|
||||
LogHelper.printException(() -> "Failed to confirm registration for user: " + userId
|
||||
+ " solution: " + solution + " response string was: " + result);
|
||||
} else {
|
||||
LogHelper.printDebug(() -> "Failed to confirm registration for user: " + userId
|
||||
LogHelper.printException(() -> "Failed to confirm registration for user: " + userId
|
||||
+ " solution: " + solution + " response code was: " + responseCode);
|
||||
}
|
||||
connection.disconnect(); // something went wrong, might as well disconnect
|
||||
@@ -355,8 +357,6 @@ public class ReturnYouTubeDislikeApi {
|
||||
LogHelper.printException(() -> "Failed to confirm registration for user: " + userId
|
||||
+ "solution: " + solution, ex);
|
||||
}
|
||||
showToast("revanced_ryd_failure_confirm_user");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -395,14 +395,13 @@ public class ReturnYouTubeDislikeApi {
|
||||
String solution = solvePuzzle(challenge, difficulty);
|
||||
return confirmVote(videoId, userId, solution);
|
||||
}
|
||||
LogHelper.printDebug(() -> "Failed to send vote for video: " + videoId
|
||||
LogHelper.printException(() -> "Failed to send vote for video: " + videoId
|
||||
+ " userId: " + userId + " vote: " + vote + " response code was: " + responseCode);
|
||||
connection.disconnect(); // something went wrong, might as well disconnect
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "Failed to send vote for video: " + videoId
|
||||
+ " user: " + userId + " vote: " + vote, ex);
|
||||
}
|
||||
showToast("revanced_ryd_failure_send_vote_failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -438,10 +437,10 @@ public class ReturnYouTubeDislikeApi {
|
||||
LogHelper.printDebug(() -> "Vote confirm successful for video: " + videoId);
|
||||
return true;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Failed to confirm vote for video: " + videoId
|
||||
LogHelper.printException(() -> "Failed to confirm vote for video: " + videoId
|
||||
+ " user: " + userId + " solution: " + solution + " response string was: " + result);
|
||||
} else {
|
||||
LogHelper.printDebug(() -> "Failed to confirm vote for video: " + videoId
|
||||
LogHelper.printException(() -> "Failed to confirm vote for video: " + videoId
|
||||
+ " user: " + userId + " solution: " + solution + " response code was: " + responseCode);
|
||||
}
|
||||
connection.disconnect(); // something went wrong, might as well disconnect
|
||||
@@ -449,16 +448,9 @@ public class ReturnYouTubeDislikeApi {
|
||||
LogHelper.printException(() -> "Failed to confirm vote for video: " + videoId
|
||||
+ " user: " + userId + " solution: " + solution, ex);
|
||||
}
|
||||
showToast("revanced_ryd_failure_confirm_vote_failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void showToast(String toastTextStringKey) {
|
||||
ReVancedUtils.runOnMainThread(() -> { // must show toasts on main thread
|
||||
Toast.makeText(ReVancedUtils.getContext(), str(toastTextStringKey), Toast.LENGTH_LONG).show();
|
||||
});
|
||||
}
|
||||
|
||||
private static void applyCommonPostRequestSettings(HttpURLConnection connection) throws ProtocolException {
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
@@ -477,7 +469,7 @@ public class ReturnYouTubeDislikeApi {
|
||||
byte[] decodedChallenge = Base64.decode(challenge, Base64.NO_WRAP);
|
||||
|
||||
byte[] buffer = new byte[20];
|
||||
for (int i = 4; i < 20; i++) {
|
||||
for (int i = 4; i < 20; i++) { // FIXME replace with System.arrayCopy
|
||||
buffer[i] = decodedChallenge[i - 4];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package app.revanced.integrations.settings;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import app.revanced.integrations.utils.SharedPrefHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum SettingsEnum {
|
||||
//Download Settings
|
||||
// TODO: DOWNLOAD_PATH("revanced_download_path", Environment.getExternalStorageDirectory().getPath() + "/Download", ReturnType.STRING),
|
||||
@@ -47,7 +46,6 @@ public enum SettingsEnum {
|
||||
ADREMOVER_INFO_PANEL_REMOVAL("revanced_adremover_info_panel", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_MEDICAL_PANEL_REMOVAL("revanced_adremover_medical_panel", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_PAID_CONTENT_REMOVAL("revanced_adremover_paid_content", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_SUGGESTIONS_REMOVAL("revanced_adremover_hide_suggestions", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_HIDE_LATEST_POSTS("revanced_adremover_hide_latest_posts", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_HIDE_CHANNEL_GUIDELINES("revanced_adremover_hide_channel_guidelines", true, ReturnType.BOOLEAN),
|
||||
ADREMOVER_SELF_SPONSOR_REMOVAL("revanced_adremover_self_sponsor", true, ReturnType.BOOLEAN),
|
||||
@@ -117,9 +115,10 @@ public enum SettingsEnum {
|
||||
PLAYBACK_MAX_BUFFER("revanced_pref_buffer_for_playback_ms", 2500, ReturnType.INTEGER),
|
||||
MAX_PLAYBACK_BUFFER_AFTER_REBUFFER("revanced_pref_buffer_for_playback_after_rebuffer_ms", 5000, ReturnType.INTEGER),
|
||||
|
||||
// ReVanced settings
|
||||
// Debug settings
|
||||
DEBUG("revanced_debug_enabled", false, ReturnType.BOOLEAN),
|
||||
DEBUG_STACKTRACE("revanced_debug_stacktrace_enabled", false, ReturnType.BOOLEAN),
|
||||
DEBUG_SHOW_TOAST_ON_ERROR("revanced_debug_toast_on_error_enabled", true, ReturnType.BOOLEAN),
|
||||
|
||||
USE_DARK_THEME("app_theme_dark", false, ReturnType.BOOLEAN),
|
||||
|
||||
@@ -145,8 +144,7 @@ public enum SettingsEnum {
|
||||
SB_IS_VIP("sb-is-vip", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
||||
SB_LAST_VIP_CHECK("sb-last-vip-check", 0L, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.LONG),
|
||||
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
||||
SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING),
|
||||
|
||||
SB_API_URL("sb-api-host-url", "https://sponsor.ajay.app", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING),
|
||||
|
||||
//
|
||||
// old deprecated settings, kept around to migrate user settings on existing installations
|
||||
@@ -225,7 +223,7 @@ public enum SettingsEnum {
|
||||
//
|
||||
|
||||
// old/new settings where old is default off, and new has inverted value and is default on
|
||||
SettingsEnum invertedSettingsToMigrate[][] = {
|
||||
SettingsEnum[][] invertedSettingsToMigrate = {
|
||||
{DEPRECATED_FULLSCREEN_PANELS_SHOWN, HIDE_FULLSCREEN_PANELS},
|
||||
{DEPRECATED_CREATE_BUTTON_ENABLED, HIDE_CREATE_BUTTON},
|
||||
{DEPRECATED_SHORTS_BUTTON_SHOWN, HIDE_SHORTS_BUTTON},
|
||||
@@ -235,7 +233,7 @@ public enum SettingsEnum {
|
||||
{DEPRECATED_BRANDING_SHOWN, HIDE_VIDEO_WATERMARK},
|
||||
{DEPRECATED_REMEMBER_VIDEO_QUALITY, REMEMBER_VIDEO_QUALITY_LAST_SELECTED},
|
||||
};
|
||||
for (SettingsEnum oldNewSetting[] : invertedSettingsToMigrate) {
|
||||
for (SettingsEnum[] oldNewSetting : invertedSettingsToMigrate) {
|
||||
// by default, old setting was default off
|
||||
// migrate to new setting of default on
|
||||
SettingsEnum oldSetting = oldNewSetting[0];
|
||||
@@ -254,7 +252,7 @@ public enum SettingsEnum {
|
||||
//
|
||||
// migrate preference of prior 'default off' settings, into replacement setting with different path name but otherwise is identical
|
||||
//
|
||||
SettingsEnum renamedSettings[][] = {
|
||||
SettingsEnum[][] renamedSettings = {
|
||||
{DEPRECATED_HIDE_MIX_PLAYLISTS, HIDE_MIX_PLAYLISTS},
|
||||
{DEPRECATED_HIDE_LIKE_BUTTON, HIDE_LIKE_BUTTON},
|
||||
{DEPRECATED_HIDE_DISLIKE_BUTTON, HIDE_DISLIKE_BUTTON},
|
||||
@@ -263,7 +261,7 @@ public enum SettingsEnum {
|
||||
{DEPRECATED_HIDE_ACTION_BUTTON, HIDE_ACTION_BUTTON},
|
||||
{DEPRECATED_HIDE_SHARE_BUTTON, HIDE_SHARE_BUTTON},
|
||||
};
|
||||
for (SettingsEnum oldNewSetting[] : renamedSettings) {
|
||||
for (SettingsEnum[] oldNewSetting : renamedSettings) {
|
||||
SettingsEnum oldSetting = oldNewSetting[0];
|
||||
SettingsEnum newSetting = oldNewSetting[1];
|
||||
|
||||
@@ -305,7 +303,7 @@ public enum SettingsEnum {
|
||||
defaultValue = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
|
||||
break;
|
||||
default:
|
||||
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + setting.name()));
|
||||
LogHelper.printException(() -> "Setting does not have a valid Type. Name is: " + setting.name());
|
||||
break;
|
||||
}
|
||||
setting.setValue(defaultValue);
|
||||
@@ -338,7 +336,7 @@ public enum SettingsEnum {
|
||||
Context context = ReVancedUtils.getContext();
|
||||
|
||||
if (context == null) {
|
||||
LogHelper.printException(() -> ("Context on SaveValue is null!"));
|
||||
LogHelper.printException(() -> "Context on SaveValue is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -359,33 +357,33 @@ public enum SettingsEnum {
|
||||
SharedPrefHelper.saveString(sharedPref, path, (String) newValue);
|
||||
break;
|
||||
default:
|
||||
LogHelper.printException(() -> ("Setting does not have a valid Type. Name is: " + name()));
|
||||
LogHelper.printException(() -> "Setting does not have a valid Type. Name is: " + name());
|
||||
break;
|
||||
}
|
||||
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
public boolean getBoolean() {
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
public Long getLong() {
|
||||
public int getInt() {
|
||||
return (Integer) value;
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
return (Long) value;
|
||||
}
|
||||
|
||||
public Float getFloat() {
|
||||
public float getFloat() {
|
||||
return (Float) value;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
public Object getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.libraries.social.licenses.LicenseActivity;
|
||||
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
@@ -44,15 +46,23 @@ public class ReVancedSettingActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
getTextView((ViewGroup) base.findViewById(getIdentifier("toolbar", "id"))).setText(preferenceIdentifier);
|
||||
TextView toolbar = getTextView((ViewGroup) base.findViewById(getIdentifier("toolbar", "id")));
|
||||
if (toolbar == null) {
|
||||
// FIXME
|
||||
// https://github.com/revanced/revanced-patches/issues/1384
|
||||
LogHelper.printDebug(() -> "Could not find toolbar");
|
||||
} else {
|
||||
toolbar.setText(preferenceIdentifier);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Couldn't set Toolbar title"), e);
|
||||
LogHelper.printException(() -> "Could not set Toolbar title", e);
|
||||
}
|
||||
|
||||
base.getFragmentManager().beginTransaction().replace(getIdentifier("revanced_settings_fragments", "id"), preferenceFragment).commit();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static <T extends View> T getView(Class<T> typeClass, ViewGroup viewGroup) {
|
||||
if (viewGroup == null) {
|
||||
return null;
|
||||
@@ -67,10 +77,12 @@ public class ReVancedSettingActivity {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ImageButton getImageButton(ViewGroup viewGroup) {
|
||||
return getView(ImageButton.class, viewGroup);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TextView getTextView(ViewGroup viewGroup) {
|
||||
return getView(TextView.class, viewGroup);
|
||||
}
|
||||
|
||||
@@ -66,12 +66,12 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
value = Integer.parseInt(editPref.getText());
|
||||
break;
|
||||
default:
|
||||
LogHelper.printException(() -> ("Setting has no valid return type! " + setting.getReturnType()));
|
||||
LogHelper.printException(() -> "Setting has no valid return type! " + setting.getReturnType());
|
||||
break;
|
||||
}
|
||||
setting.setValue(value);
|
||||
} else {
|
||||
LogHelper.printException(() -> ("Setting cannot be handled! " + pref.toString()));
|
||||
LogHelper.printException(() -> "Setting cannot be handled: " + pref.getClass() + " " + pref.toString());
|
||||
}
|
||||
|
||||
if (ReVancedUtils.getContext() != null && settingsInitialized && setting.shouldRebootOnChange()) {
|
||||
@@ -96,7 +96,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
|
||||
this.settingsInitialized = true;
|
||||
} catch (Throwable th) {
|
||||
LogHelper.printException(() -> ("Error during onCreate()"), th);
|
||||
LogHelper.printException(() -> "Error during onCreate()", th);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
|
||||
private Preference findPreferenceOnScreen(CharSequence key) {
|
||||
if (key == null) {
|
||||
LogHelper.printException(() -> ("Key cannot be null!"));
|
||||
LogHelper.printException(() -> "Key cannot be null!");
|
||||
return null;
|
||||
}
|
||||
Preference pref = null;
|
||||
@@ -144,7 +144,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
private String getPackageName() {
|
||||
Context context = ReVancedUtils.getContext();
|
||||
if (context == null) {
|
||||
LogHelper.printException(() -> ("Context is null, returning com.google.android.youtube!"));
|
||||
LogHelper.printException(() -> "Context is null, returning com.google.android.youtube!");
|
||||
return "com.google.android.youtube";
|
||||
}
|
||||
String PACKAGE_NAME = context.getPackageName();
|
||||
@@ -169,7 +169,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
||||
Resources res = context.getResources();
|
||||
return res.getString(res.getIdentifier(name, "string", context.getPackageName()));
|
||||
} catch (Throwable exception) {
|
||||
LogHelper.printException(() -> ("Resource not found."), exception);
|
||||
LogHelper.printException(() -> "Resource not found.", exception);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
||||
setPreferenceScreen(preferenceScreen);
|
||||
|
||||
enabledPreference = new SwitchPreference(context);
|
||||
enabledPreference.setKey(SettingsEnum.RYD_ENABLED.getPath());
|
||||
enabledPreference.setDefaultValue(SettingsEnum.RYD_ENABLED.getDefaultValue());
|
||||
enabledPreference.setChecked(SettingsEnum.RYD_ENABLED.getBoolean());
|
||||
enabledPreference.setTitle(str("revanced_ryd_enable_title"));
|
||||
enabledPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||
@@ -77,8 +75,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
||||
preferenceScreen.addPreference(enabledPreference);
|
||||
|
||||
percentagePreference = new SwitchPreference(context);
|
||||
percentagePreference.setKey(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getPath());
|
||||
percentagePreference.setDefaultValue(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getDefaultValue());
|
||||
percentagePreference.setChecked(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getBoolean());
|
||||
percentagePreference.setTitle(str("revanced_ryd_dislike_percentage_title"));
|
||||
percentagePreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||
@@ -90,8 +86,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
||||
preferenceScreen.addPreference(percentagePreference);
|
||||
|
||||
compactLayoutPreference = new SwitchPreference(context);
|
||||
compactLayoutPreference.setKey(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getPath());
|
||||
compactLayoutPreference.setDefaultValue(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getDefaultValue());
|
||||
compactLayoutPreference.setChecked(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean());
|
||||
compactLayoutPreference.setTitle(str("revanced_ryd_compact_layout_title"));
|
||||
compactLayoutPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||
|
||||
@@ -171,6 +171,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
screen.addPreference(colorPreference);
|
||||
colorPreference.setTitle(str("color_change"));
|
||||
colorPreference.setSummary(str("color_change_sum"));
|
||||
colorPreference.setSelectable(false);
|
||||
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
||||
}
|
||||
|
||||
@@ -184,6 +185,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
Preference preference = new Preference(context);
|
||||
category.addPreference(preference);
|
||||
preference.setTitle(str("stats_loading"));
|
||||
preference.setSelectable(false);
|
||||
|
||||
SBRequester.retrieveUserStats(category, preference);
|
||||
}
|
||||
@@ -211,6 +213,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
Preference preference = new Preference(context);
|
||||
screen.addPreference(preference);
|
||||
preference.setTitle(str("about_madeby"));
|
||||
preference.setSelectable(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -233,11 +236,14 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
}
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
SwitchPreference preference = new SwitchPreference(context);
|
||||
preference.setTitle(str("general_skiptoast"));
|
||||
preference.setSummary(str("general_skiptoast_sum"));
|
||||
preference.setKey(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getDefaultValue());
|
||||
preference.setChecked(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getBoolean());
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.saveValue(newValue);
|
||||
return true;
|
||||
});
|
||||
preference.setOnPreferenceClickListener(preference12 -> {
|
||||
Toast.makeText(preference12.getContext(), str("skipped_sponsor"), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
@@ -247,21 +253,28 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
}
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
SwitchPreference preference = new SwitchPreference(context);
|
||||
preference.setTitle(str("general_skipcount"));
|
||||
preference.setSummary(str("general_skipcount_sum"));
|
||||
preference.setKey(SettingsEnum.SB_COUNT_SKIPS.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_COUNT_SKIPS.getDefaultValue());
|
||||
preference.setChecked(SettingsEnum.SB_COUNT_SKIPS.getBoolean());
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_COUNT_SKIPS.saveValue(newValue);
|
||||
return true;
|
||||
});
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
screen.addPreference(preference);
|
||||
}
|
||||
|
||||
{
|
||||
Preference preference = new SwitchPreference(context);
|
||||
SwitchPreference preference = new SwitchPreference(context);
|
||||
preference.setTitle(str("general_time_without_sb"));
|
||||
preference.setSummary(str("general_time_without_sb_sum"));
|
||||
preference.setKey(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getDefaultValue());
|
||||
preference.setChecked(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean());
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.saveValue(newValue);
|
||||
return true;
|
||||
});
|
||||
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
screen.addPreference(preference);
|
||||
}
|
||||
@@ -271,8 +284,11 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
preference.setTitle(str("general_adjusting"));
|
||||
preference.setSummary(str("general_adjusting_sum"));
|
||||
preference.setKey(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getDefaultValue() + "");
|
||||
preference.setText(String.valueOf(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getInt()));
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.saveValue(Integer.valueOf(newValue.toString()));
|
||||
return true;
|
||||
});
|
||||
screen.addPreference(preference);
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
}
|
||||
@@ -282,18 +298,25 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
preference.setTitle(str("general_min_duration"));
|
||||
preference.setSummary(str("general_min_duration_sum"));
|
||||
preference.setKey(SettingsEnum.SB_MIN_DURATION.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_MIN_DURATION.getDefaultValue() + "");
|
||||
preference.setText(String.valueOf(SettingsEnum.SB_MIN_DURATION.getFloat()));
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_MIN_DURATION.saveValue(Float.valueOf(newValue.toString()));
|
||||
return true;
|
||||
});
|
||||
screen.addPreference(preference);
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
}
|
||||
|
||||
{
|
||||
Preference preference = new EditTextPreference(context);
|
||||
EditTextPreference preference = new EditTextPreference(context);
|
||||
preference.setTitle(str("general_uuid"));
|
||||
preference.setSummary(str("general_uuid_sum"));
|
||||
preference.setKey(SettingsEnum.SB_UUID.getPath());
|
||||
preference.setDefaultValue(SettingsEnum.SB_UUID.getDefaultValue() + "");
|
||||
preference.setText(SettingsEnum.SB_UUID.getString());
|
||||
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||
SettingsEnum.SB_UUID.saveValue(newValue.toString());
|
||||
return true;
|
||||
});
|
||||
|
||||
screen.addPreference(preference);
|
||||
preferencesToDisableWhenSBDisabled.add(preference);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import app.revanced.integrations.utils.Event
|
||||
*/
|
||||
@Suppress("unused")
|
||||
enum class PlayerType {
|
||||
NONE,
|
||||
NONE, // this also includes when shorts are playing
|
||||
HIDDEN,
|
||||
WATCH_WHILE_MINIMIZED,
|
||||
WATCH_WHILE_MAXIMIZED,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -52,7 +52,7 @@ public class ShieldButton {
|
||||
isShowing = true;
|
||||
changeVisibilityImmediate(false);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Unable to set RelativeLayout"), ex);
|
||||
LogHelper.printException(() -> "Unable to set RelativeLayout", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,29 +69,33 @@ public class ShieldButton {
|
||||
}
|
||||
|
||||
public static void changeVisibility(boolean visible, boolean immediate) {
|
||||
if (isShowing == visible) return;
|
||||
isShowing = visible;
|
||||
try {
|
||||
if (isShowing == visible) return;
|
||||
isShowing = visible;
|
||||
|
||||
ImageView iView = _shieldBtn.get();
|
||||
if (_youtubeControlsLayout == null || iView == null) return;
|
||||
ImageView iView = _shieldBtn.get();
|
||||
if (_youtubeControlsLayout == null || iView == null) return;
|
||||
|
||||
if (visible && shouldBeShown()) {
|
||||
if (getLastKnownVideoTime() >= getCurrentVideoLength()) {
|
||||
if (visible && shouldBeShown()) {
|
||||
if (getLastKnownVideoTime() >= getCurrentVideoLength()) {
|
||||
return;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Fading in");
|
||||
|
||||
iView.setVisibility(View.VISIBLE);
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeIn);
|
||||
return;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Fading in");
|
||||
|
||||
iView.setVisibility(View.VISIBLE);
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeIn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iView.getVisibility() == View.VISIBLE) {
|
||||
LogHelper.printDebug(() -> "Fading out");
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeOut);
|
||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||
if (iView.getVisibility() == View.VISIBLE) {
|
||||
LogHelper.printDebug(() -> "Fading out");
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeOut);
|
||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "changeVisibility failure", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import static app.revanced.integrations.sponsorblock.player.ui.SponsorBlockView.hideSkipButton;
|
||||
import static app.revanced.integrations.sponsorblock.player.ui.SponsorBlockView.showSkipButton;
|
||||
|
||||
@SuppressLint({"RtlHardcoded", "SetTextI18n", "LongLogTag", "AppCompatCustomView"})
|
||||
@SuppressLint({"RtlHardcoded", "SetTextI18n", "AppCompatCustomView"})
|
||||
public class SkipSegmentView {
|
||||
|
||||
private static SponsorSegment lastNotifiedSegment;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SponsorBlockSettings {
|
||||
sponsorBlockUrlCategories = "[%22" + TextUtils.join("%22,%22", enabledCategories) + "%22]";
|
||||
|
||||
String uuid = SettingsEnum.SB_UUID.getString();
|
||||
if (uuid == null) {
|
||||
if (uuid == null || uuid.length() == 0) {
|
||||
uuid = (UUID.randomUUID().toString() +
|
||||
UUID.randomUUID().toString() +
|
||||
UUID.randomUUID().toString())
|
||||
|
||||
@@ -46,12 +46,12 @@ import java.util.TimeZone;
|
||||
import app.revanced.integrations.settings.SettingsEnum;
|
||||
import app.revanced.integrations.sponsorblock.player.PlayerType;
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import app.revanced.integrations.utils.SharedPrefHelper;
|
||||
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||
import app.revanced.integrations.sponsorblock.requests.SBRequester;
|
||||
|
||||
@SuppressWarnings({"LongLogTag"})
|
||||
public abstract class SponsorBlockUtils {
|
||||
public static final String DATE_FORMAT = "HH:mm:ss.SSS";
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
@@ -154,7 +154,7 @@ public abstract class SponsorBlockUtils {
|
||||
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
||||
|
||||
appContext = new WeakReference<>(context);
|
||||
new Thread(submitRunnable).start();
|
||||
ReVancedUtils.runOnBackgroundThread(submitRunnable);
|
||||
}
|
||||
};
|
||||
public static String messageToToast = "";
|
||||
@@ -233,13 +233,13 @@ public abstract class SponsorBlockUtils {
|
||||
final SponsorBlockSettings.SegmentInfo segmentType = SponsorBlockUtils.newSponsorBlockSegmentType;
|
||||
try {
|
||||
if (start < 0 || end < 0 || start >= end || segmentType == null || videoId == null || uuid == null) {
|
||||
LogHelper.printException(() -> ("Unable to submit times, invalid parameters"));
|
||||
LogHelper.printException(() -> "Unable to submit times, invalid parameters");
|
||||
return;
|
||||
}
|
||||
SBRequester.submitSegments(videoId, uuid, ((float) start) / 1000f, ((float) end) / 1000f, segmentType.key, toastRunnable);
|
||||
newSponsorSegmentEndMillis = newSponsorSegmentStartMillis = -1;
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Unable to submit segment"), e);
|
||||
LogHelper.printException(() -> "Unable to submit segment", e);
|
||||
}
|
||||
|
||||
if (videoId != null)
|
||||
@@ -403,11 +403,15 @@ public abstract class SponsorBlockUtils {
|
||||
}
|
||||
|
||||
public static String appendTimeWithoutSegments(String totalTime) {
|
||||
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
|
||||
if (timeWithoutSegments.isEmpty()) {
|
||||
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);
|
||||
try {
|
||||
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
|
||||
if (timeWithoutSegments.isEmpty()) {
|
||||
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);
|
||||
}
|
||||
return totalTime + timeWithoutSegments;
|
||||
}
|
||||
return totalTime + timeWithoutSegments;
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "appendTimeWithoutSegments failure", ex);
|
||||
}
|
||||
|
||||
return totalTime;
|
||||
@@ -436,7 +440,7 @@ public abstract class SponsorBlockUtils {
|
||||
PlayerController.setCurrentVideoId(null);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Player type changed caused a crash."), ex);
|
||||
LogHelper.printException(() -> "Player type changed caused a crash.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,6 +474,7 @@ public abstract class SponsorBlockUtils {
|
||||
category.addPreference(preference);
|
||||
String formatted = FORMATTER.format(stats.getSegmentCount());
|
||||
preference.setTitle(fromHtml(str("stats_submissions", formatted)));
|
||||
preference.setSelectable(false);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -503,6 +508,7 @@ public abstract class SponsorBlockUtils {
|
||||
|
||||
preference.setTitle(fromHtml(str("stats_self_saved", formatted)));
|
||||
preference.setSummary(fromHtml(str("stats_self_saved_sum", formattedSaved)));
|
||||
preference.setSelectable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,25 +547,18 @@ public abstract class SponsorBlockUtils {
|
||||
editor.putString(category.key, behaviour.key);
|
||||
}
|
||||
|
||||
SettingsEnum.SB_UUID.saveValue(settingsJson.getString("userID"));
|
||||
SettingsEnum.SB_IS_VIP.saveValue(settingsJson.getBoolean("isVip"));
|
||||
SettingsEnum.SB_API_URL.saveValue(settingsJson.getString("serverAddress"));
|
||||
SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.saveValue(!settingsJson.getBoolean("dontShowNotice"));
|
||||
SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.saveValue(settingsJson.getBoolean("showTimeWithSkips"));
|
||||
SettingsEnum.SB_COUNT_SKIPS.saveValue(settingsJson.getBoolean("trackViewCount"));
|
||||
SettingsEnum.SB_IS_VIP.saveValue(settingsJson.getBoolean("isVip"));
|
||||
SettingsEnum.SB_MIN_DURATION.saveValue(Float.valueOf(settingsJson.getString("minDuration")));
|
||||
SettingsEnum.SB_UUID.saveValue(settingsJson.getString("userID"));
|
||||
SettingsEnum.SB_LAST_VIP_CHECK.saveValue(settingsJson.getLong("lastIsVipUpdate"));
|
||||
|
||||
|
||||
String serverAddress = settingsJson.getString("serverAddress");
|
||||
if (serverAddress.equalsIgnoreCase("https://sponsor.ajay.app")) {
|
||||
serverAddress = (String) SettingsEnum.SB_API_URL.getDefaultValue();
|
||||
}
|
||||
SettingsEnum.SB_API_URL.saveValue(serverAddress);
|
||||
SettingsEnum.SB_COUNT_SKIPS.saveValue(settingsJson.getBoolean("trackViewCount"));
|
||||
|
||||
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printInfo(() -> "failed to import settings", ex); // use info level, as we are showing our own toast
|
||||
Toast.makeText(context, str("settings_import_failed"), Toast.LENGTH_SHORT).show();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,21 +584,20 @@ public abstract class SponsorBlockUtils {
|
||||
categorySelectionsArray.put(behaviorObject);
|
||||
}
|
||||
}
|
||||
json.put("userID", SettingsEnum.SB_UUID.getString());
|
||||
json.put("isVip", SettingsEnum.SB_IS_VIP.getBoolean());
|
||||
json.put("serverAddress", SettingsEnum.SB_API_URL.getString());
|
||||
json.put("dontShowNotice", !SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getBoolean());
|
||||
json.put("barTypes", barTypesObject);
|
||||
json.put("showTimeWithSkips", SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean());
|
||||
json.put("minDuration", SettingsEnum.SB_MIN_DURATION.getFloat());
|
||||
json.put("trackViewCount", SettingsEnum.SB_COUNT_SKIPS.getBoolean());
|
||||
json.put("categorySelections", categorySelectionsArray);
|
||||
json.put("userID", SettingsEnum.SB_UUID.getString());
|
||||
json.put("isVip", SettingsEnum.SB_IS_VIP.getBoolean());
|
||||
json.put("lastIsVipUpdate", SettingsEnum.SB_LAST_VIP_CHECK.getLong());
|
||||
json.put("serverAddress", SettingsEnum.SB_API_URL.getString());
|
||||
json.put("barTypes", barTypesObject);
|
||||
|
||||
return json.toString();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printInfo(() -> "failed to export settings", ex); // use info level, as we are showing our own toast
|
||||
Toast.makeText(context, str("settings_export_failed"), Toast.LENGTH_SHORT).show();
|
||||
ex.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +103,11 @@ public class StringRef {
|
||||
if (resources != null) {
|
||||
final int identifier = resources.getIdentifier(value, "string", packageName);
|
||||
if (identifier == 0)
|
||||
LogHelper.printException(() -> ("Resource not found: " + value));
|
||||
LogHelper.printException(() -> "Resource not found: " + value);
|
||||
else
|
||||
value = resources.getString(identifier);
|
||||
} else {
|
||||
LogHelper.printException(() -> ("Could not resolve resources!"));
|
||||
LogHelper.printException(() -> "Could not resolve resources!");
|
||||
}
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SwipeHelper {
|
||||
isTabletMode = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Unable to set FrameLayout"), e);
|
||||
LogHelper.printException(() -> "Unable to set FrameLayout", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class SwipeHelper {
|
||||
try {
|
||||
nextGenWatchLayout = (ViewGroup) obj;
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Unable to set _nextGenWatchLayout"), e);
|
||||
LogHelper.printException(() -> "Unable to set _nextGenWatchLayout", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SwipeHelper {
|
||||
}
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Unable to get related_endscreen_results visibility"), e);
|
||||
LogHelper.printException(() -> "Unable to get related_endscreen_results visibility", e);
|
||||
}
|
||||
if (_frameLayout.getChildCount() > 0) {
|
||||
return _frameLayout.getChildAt(0).getVisibility() == View.VISIBLE;
|
||||
@@ -61,7 +61,7 @@ public class SwipeHelper {
|
||||
LogHelper.printDebug(() -> "related_endscreen_results refreshed");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogHelper.printException(() -> ("Unable to refresh related_endscreen_results layout"), e);
|
||||
LogHelper.printException(() -> "Unable to refresh related_endscreen_results layout", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class VotingButton {
|
||||
isShowing = true;
|
||||
changeVisibilityImmediate(false);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Unable to set RelativeLayout"), ex);
|
||||
LogHelper.printException(() -> "Unable to set RelativeLayout", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,28 +68,32 @@ public class VotingButton {
|
||||
}
|
||||
|
||||
public static void changeVisibility(boolean visible, boolean immediate) {
|
||||
if (isShowing == visible) return;
|
||||
isShowing = visible;
|
||||
try {
|
||||
if (isShowing == visible) return;
|
||||
isShowing = visible;
|
||||
|
||||
ImageView iView = _votingButton.get();
|
||||
if (_youtubeControlsLayout == null || iView == null) return;
|
||||
ImageView iView = _votingButton.get();
|
||||
if (_youtubeControlsLayout == null || iView == null) return;
|
||||
|
||||
if (visible && shouldBeShown()) {
|
||||
if (getLastKnownVideoTime() >= getCurrentVideoLength()) {
|
||||
if (visible && shouldBeShown()) {
|
||||
if (getLastKnownVideoTime() >= getCurrentVideoLength()) {
|
||||
return;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Fading in");
|
||||
iView.setVisibility(View.VISIBLE);
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeIn);
|
||||
return;
|
||||
}
|
||||
LogHelper.printDebug(() -> "Fading in");
|
||||
iView.setVisibility(View.VISIBLE);
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeIn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iView.getVisibility() == View.VISIBLE) {
|
||||
LogHelper.printDebug(() -> "Fading out");
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeOut);
|
||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||
if (iView.getVisibility() == View.VISIBLE) {
|
||||
LogHelper.printDebug(() -> "Fading out");
|
||||
if (!immediate)
|
||||
iView.startAnimation(fadeOut);
|
||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "changeVisibility failure", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class SlimButton implements View.OnClickListener {
|
||||
}
|
||||
setContainerVisibility();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Error while changing button visibility"), ex);
|
||||
LogHelper.printException(() -> "Error while changing button visibility", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SponsorBlockView {
|
||||
|
||||
addView();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Unable to set ViewGroup"), ex);
|
||||
LogHelper.printException(() -> "Unable to set ViewGroup", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class SponsorBlockView {
|
||||
setSkipBtnMargins(false);
|
||||
setNewSegmentLayoutMargins(false);
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> ("Player type changed caused a crash."), ex);
|
||||
LogHelper.printException(() -> "Player type changed caused a crash.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,13 +87,13 @@ public class SponsorBlockView {
|
||||
private static void setSkipBtnMargins(boolean fullScreen) {
|
||||
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
||||
if (skipSponsorButton == null) {
|
||||
LogHelper.printException(() -> ("Unable to setSkipBtnMargins"));
|
||||
LogHelper.printException(() -> "Unable to setSkipBtnMargins");
|
||||
return;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) skipSponsorButton.getLayoutParams();
|
||||
if (params == null) {
|
||||
LogHelper.printException(() -> ("Unable to setSkipBtnMargins"));
|
||||
LogHelper.printException(() -> "Unable to setSkipBtnMargins");
|
||||
return;
|
||||
}
|
||||
params.bottomMargin = fullScreen ? skipSponsorButton.ctaBottomMargin : skipSponsorButton.defaultBottomMargin;
|
||||
@@ -103,7 +103,7 @@ public class SponsorBlockView {
|
||||
private static void skipSponsorButtonVisibility(boolean visible) {
|
||||
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
||||
if (skipSponsorButton == null) {
|
||||
LogHelper.printException(() -> ("Unable to skipSponsorButtonVisibility"));
|
||||
LogHelper.printException(() -> "Unable to skipSponsorButtonVisibility");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -116,13 +116,13 @@ public class SponsorBlockView {
|
||||
private static void setNewSegmentLayoutMargins(boolean fullScreen) {
|
||||
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
||||
if (newSegmentLayout == null) {
|
||||
LogHelper.printException(() -> ("Unable to setNewSegmentLayoutMargins"));
|
||||
LogHelper.printException(() -> "Unable to setNewSegmentLayoutMargins");
|
||||
return;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) newSegmentLayout.getLayoutParams();
|
||||
if (params == null) {
|
||||
LogHelper.printException(() -> ("Unable to setNewSegmentLayoutMargins"));
|
||||
LogHelper.printException(() -> "Unable to setNewSegmentLayoutMargins");
|
||||
return;
|
||||
}
|
||||
params.bottomMargin = fullScreen ? newSegmentLayout.ctaBottomMargin : newSegmentLayout.defaultBottomMargin;
|
||||
@@ -132,7 +132,7 @@ public class SponsorBlockView {
|
||||
private static void newSegmentLayoutVisibility(boolean visible) {
|
||||
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
||||
if (newSegmentLayout == null) {
|
||||
LogHelper.printException(() -> ("Unable to newSegmentLayoutVisibility"));
|
||||
LogHelper.printException(() -> "Unable to newSegmentLayoutVisibility");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
|
||||
import app.revanced.integrations.sponsorblock.SponsorBlockUtils.VoteOption;
|
||||
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||
import app.revanced.integrations.utils.ReVancedUtils;
|
||||
import app.revanced.integrations.utils.LogHelper;
|
||||
|
||||
public class SBRequester {
|
||||
private static final String TIME_TEMPLATE = "%.3f";
|
||||
@@ -79,7 +81,7 @@ public class SBRequester {
|
||||
}
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to get segments", ex);
|
||||
}
|
||||
return segments.toArray(new SponsorSegment[0]);
|
||||
}
|
||||
@@ -115,7 +117,7 @@ public class SBRequester {
|
||||
runOnMainThread(toastRunnable);
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to submit segments", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,19 +126,17 @@ public class SBRequester {
|
||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.VIEWED_SEGMENT, segment.UUID);
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to send view count request", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, String... args) {
|
||||
new Thread(() -> {
|
||||
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||
try {
|
||||
String segmentUuid = segment.UUID;
|
||||
String uuid = SettingsEnum.SB_UUID.getString();
|
||||
String vote = Integer.toString(voteOption == VoteOption.UPVOTE ? 1 : 0);
|
||||
|
||||
runOnMainThread(() -> Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show());
|
||||
|
||||
HttpURLConnection connection = voteOption == VoteOption.CATEGORY_CHANGE
|
||||
? getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_CATEGORY, segmentUuid, uuid, args[0])
|
||||
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, segmentUuid, uuid, vote);
|
||||
@@ -156,9 +156,9 @@ public class SBRequester {
|
||||
runOnMainThread(() -> Toast.makeText(context, SponsorBlockUtils.messageToToast, Toast.LENGTH_LONG).show());
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to vote for segment", ex);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
public static void retrieveUserStats(PreferenceCategory category, Preference loadingPreference) {
|
||||
@@ -167,20 +167,22 @@ public class SBRequester {
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||
try {
|
||||
JSONObject json = getJSONObject(SBRoutes.GET_USER_STATS, SettingsEnum.SB_UUID.getString());
|
||||
UserStats stats = new UserStats(json.getString("userName"), json.getDouble("minutesSaved"), json.getInt("segmentCount"),
|
||||
json.getInt("viewCount"));
|
||||
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
||||
runOnMainThread(() -> { // get back on main thread to modify UI elements
|
||||
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to retrieve user stats", ex);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
||||
new Thread(() -> {
|
||||
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||
try {
|
||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SettingsEnum.SB_UUID.getString(), username);
|
||||
int responseCode = connection.getResponseCode();
|
||||
@@ -197,9 +199,9 @@ public class SBRequester {
|
||||
runOnMainThread(toastRunnable);
|
||||
connection.disconnect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to set username", ex);
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
|
||||
public static void runVipCheck() {
|
||||
@@ -213,7 +215,7 @@ public class SBRequester {
|
||||
SettingsEnum.SB_IS_VIP.saveValue(vip);
|
||||
SettingsEnum.SB_LAST_VIP_CHECK.saveValue(now);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogHelper.printException(() -> "failed to check VIP", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ import static app.revanced.integrations.requests.Route.Method.POST;
|
||||
|
||||
import app.revanced.integrations.requests.Route;
|
||||
|
||||
public class SBRoutes {
|
||||
public static final Route IS_USER_VIP = new Route(GET, "isUserVIP?userID={user_id}");
|
||||
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
||||
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
||||
public static final Route GET_USER_STATS = new Route(GET, "userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
||||
public static final Route CHANGE_USERNAME = new Route(POST, "setUsername?userID={user_id}&username={username}");
|
||||
public static final Route SUBMIT_SEGMENTS = new Route(POST, "skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}&videoDuration={duration}");
|
||||
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
||||
public static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
||||
class SBRoutes {
|
||||
static final Route IS_USER_VIP = new Route(GET, "/api/isUserVIP?userID={user_id}");
|
||||
static final Route GET_SEGMENTS = new Route(GET, "/api/skipSegments?videoID={video_id}&categories={categories}");
|
||||
static final Route VIEWED_SEGMENT = new Route(POST, "/api/viewedVideoSponsorTime?UUID={segment_id}");
|
||||
static final Route GET_USER_STATS = new Route(GET, "/api/userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
||||
static final Route CHANGE_USERNAME = new Route(POST, "/api/setUsername?userID={user_id}&username={username}");
|
||||
static final Route SUBMIT_SEGMENTS = new Route(POST, "/api/skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}&videoDuration={duration}");
|
||||
static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "/api/voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
||||
static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "/api/voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
||||
|
||||
private SBRoutes() {
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import android.media.AudioManager
|
||||
import android.os.Build
|
||||
import app.revanced.integrations.swipecontrols.misc.clamp
|
||||
import app.revanced.integrations.utils.LogHelper.printDebug
|
||||
import app.revanced.integrations.utils.LogHelper.printException
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ class AudioVolumeController(
|
||||
// bind audio service
|
||||
val mgr = context.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
||||
if (mgr == null) {
|
||||
printDebug { "failed to acquire AUDIO_SERVICE" }
|
||||
printException { "failed to acquire AUDIO_SERVICE" }
|
||||
} else {
|
||||
audioManager = mgr
|
||||
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package app.revanced.integrations.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
@@ -13,16 +18,19 @@ public class LogHelper {
|
||||
* Log messages using lambdas.
|
||||
*/
|
||||
public interface LogMessage {
|
||||
@NonNull
|
||||
String buildMessageString();
|
||||
|
||||
/**
|
||||
* @return For non inner classes, this returns {@link Class#getSimpleName()}.
|
||||
* For inner classes (static and anonymous), this returns the enclosing class simple name.<br>
|
||||
* @return For outer classes, this returns {@link Class#getSimpleName()}.
|
||||
* For inner, static, or anonymous classes, this returns the simple name of the enclosing class.<br>
|
||||
* <br>
|
||||
* For example, each of these classes return 'SomethingView':<br>
|
||||
* com.company.SomethingView<br>
|
||||
* com.company.SomethingView$StaticClass<br>
|
||||
* com.company.SomethingView$1<br>
|
||||
* For example, each of these classes return 'SomethingView':
|
||||
* <code>
|
||||
* com.company.SomethingView
|
||||
* com.company.SomethingView$StaticClass
|
||||
* com.company.SomethingView$1
|
||||
* </code>
|
||||
*/
|
||||
private String findOuterClassSimpleName() {
|
||||
var selfClass = this.getClass();
|
||||
@@ -32,8 +40,8 @@ public class LogHelper {
|
||||
if (dollarSignIndex == -1) {
|
||||
return selfClass.getSimpleName(); // already an outer class
|
||||
}
|
||||
// else, class is inner class (static or anonymous)
|
||||
|
||||
// class is inner, static, or anonymous
|
||||
// parse the simple name full name
|
||||
// a class with no package returns index of -1, but incrementing gives index zero which is correct
|
||||
final int simpleClassNameStartIndex = fullClassName.lastIndexOf('.') + 1;
|
||||
@@ -41,17 +49,14 @@ public class LogHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs information messages with the most outer class name of the code that is calling this method.
|
||||
*/
|
||||
public static void printInfo(LogMessage message) {
|
||||
Log.i("revanced: " + message.findOuterClassSimpleName(), message.buildMessageString());
|
||||
}
|
||||
private static final String REVANCED_LOG_PREFIX = "revanced: ";
|
||||
|
||||
/**
|
||||
* Logs debug messages with the most outer class name of the code that is calling this method.
|
||||
* Logs debug messages under the outer class name of the code calling this method.
|
||||
* Whenever possible, the log string should be constructed entirely inside {@link LogMessage#buildMessageString()}
|
||||
* so the performance cost of building strings is paid only if {@link SettingsEnum#DEBUG} is enabled.
|
||||
*/
|
||||
public static void printDebug(LogMessage message) {
|
||||
public static void printDebug(@NonNull LogMessage message) {
|
||||
if (SettingsEnum.DEBUG.getBoolean()) {
|
||||
var messageString = message.buildMessageString();
|
||||
|
||||
@@ -60,62 +65,79 @@ public class LogHelper {
|
||||
var sw = new StringWriter();
|
||||
new Throwable().printStackTrace(new PrintWriter(sw));
|
||||
|
||||
builder.append(String.format("\n%s", sw));
|
||||
builder.append('\n').append(sw);
|
||||
messageString = builder.toString();
|
||||
}
|
||||
|
||||
Log.d("revanced: " + message.findOuterClassSimpleName(), messageString);
|
||||
Log.d(REVANCED_LOG_PREFIX + message.findOuterClassSimpleName(), messageString);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs messages with the most outer class name of the code that is calling this method.
|
||||
* Logs information messages using the outer class name of the code calling this method.
|
||||
*/
|
||||
public static void printException(LogMessage message) {
|
||||
Log.e("revanced: " + message.findOuterClassSimpleName(), message.buildMessageString());
|
||||
public static void printInfo(@NonNull LogMessage message) {
|
||||
printInfo(message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs exceptions with the most outer class name of the code that is calling this method.
|
||||
* Logs information messages using the outer class name of the code calling this method.
|
||||
*/
|
||||
public static void printException(LogMessage message, Throwable ex) {
|
||||
Log.e("revanced: " + message.findOuterClassSimpleName(), message.buildMessageString(), ex);
|
||||
public static void printInfo(@NonNull LogMessage message, @Nullable Exception ex) {
|
||||
String logTag = REVANCED_LOG_PREFIX + message.findOuterClassSimpleName();
|
||||
String logMessage = message.buildMessageString();
|
||||
if (ex == null) {
|
||||
Log.i(logTag, logMessage);
|
||||
} else {
|
||||
Log.i(logTag, logMessage, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Instead call {@link #printDebug(LogMessage)},
|
||||
* which does not cause log messages to be constructed unless logging is enabled.
|
||||
* Logs exceptions under the outer class name of the code calling this method.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void debug(Class _clazz, String message) {
|
||||
printDebug(() -> message); // this fails to show the correct calling class name, but it's deprecated who cares
|
||||
public static void printException(@NonNull LogMessage message) {
|
||||
printException(message, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Instead call {@link #printException(LogMessage, Throwable)}
|
||||
* or {@link #printException(LogMessage)}
|
||||
* which does not cause log messages to be constructed unless logging is enabled.
|
||||
* Logs exceptions under the outer class name of the code calling this method.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void printException(Class _clazz, String message, Throwable ex) {
|
||||
printException(() -> message, ex);
|
||||
public static void printException(@NonNull LogMessage message, @Nullable Throwable ex) {
|
||||
printException(message, ex, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Instead call {@link #printException(LogMessage)},
|
||||
* which does not cause log messages to be constructed unless logging is enabled.
|
||||
* Logs exceptions under the outer class name of the code calling this method.
|
||||
* <p>
|
||||
* If the calling code is showing it's own error toast,
|
||||
* instead use {@link #printInfo(LogMessage, Exception)}
|
||||
*
|
||||
* @param message log message
|
||||
* @param ex exception (optional)
|
||||
* @param userToastMessage user specific toast message to show instead of the log message (optional)
|
||||
*/
|
||||
@Deprecated
|
||||
public static void printException(Class _clazz, String message) {
|
||||
printException(() -> message);
|
||||
public static void printException(@NonNull LogMessage message, @Nullable Throwable ex,
|
||||
@Nullable String userToastMessage) {
|
||||
String messageString = message.buildMessageString();
|
||||
String outerClassSimpleName = message.findOuterClassSimpleName();
|
||||
String logMessage = REVANCED_LOG_PREFIX + outerClassSimpleName;
|
||||
if (ex == null) {
|
||||
Log.e(logMessage, messageString);
|
||||
} else {
|
||||
Log.e(logMessage, messageString, ex);
|
||||
}
|
||||
if (SettingsEnum.DEBUG_SHOW_TOAST_ON_ERROR.getBoolean()) {
|
||||
String toastMessageToDisplay = (userToastMessage != null)
|
||||
? userToastMessage
|
||||
: outerClassSimpleName + ": " + messageString;
|
||||
ReVancedUtils.runOnMainThread(() -> {
|
||||
Context context = ReVancedUtils.getContext();
|
||||
if (context != null) {
|
||||
Toast.makeText(context, toastMessageToDisplay, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated. Instead call {@link #printInfo(LogMessage)},
|
||||
* which does not cause log messages to be constructed unless logging is enabled.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void info(Class _clazz, String message) {
|
||||
printInfo(() -> message);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import android.content.res.Resources;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.text.Bidi;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -38,7 +40,7 @@ public class ReVancedUtils {
|
||||
* All tasks run at max thread priority.
|
||||
*/
|
||||
private static final ThreadPoolExecutor backgroundThreadPool = new ThreadPoolExecutor(
|
||||
1, // minimum 1 thread always ready to be used
|
||||
2, // minimum 2 threads always ready to be used
|
||||
10, // For any threads over the minimum, keep them alive 10 seconds after they go idle
|
||||
SHARED_THREAD_POOL_MAXIMUM_BACKGROUND_THREADS,
|
||||
TimeUnit.SECONDS,
|
||||
@@ -58,10 +60,6 @@ public class ReVancedUtils {
|
||||
// or some ReVanced code is submitting an unexpected number of background tasks.
|
||||
LogHelper.printException(() -> "Reached maximum background thread count of "
|
||||
+ SHARED_THREAD_POOL_MAXIMUM_BACKGROUND_THREADS + " threads");
|
||||
|
||||
// Because this condition will manifest as a slow running app or a memory leak,
|
||||
// it might be best to show the user a toast or some other suggestion to restart the app.
|
||||
// TODO? if debug is enabled, show a toast?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +94,7 @@ public class ReVancedUtils {
|
||||
Resources res = context.getResources();
|
||||
return res.getIdentifier(name, type, context.getPackageName());
|
||||
} catch (Throwable exception) {
|
||||
LogHelper.printException(() -> ("Resource not found."), exception);
|
||||
LogHelper.printException(() -> "Resource not found.", exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +116,7 @@ public class ReVancedUtils {
|
||||
if (context != null) {
|
||||
return context;
|
||||
} else {
|
||||
LogHelper.printException(() -> ("Context is null, returning null!"));
|
||||
LogHelper.printException(() -> "Context is null, returning null!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -149,37 +147,44 @@ public class ReVancedUtils {
|
||||
* Automatically logs any exceptions the runnable throws
|
||||
*/
|
||||
public static void runOnMainThread(Runnable runnable) {
|
||||
Runnable exceptLoggingRunnable = () -> {
|
||||
runOnMainThreadDelayed(runnable, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically logs any exceptions the runnable throws
|
||||
*/
|
||||
public static void runOnMainThreadDelayed(Runnable runnable, long delayMillis) {
|
||||
Runnable loggingRunnable = () -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Exception ex) {
|
||||
LogHelper.printException(() -> "Exception on main thread from runnable: " + runnable.toString(), ex);
|
||||
LogHelper.printException(() -> runnable.getClass() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
};
|
||||
new Handler(Looper.getMainLooper()).post(exceptLoggingRunnable);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(loggingRunnable, delayMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the calling thread is on the main thread
|
||||
*/
|
||||
public static boolean currentIsOnMainThread() {
|
||||
public static boolean currentlyIsOnMainThread() {
|
||||
return Looper.getMainLooper().isCurrentThread();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if the calling thread is _not_ on the main thread
|
||||
* @throws IllegalStateException if the calling thread is _off_ the main thread
|
||||
*/
|
||||
public static void verifyOnMainThread() throws IllegalStateException {
|
||||
if (!currentIsOnMainThread()) {
|
||||
if (!currentlyIsOnMainThread()) {
|
||||
throw new IllegalStateException("Must call _on_ the main thread");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IllegalStateException if the calling thread _is_ on the main thread
|
||||
* @throws IllegalStateException if the calling thread is _on_ the main thread
|
||||
*/
|
||||
public static void verifyOffMainThread() throws IllegalStateException {
|
||||
if (currentIsOnMainThread()) {
|
||||
if (currentlyIsOnMainThread()) {
|
||||
throw new IllegalStateException("Must call _off_ the main thread");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DownloadButton extends BottomControlButton {
|
||||
|
||||
LogHelper.printDebug(() -> "Launched the intent with the content: " + content);
|
||||
} catch (Exception error) {
|
||||
LogHelper.printDebug(() -> "Failed to launch the intent: " + error);
|
||||
LogHelper.printException(() -> "Failed to launch the intent: " + error, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user