mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-12-25 04:05:50 +01:00
feat(youtube): show toasts along exceptions (#293)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
a70e80dfa0
commit
dbf1f3f0ce
@ -112,7 +112,7 @@ public final class GeneralAdsPatch extends Filter {
|
|||||||
else
|
else
|
||||||
result = BlockResult.UNBLOCKED;
|
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;
|
return result.filter;
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ public final class GeneralAdsPatch extends Filter {
|
|||||||
private static void hideView(SettingsEnum condition, View view) {
|
private static void hideView(SettingsEnum condition, View view) {
|
||||||
if (!condition.getBoolean()) return;
|
if (!condition.getBoolean()) return;
|
||||||
|
|
||||||
log("Hiding view with setting: " + condition);
|
LogHelper.printDebug(() -> "Hiding view with setting: " + condition);
|
||||||
|
|
||||||
AdRemoverAPI.HideViewWithLayout1dp(view);
|
AdRemoverAPI.HideViewWithLayout1dp(view);
|
||||||
}
|
}
|
||||||
@ -164,7 +164,4 @@ public final class GeneralAdsPatch extends Filter {
|
|||||||
hideView(SettingsEnum.ADREMOVER_SHORTS_REMOVAL, view);
|
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
|
//Used by app.revanced.patches.youtube.layout.createbutton.patch.CreateButtonRemoverPatch
|
||||||
public static void hideCreateButton(View view) {
|
public static void hideCreateButton(View view) {
|
||||||
boolean hidden = SettingsEnum.HIDE_CREATE_BUTTON.getBoolean();
|
boolean hidden = SettingsEnum.HIDE_CREATE_BUTTON.getBoolean();
|
||||||
String message = "Create button: " + (hidden ? "hidden" : "shown");
|
LogHelper.printDebug(() -> "Create button: " + (hidden ? "hidden" : "shown"));
|
||||||
LogHelper.printDebug(() -> message);
|
|
||||||
view.setVisibility(hidden ? View.GONE : View.VISIBLE);
|
view.setVisibility(hidden ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,9 @@ public class HideShortsButtonPatch {
|
|||||||
public static void hideShortsButton(View view) {
|
public static void hideShortsButton(View view) {
|
||||||
if (lastPivotTab != null && lastPivotTab.name() == "TAB_SHORTS") {
|
if (lastPivotTab != null && lastPivotTab.name() == "TAB_SHORTS") {
|
||||||
boolean hide = SettingsEnum.HIDE_SHORTS_BUTTON.getBoolean();
|
boolean hide = SettingsEnum.HIDE_SHORTS_BUTTON.getBoolean();
|
||||||
String message = hide ? "Shorts button: hidden" : "Shorts button: shown";
|
LogHelper.printDebug(() -> hide ? "Shorts button: hidden" : "Shorts button: shown");
|
||||||
LogHelper.printDebug(() -> message);
|
|
||||||
if (hide) {
|
if (hide) {
|
||||||
view.setVisibility(hide ? View.GONE : View.VISIBLE);
|
view.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class MicroGSupport {
|
|||||||
try {
|
try {
|
||||||
context.getPackageManager().getPackageInfo(MICROG_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
|
context.getPackageManager().getPackageInfo(MICROG_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
|
||||||
} catch (PackageManager.NameNotFoundException exception) {
|
} 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"));
|
startIntent(context, VANCED_MICROG_DOWNLOAD_LINK, str("microg_not_installed_warning"));
|
||||||
|
|
||||||
// Gracefully exit the app, so it does not crash.
|
// Gracefully exit the app, so it does not crash.
|
||||||
@ -44,7 +44,7 @@ public class MicroGSupport {
|
|||||||
|
|
||||||
try (var client = context.getContentResolver().acquireContentProviderClient(VANCED_MICROG_PROVIDER)) {
|
try (var client = context.getContentResolver().acquireContentProviderClient(VANCED_MICROG_PROVIDER)) {
|
||||||
if (client != null) return;
|
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"));
|
startIntent(context, DONT_KILL_MY_APP_LINK, str("microg_not_running_warning"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public final class VideoInformation {
|
|||||||
seekMethod = thisRef.getClass().getMethod(SEEK_METHOD_NAME, Long.TYPE);
|
seekMethod = thisRef.getClass().getMethod(SEEK_METHOD_NAME, Long.TYPE);
|
||||||
seekMethod.setAccessible(true);
|
seekMethod.setAccessible(true);
|
||||||
} catch (NoSuchMethodException ex) {
|
} 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);
|
LogHelper.printDebug(() -> "Seeking to " + millisecond);
|
||||||
seekMethod.invoke(playerController.get(), millisecond);
|
seekMethod.invoke(playerController.get(), millisecond);
|
||||||
} catch (Exception ex) {
|
} 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;
|
package app.revanced.integrations.patches.playback.quality;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
@ -26,24 +27,25 @@ public class RememberVideoQualityPatch {
|
|||||||
if (isConnectedWifi(context)) {
|
if (isConnectedWifi(context)) {
|
||||||
try {
|
try {
|
||||||
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "wifi_quality", defaultQuality + "");
|
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) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> ("Failed to change default WI-FI quality:" + 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.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)) {
|
} else if (isConnectedMobile(context)) {
|
||||||
try {
|
try {
|
||||||
SharedPrefHelper.saveString(SharedPrefHelper.SharedPrefNames.REVANCED_PREFS, "mobile_quality", defaultQuality + "");
|
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) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printDebug(() -> "Failed to change default mobile data quality" + ex);
|
LogHelper.printException(() -> "Failed to change default mobile data quality", ex);
|
||||||
Toast.makeText(context, "Failed to change default mobile data quality", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
LogHelper.printDebug(() -> "Changing default mobile data quality to:" + defaultQuality);
|
|
||||||
Toast.makeText(context, "Changing default mobile data quality to:" + defaultQuality, Toast.LENGTH_SHORT).show();
|
|
||||||
} else {
|
} else {
|
||||||
LogHelper.printDebug(() -> "No internet connection.");
|
String message = "No internet connection.";
|
||||||
Toast.makeText(context, "No internet connection.", Toast.LENGTH_SHORT).show();
|
LogHelper.printDebug(() -> message);
|
||||||
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
userChangedQuality = false;
|
userChangedQuality = false;
|
||||||
}
|
}
|
||||||
@ -88,7 +90,7 @@ public class RememberVideoQualityPatch {
|
|||||||
LogHelper.printDebug(() -> "Quality: " + qualityToLog);
|
LogHelper.printDebug(() -> "Quality: " + qualityToLog);
|
||||||
Context context = ReVancedUtils.getContext();
|
Context context = ReVancedUtils.getContext();
|
||||||
if (context == null) {
|
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;
|
return quality;
|
||||||
}
|
}
|
||||||
if (isConnectedWifi(context)) {
|
if (isConnectedWifi(context)) {
|
||||||
@ -129,8 +131,7 @@ public class RememberVideoQualityPatch {
|
|||||||
LogHelper.printDebug(() -> "Quality changed to: " + qualityIndex);
|
LogHelper.printDebug(() -> "Quality changed to: " + qualityIndex);
|
||||||
return qualityIndex;
|
return qualityIndex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> ("Failed to set quality"), ex);
|
LogHelper.printException(() -> "Failed to set quality", ex);
|
||||||
Toast.makeText(context, "Failed to set quality", Toast.LENGTH_SHORT).show();
|
|
||||||
return qualityIndex;
|
return qualityIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +148,7 @@ public class RememberVideoQualityPatch {
|
|||||||
newVideo = true;
|
newVideo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
private static NetworkInfo getNetworkInfo(Context context) {
|
private static NetworkInfo getNetworkInfo(Context context) {
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
return cm.getActiveNetworkInfo();
|
return cm.getActiveNetworkInfo();
|
||||||
|
@ -95,7 +95,16 @@ public class ReturnYouTubeDislike {
|
|||||||
private static NumberFormat dislikePercentageFormatter;
|
private static NumberFormat dislikePercentageFormatter;
|
||||||
|
|
||||||
public static void onEnabledChange(boolean enabled) {
|
public static void onEnabledChange(boolean enabled) {
|
||||||
|
synchronized (videoIdLockObject) {
|
||||||
isEnabled = enabled;
|
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() {
|
private static String getCurrentVideoId() {
|
||||||
@ -160,6 +169,10 @@ public class ReturnYouTubeDislike {
|
|||||||
long fetchStartTime = 0;
|
long fetchStartTime = 0;
|
||||||
try {
|
try {
|
||||||
Future<RYDVoteData> fetchFuture = getVoteFetchFuture();
|
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()) {
|
if (SettingsEnum.DEBUG.getBoolean() && !fetchFuture.isDone()) {
|
||||||
fetchStartTime = System.currentTimeMillis();
|
fetchStartTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
@ -201,6 +214,12 @@ public class ReturnYouTubeDislike {
|
|||||||
|
|
||||||
// Must make a local copy of videoId, since it may change between now and when the vote thread runs
|
// Must make a local copy of videoId, since it may change between now and when the vote thread runs
|
||||||
String videoIdToVoteFor = getCurrentVideoId();
|
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(() -> {
|
voteSerialExecutor.execute(() -> {
|
||||||
// must wrap in try/catch to properly log exceptions
|
// must wrap in try/catch to properly log exceptions
|
||||||
@ -286,9 +305,6 @@ public class ReturnYouTubeDislike {
|
|||||||
//
|
//
|
||||||
// Change the "Likes" string to show that likes and dislikes are hidden
|
// 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");
|
String hiddenMessageString = str("revanced_ryd_video_likes_hidden_by_video_owner");
|
||||||
if (hiddenMessageString.equals(oldLikesString)) {
|
if (hiddenMessageString.equals(oldLikesString)) {
|
||||||
return false;
|
return false;
|
||||||
@ -457,7 +473,6 @@ public class ReturnYouTubeDislike {
|
|||||||
|
|
||||||
private static String formatDislikeCount(long dislikeCount) {
|
private static String formatDislikeCount(long dislikeCount) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
String formatted;
|
|
||||||
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
||||||
if (dislikeCountFormatter == null) {
|
if (dislikeCountFormatter == null) {
|
||||||
// Note: Java number formatters will use the locale specific number characters.
|
// Note: Java number formatters will use the locale specific number characters.
|
||||||
@ -468,18 +483,15 @@ public class ReturnYouTubeDislike {
|
|||||||
LogHelper.printDebug(() -> "Locale: " + locale);
|
LogHelper.printDebug(() -> "Locale: " + locale);
|
||||||
dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT);
|
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);
|
return String.valueOf(dislikeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatDislikePercentage(float dislikePercentage) {
|
private static String formatDislikePercentage(float dislikePercentage) {
|
||||||
String formatted;
|
|
||||||
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
|
||||||
if (dislikePercentageFormatter == null) {
|
if (dislikePercentageFormatter == null) {
|
||||||
Locale locale = ReVancedUtils.getContext().getResources().getConfiguration().locale;
|
Locale locale = ReVancedUtils.getContext().getResources().getConfiguration().locale;
|
||||||
@ -491,10 +503,8 @@ public class ReturnYouTubeDislike {
|
|||||||
} else {
|
} else {
|
||||||
dislikePercentageFormatter.setMaximumFractionDigits(1); // show up to 1 digit precision
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -508,6 +518,7 @@ public class ReturnYouTubeDislike {
|
|||||||
*/
|
*/
|
||||||
private static volatile long totalTimeUIWaitedOnNetworkCalls;
|
private static volatile long totalTimeUIWaitedOnNetworkCalls;
|
||||||
|
|
||||||
|
@SuppressWarnings("NonAtomicOperationOnVolatileField")
|
||||||
private static void recordTimeUISpentWaitingForNetworkCall(long timeUIWaitStarted) {
|
private static void recordTimeUISpentWaitingForNetworkCall(long timeUIWaitStarted) {
|
||||||
if (timeUIWaitStarted == 0 || !SettingsEnum.DEBUG.getBoolean()) {
|
if (timeUIWaitStarted == 0 || !SettingsEnum.DEBUG.getBoolean()) {
|
||||||
return;
|
return;
|
||||||
|
@ -185,11 +185,15 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
lastTimeRateLimitWasHit = System.currentTimeMillis();
|
lastTimeRateLimitWasHit = System.currentTimeMillis();
|
||||||
LogHelper.printDebug(() -> "API rate limit was hit. Stopping API calls for the next "
|
LogHelper.printDebug(() -> "API rate limit was hit. Stopping API calls for the next "
|
||||||
+ RATE_LIMIT_BACKOFF_SECONDS + " seconds");
|
+ 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 true;
|
||||||
}
|
}
|
||||||
return false;
|
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) {
|
private static void updateStatistics(long timeNetworkCallStarted, long timeNetworkCallEnded, boolean connectionError, boolean rateLimitHit) {
|
||||||
if (connectionError && rateLimitHit) {
|
if (connectionError && rateLimitHit) {
|
||||||
throw new IllegalArgumentException("both connection error and rate limit parameter were true");
|
throw new IllegalArgumentException("both connection error and rate limit parameter were true");
|
||||||
@ -202,11 +206,9 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
if (connectionError) {
|
if (connectionError) {
|
||||||
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
||||||
fetchCallNumberOfFailures++;
|
fetchCallNumberOfFailures++;
|
||||||
showToast("revanced_ryd_failure_connection_timeout");
|
|
||||||
} else if (rateLimitHit) {
|
} else if (rateLimitHit) {
|
||||||
fetchCallResponseTimeLast = FETCH_CALL_RESPONSE_TIME_VALUE_RATE_LIMIT;
|
fetchCallResponseTimeLast = FETCH_CALL_RESPONSE_TIME_VALUE_RATE_LIMIT;
|
||||||
numberOfRateLimitRequestsEncountered++;
|
numberOfRateLimitRequestsEncountered++;
|
||||||
showToast("revanced_ryd_failure_client_rate_limit_requested");
|
|
||||||
} else {
|
} else {
|
||||||
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
fetchCallResponseTimeLast = responseTimeOfFetchCall;
|
||||||
}
|
}
|
||||||
@ -226,6 +228,7 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
LogHelper.printDebug(() -> "Fetching votes for: " + videoId);
|
LogHelper.printDebug(() -> "Fetching votes for: " + videoId);
|
||||||
final long timeNetworkCallStarted = System.currentTimeMillis();
|
final long timeNetworkCallStarted = System.currentTimeMillis();
|
||||||
|
|
||||||
|
String connectionErrorMessageStringKey = "revanced_ryd_failure_connection_timeout";
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = getRYDConnectionFromRoute(ReturnYouTubeDislikeRoutes.GET_DISLIKES, videoId);
|
HttpURLConnection connection = getRYDConnectionFromRoute(ReturnYouTubeDislikeRoutes.GET_DISLIKES, videoId);
|
||||||
// request headers, as per https://returnyoutubedislike.com/docs/fetching
|
// request headers, as per https://returnyoutubedislike.com/docs/fetching
|
||||||
@ -261,12 +264,12 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
// fall thru to update statistics
|
// fall thru to update statistics
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogHelper.printDebug(() -> "Failed to fetch votes for video: " + videoId
|
LogHelper.printException(() -> "Failed to fetch votes for video: " + videoId
|
||||||
+ " response code was: " + responseCode);
|
+ " response code was: " + responseCode, null, str(connectionErrorMessageStringKey));
|
||||||
connection.disconnect(); // something went wrong, might as well disconnect
|
connection.disconnect(); // something went wrong, might as well disconnect
|
||||||
}
|
}
|
||||||
} catch (Exception ex) { // connection timed out, response timeout, or some other network error
|
} 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);
|
updateStatistics(timeNetworkCallStarted, System.currentTimeMillis(), true, false);
|
||||||
@ -304,13 +307,12 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
String solution = solvePuzzle(challenge, difficulty);
|
String solution = solvePuzzle(challenge, difficulty);
|
||||||
return confirmRegistration(userId, solution);
|
return confirmRegistration(userId, solution);
|
||||||
}
|
}
|
||||||
LogHelper.printDebug(() -> "Failed to register new user: " + userId
|
LogHelper.printException(() -> "Failed to register new user: " + userId
|
||||||
+ " response code was: " + responseCode);
|
+ " response code was: " + responseCode);
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> "Failed to register user", ex);
|
LogHelper.printException(() -> "Failed to register user", ex);
|
||||||
}
|
}
|
||||||
showToast("revanced_ryd_failure_register_user");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,10 +346,10 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
LogHelper.printDebug(() -> "Registration confirmation successful for user: " + userId);
|
LogHelper.printDebug(() -> "Registration confirmation successful for user: " + userId);
|
||||||
return 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);
|
+ " solution: " + solution + " response string was: " + result);
|
||||||
} else {
|
} 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);
|
+ " solution: " + solution + " response code was: " + responseCode);
|
||||||
}
|
}
|
||||||
connection.disconnect(); // something went wrong, might as well disconnect
|
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
|
LogHelper.printException(() -> "Failed to confirm registration for user: " + userId
|
||||||
+ "solution: " + solution, ex);
|
+ "solution: " + solution, ex);
|
||||||
}
|
}
|
||||||
showToast("revanced_ryd_failure_confirm_user");
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,14 +395,13 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
String solution = solvePuzzle(challenge, difficulty);
|
String solution = solvePuzzle(challenge, difficulty);
|
||||||
return confirmVote(videoId, userId, solution);
|
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);
|
+ " userId: " + userId + " vote: " + vote + " response code was: " + responseCode);
|
||||||
connection.disconnect(); // something went wrong, might as well disconnect
|
connection.disconnect(); // something went wrong, might as well disconnect
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> "Failed to send vote for video: " + videoId
|
LogHelper.printException(() -> "Failed to send vote for video: " + videoId
|
||||||
+ " user: " + userId + " vote: " + vote, ex);
|
+ " user: " + userId + " vote: " + vote, ex);
|
||||||
}
|
}
|
||||||
showToast("revanced_ryd_failure_send_vote_failed");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,10 +437,10 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
LogHelper.printDebug(() -> "Vote confirm successful for video: " + videoId);
|
LogHelper.printDebug(() -> "Vote confirm successful for video: " + videoId);
|
||||||
return true;
|
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);
|
+ " user: " + userId + " solution: " + solution + " response string was: " + result);
|
||||||
} else {
|
} 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);
|
+ " user: " + userId + " solution: " + solution + " response code was: " + responseCode);
|
||||||
}
|
}
|
||||||
connection.disconnect(); // something went wrong, might as well disconnect
|
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
|
LogHelper.printException(() -> "Failed to confirm vote for video: " + videoId
|
||||||
+ " user: " + userId + " solution: " + solution, ex);
|
+ " user: " + userId + " solution: " + solution, ex);
|
||||||
}
|
}
|
||||||
showToast("revanced_ryd_failure_confirm_vote_failed");
|
|
||||||
return false;
|
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 {
|
private static void applyCommonPostRequestSettings(HttpURLConnection connection) throws ProtocolException {
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
@ -477,7 +469,7 @@ public class ReturnYouTubeDislikeApi {
|
|||||||
byte[] decodedChallenge = Base64.decode(challenge, Base64.NO_WRAP);
|
byte[] decodedChallenge = Base64.decode(challenge, Base64.NO_WRAP);
|
||||||
|
|
||||||
byte[] buffer = new byte[20];
|
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];
|
buffer[i] = decodedChallenge[i - 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +115,10 @@ public enum SettingsEnum {
|
|||||||
PLAYBACK_MAX_BUFFER("revanced_pref_buffer_for_playback_ms", 2500, ReturnType.INTEGER),
|
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),
|
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("revanced_debug_enabled", false, ReturnType.BOOLEAN),
|
||||||
DEBUG_STACKTRACE("revanced_debug_stacktrace_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),
|
USE_DARK_THEME("app_theme_dark", false, ReturnType.BOOLEAN),
|
||||||
|
|
||||||
@ -303,7 +304,7 @@ public enum SettingsEnum {
|
|||||||
defaultValue = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
|
defaultValue = SharedPrefHelper.getString(setting.sharedPref, path, (String) defaultValue);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
setting.setValue(defaultValue);
|
setting.setValue(defaultValue);
|
||||||
@ -336,7 +337,7 @@ public enum SettingsEnum {
|
|||||||
Context context = ReVancedUtils.getContext();
|
Context context = ReVancedUtils.getContext();
|
||||||
|
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
LogHelper.printException(() -> ("Context on SaveValue is null!"));
|
LogHelper.printException(() -> "Context on SaveValue is null!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +358,7 @@ public enum SettingsEnum {
|
|||||||
SharedPrefHelper.saveString(sharedPref, path, (String) newValue);
|
SharedPrefHelper.saveString(sharedPref, path, (String) newValue);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.android.libraries.social.licenses.LicenseActivity;
|
import com.google.android.libraries.social.licenses.LicenseActivity;
|
||||||
|
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
@ -44,15 +46,23 @@ public class ReVancedSettingActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
} 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();
|
base.getFragmentManager().beginTransaction().replace(getIdentifier("revanced_settings_fragments", "id"), preferenceFragment).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static <T extends View> T getView(Class<T> typeClass, ViewGroup viewGroup) {
|
public static <T extends View> T getView(Class<T> typeClass, ViewGroup viewGroup) {
|
||||||
if (viewGroup == null) {
|
if (viewGroup == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -67,10 +77,12 @@ public class ReVancedSettingActivity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static ImageButton getImageButton(ViewGroup viewGroup) {
|
public static ImageButton getImageButton(ViewGroup viewGroup) {
|
||||||
return getView(ImageButton.class, viewGroup);
|
return getView(ImageButton.class, viewGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static TextView getTextView(ViewGroup viewGroup) {
|
public static TextView getTextView(ViewGroup viewGroup) {
|
||||||
return getView(TextView.class, viewGroup);
|
return getView(TextView.class, viewGroup);
|
||||||
}
|
}
|
||||||
|
@ -66,12 +66,12 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
value = Integer.parseInt(editPref.getText());
|
value = Integer.parseInt(editPref.getText());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogHelper.printException(() -> ("Setting has no valid return type! " + setting.getReturnType()));
|
LogHelper.printException(() -> "Setting has no valid return type! " + setting.getReturnType());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setting.setValue(value);
|
setting.setValue(value);
|
||||||
} else {
|
} 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()) {
|
if (ReVancedUtils.getContext() != null && settingsInitialized && setting.shouldRebootOnChange()) {
|
||||||
@ -96,7 +96,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
|
|
||||||
this.settingsInitialized = true;
|
this.settingsInitialized = true;
|
||||||
} catch (Throwable th) {
|
} 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) {
|
private Preference findPreferenceOnScreen(CharSequence key) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
LogHelper.printException(() -> ("Key cannot be null!"));
|
LogHelper.printException(() -> "Key cannot be null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Preference pref = null;
|
Preference pref = null;
|
||||||
@ -144,7 +144,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
private String getPackageName() {
|
private String getPackageName() {
|
||||||
Context context = ReVancedUtils.getContext();
|
Context context = ReVancedUtils.getContext();
|
||||||
if (context == null) {
|
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";
|
return "com.google.android.youtube";
|
||||||
}
|
}
|
||||||
String PACKAGE_NAME = context.getPackageName();
|
String PACKAGE_NAME = context.getPackageName();
|
||||||
@ -169,7 +169,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
|
|||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
return res.getString(res.getIdentifier(name, "string", context.getPackageName()));
|
return res.getString(res.getIdentifier(name, "string", context.getPackageName()));
|
||||||
} catch (Throwable exception) {
|
} catch (Throwable exception) {
|
||||||
LogHelper.printException(() -> ("Resource not found."), exception);
|
LogHelper.printException(() -> "Resource not found.", exception);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,11 @@
|
|||||||
package app.revanced.integrations.sponsorblock;
|
package app.revanced.integrations.sponsorblock;
|
||||||
|
|
||||||
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.timeWithoutSegments;
|
|
||||||
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.videoHasSegments;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
import app.revanced.integrations.patches.VideoInformation;
|
import app.revanced.integrations.patches.VideoInformation;
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
import app.revanced.integrations.shared.PlayerType;
|
import app.revanced.integrations.shared.PlayerType;
|
||||||
@ -26,6 +14,15 @@ import app.revanced.integrations.sponsorblock.requests.SBRequester;
|
|||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
import app.revanced.integrations.utils.ReVancedUtils;
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.timeWithoutSegments;
|
||||||
|
import static app.revanced.integrations.sponsorblock.SponsorBlockUtils.videoHasSegments;
|
||||||
|
|
||||||
public class PlayerController {
|
public class PlayerController {
|
||||||
|
|
||||||
private static final Timer sponsorTimer = new Timer("sponsor-skip-timer");
|
private static final Timer sponsorTimer = new Timer("sponsor-skip-timer");
|
||||||
@ -47,6 +44,7 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setCurrentVideoId(final String videoId) {
|
public static void setCurrentVideoId(final String videoId) {
|
||||||
|
try {
|
||||||
if (videoId == null) {
|
if (videoId == null) {
|
||||||
currentVideoId = null;
|
currentVideoId = null;
|
||||||
sponsorSegmentsOfCurrentVideo = null;
|
sponsorSegmentsOfCurrentVideo = null;
|
||||||
@ -76,21 +74,33 @@ public class PlayerController {
|
|||||||
sponsorTimer.schedule(new TimerTask() {
|
sponsorTimer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
executeDownloadSegments(currentVideoId);
|
executeDownloadSegments(currentVideoId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.printException(() -> "Failed to download segments", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "setCurrentVideoId failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play
|
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play
|
||||||
*/
|
*/
|
||||||
public static void initialize(Object _o) {
|
public static void initialize(Object _o) {
|
||||||
|
try {
|
||||||
lastKnownVideoTime = 0;
|
lastKnownVideoTime = 0;
|
||||||
SkipSegmentView.hide();
|
SkipSegmentView.hide();
|
||||||
NewSegmentHelperLayout.hide();
|
NewSegmentHelperLayout.hide();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "initialize failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeDownloadSegments(String videoId) {
|
public static void executeDownloadSegments(String videoId) {
|
||||||
|
try {
|
||||||
videoHasSegments = false;
|
videoHasSegments = false;
|
||||||
timeWithoutSegments = "";
|
timeWithoutSegments = "";
|
||||||
|
|
||||||
@ -103,12 +113,17 @@ public class PlayerController {
|
|||||||
|
|
||||||
sponsorSegmentsOfCurrentVideo = segments;
|
sponsorSegmentsOfCurrentVideo = segments;
|
||||||
// new Handler(Looper.getMainLooper()).post(findAndSkipSegmentRunnable);
|
// new Handler(Looper.getMainLooper()).post(findAndSkipSegmentRunnable);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "executeDownloadSegments failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setVideoTime(long millis) {
|
public static void setVideoTime(long millis) {
|
||||||
LogHelper.printDebug(() -> "setCurrentVideoTime: current video time: " + millis);
|
try {
|
||||||
if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
|
if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
|
||||||
|
LogHelper.printDebug(() -> "setCurrentVideoTime: current video time: " + millis);
|
||||||
|
// fixme? if (millis == lastKnownVideoTime), should it return here and not continue?
|
||||||
lastKnownVideoTime = millis;
|
lastKnownVideoTime = millis;
|
||||||
if (millis <= 0) return;
|
if (millis <= 0) return;
|
||||||
//findAndSkipSegment(false);
|
//findAndSkipSegment(false);
|
||||||
@ -139,7 +154,7 @@ public class PlayerController {
|
|||||||
public void run() {
|
public void run() {
|
||||||
skipSponsorTask = null;
|
skipSponsorTask = null;
|
||||||
lastKnownVideoTime = segment.start + 1;
|
lastKnownVideoTime = segment.start + 1;
|
||||||
new Handler(Looper.getMainLooper()).post(findAndSkipSegmentRunnable);
|
ReVancedUtils.runOnMainThread(findAndSkipSegmentRunnable);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sponsorTimer.schedule(skipSponsorTask, segment.start - millis);
|
sponsorTimer.schedule(skipSponsorTask, segment.start - millis);
|
||||||
@ -164,6 +179,9 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SkipSegmentView.hide();
|
SkipSegmentView.hide();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogHelper.printException(() -> "setVideoTime failure", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendViewRequestAsync(final long millis, final SponsorSegment segment) {
|
private static void sendViewRequestAsync(final long millis, final SponsorSegment segment) {
|
||||||
@ -175,7 +193,7 @@ public class PlayerController {
|
|||||||
SettingsEnum.SB_SKIPPED_SEGMENTS_TIME.saveValue(newSkippedTime);
|
SettingsEnum.SB_SKIPPED_SEGMENTS_TIME.saveValue(newSkippedTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new Thread(() -> {
|
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
||||||
if (SettingsEnum.SB_COUNT_SKIPS.getBoolean() &&
|
if (SettingsEnum.SB_COUNT_SKIPS.getBoolean() &&
|
||||||
segment.category != SponsorBlockSettings.SegmentInfo.UNSUBMITTED &&
|
segment.category != SponsorBlockSettings.SegmentInfo.UNSUBMITTED &&
|
||||||
millis - segment.start < 2000) {
|
millis - segment.start < 2000) {
|
||||||
@ -186,6 +204,7 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setHighPrecisionVideoTime(final long millis) {
|
public static void setHighPrecisionVideoTime(final long millis) {
|
||||||
|
try {
|
||||||
if ((millis < lastKnownVideoTime && lastKnownVideoTime >= VideoInformation.getCurrentVideoLength()) || millis == 0) {
|
if ((millis < lastKnownVideoTime && lastKnownVideoTime >= VideoInformation.getCurrentVideoLength()) || millis == 0) {
|
||||||
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
|
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
|
||||||
SponsorBlockUtils.showVoteButton();
|
SponsorBlockUtils.showVoteButton();
|
||||||
@ -194,6 +213,9 @@ public class PlayerController {
|
|||||||
lastKnownVideoTime = millis;
|
lastKnownVideoTime = millis;
|
||||||
} else
|
} else
|
||||||
setVideoTime(millis);
|
setVideoTime(millis);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "setHighPrecisionVideoTime failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getCurrentVideoLength() {
|
public static long getCurrentVideoLength() {
|
||||||
@ -223,8 +245,8 @@ public class PlayerController {
|
|||||||
setSponsorBarAbsoluteLeft(rect.left);
|
setSponsorBarAbsoluteLeft(rect.left);
|
||||||
setSponsorBarAbsoluteRight(rect.right);
|
setSponsorBarAbsoluteRight(rect.right);
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
} catch (Exception ex) {
|
||||||
e.printStackTrace();
|
LogHelper.printException(() -> "setSponsorBarRect failure", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +261,11 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setSponsorBarThickness(final int thickness) {
|
public static void setSponsorBarThickness(final int thickness) {
|
||||||
|
try {
|
||||||
setSponsorBarThickness((float) thickness);
|
setSponsorBarThickness((float) thickness);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "setSponsorBarThickness failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSponsorBarThickness(final float thickness) {
|
public static void setSponsorBarThickness(final float thickness) {
|
||||||
@ -256,24 +282,33 @@ public class PlayerController {
|
|||||||
|
|
||||||
|
|
||||||
public static void addSkipSponsorView15(final View view) {
|
public static void addSkipSponsorView15(final View view) {
|
||||||
|
try {
|
||||||
playerActivity = new WeakReference<>((Activity) view.getContext());
|
playerActivity = new WeakReference<>((Activity) view.getContext());
|
||||||
LogHelper.printDebug(() -> "addSkipSponsorView15: view=" + view.toString());
|
LogHelper.printDebug(() -> "addSkipSponsorView15: view=" + view.toString());
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
ReVancedUtils.runOnMainThreadDelayed(() -> {
|
||||||
final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) view).getChildAt(2);
|
final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) view).getChildAt(2);
|
||||||
Activity context = ((Activity) viewGroup.getContext());
|
Activity context = ((Activity) viewGroup.getContext());
|
||||||
NewSegmentHelperLayout.context = context;
|
NewSegmentHelperLayout.context = context;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "addSkipSponsorView15 failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Edit: Is this method ever called? Where is the patch code that calls this?
|
||||||
public static void addSkipSponsorView14(final View view) {
|
public static void addSkipSponsorView14(final View view) {
|
||||||
|
try {
|
||||||
playerActivity = new WeakReference<>((Activity) view.getContext());
|
playerActivity = new WeakReference<>((Activity) view.getContext());
|
||||||
LogHelper.printDebug(() -> "addSkipSponsorView14: view=" + view.toString());
|
LogHelper.printDebug(() -> "addSkipSponsorView14: view=" + view.toString());
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
ReVancedUtils.runOnMainThreadDelayed(() -> {
|
||||||
final ViewGroup viewGroup = (ViewGroup) view.getParent();
|
final ViewGroup viewGroup = (ViewGroup) view.getParent();
|
||||||
Activity activity = (Activity) viewGroup.getContext();
|
Activity activity = (Activity) viewGroup.getContext();
|
||||||
NewSegmentHelperLayout.context = activity;
|
NewSegmentHelperLayout.context = activity;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "addSkipSponsorView14 failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -281,6 +316,7 @@ public class PlayerController {
|
|||||||
* Called when it's time to draw time bar
|
* Called when it's time to draw time bar
|
||||||
*/
|
*/
|
||||||
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
|
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
|
||||||
|
try {
|
||||||
if (sponsorBarThickness < 0.1) return;
|
if (sponsorBarThickness < 0.1) return;
|
||||||
if (sponsorSegmentsOfCurrentVideo == null) return;
|
if (sponsorSegmentsOfCurrentVideo == null) return;
|
||||||
|
|
||||||
@ -297,6 +333,9 @@ public class PlayerController {
|
|||||||
float right = segment.end * tmp1 + absoluteLeft;
|
float right = segment.end * tmp1 + absoluteLeft;
|
||||||
canvas.drawRect(left, top, right, bottom, segment.category.paint);
|
canvas.drawRect(left, top, right, bottom, segment.category.paint);
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "drawSponsorTimeBars failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private final static Pattern videoIdRegex = Pattern.compile(".*\\.be\\/([A-Za-z0-9_\\-]{0,50}).*");
|
// private final static Pattern videoIdRegex = Pattern.compile(".*\\.be\\/([A-Za-z0-9_\\-]{0,50}).*");
|
||||||
@ -327,7 +366,7 @@ public class PlayerController {
|
|||||||
lastKnownVideoTime = finalMillisecond;
|
lastKnownVideoTime = finalMillisecond;
|
||||||
VideoInformation.seekTo(finalMillisecond);
|
VideoInformation.seekTo(finalMillisecond);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.printException(() -> ("Cannot skip to millisecond"), e);
|
LogHelper.printException(() -> "Cannot skip to millisecond", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -335,6 +374,7 @@ public class PlayerController {
|
|||||||
|
|
||||||
|
|
||||||
private static void findAndSkipSegment(boolean wasClicked) {
|
private static void findAndSkipSegment(boolean wasClicked) {
|
||||||
|
try {
|
||||||
if (sponsorSegmentsOfCurrentVideo == null)
|
if (sponsorSegmentsOfCurrentVideo == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -357,9 +397,13 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkipSegmentView.hide();
|
SkipSegmentView.hide();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "findAndSkipSegment failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void skipSegment(SponsorSegment segment, boolean wasClicked) {
|
private static void skipSegment(SponsorSegment segment, boolean wasClicked) {
|
||||||
|
try {
|
||||||
// if (lastSkippedSegment == segment) return;
|
// if (lastSkippedSegment == segment) return;
|
||||||
// lastSkippedSegment = segment;
|
// lastSkippedSegment = segment;
|
||||||
LogHelper.printDebug(() -> "Skipping segment: " + segment.toString());
|
LogHelper.printDebug(() -> "Skipping segment: " + segment.toString());
|
||||||
@ -381,5 +425,8 @@ public class PlayerController {
|
|||||||
}
|
}
|
||||||
sponsorSegmentsOfCurrentVideo = newSegments;
|
sponsorSegmentsOfCurrentVideo = newSegments;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "skipSegment failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ public class ShieldButton {
|
|||||||
isShowing = true;
|
isShowing = true;
|
||||||
changeVisibilityImmediate(false);
|
changeVisibilityImmediate(false);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> ("Unable to set RelativeLayout"), ex);
|
LogHelper.printException(() -> "Unable to set RelativeLayout", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ public class ShieldButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void changeVisibility(boolean visible, boolean immediate) {
|
public static void changeVisibility(boolean visible, boolean immediate) {
|
||||||
|
try {
|
||||||
if (isShowing == visible) return;
|
if (isShowing == visible) return;
|
||||||
isShowing = visible;
|
isShowing = visible;
|
||||||
|
|
||||||
@ -93,6 +94,9 @@ public class ShieldButton {
|
|||||||
iView.startAnimation(fadeOut);
|
iView.startAnimation(fadeOut);
|
||||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "changeVisibility failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean shouldBeShown() {
|
static boolean shouldBeShown() {
|
||||||
|
@ -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.hideSkipButton;
|
||||||
import static app.revanced.integrations.sponsorblock.player.ui.SponsorBlockView.showSkipButton;
|
import static app.revanced.integrations.sponsorblock.player.ui.SponsorBlockView.showSkipButton;
|
||||||
|
|
||||||
@SuppressLint({"RtlHardcoded", "SetTextI18n", "LongLogTag", "AppCompatCustomView"})
|
@SuppressLint({"RtlHardcoded", "SetTextI18n", "AppCompatCustomView"})
|
||||||
public class SkipSegmentView {
|
public class SkipSegmentView {
|
||||||
|
|
||||||
private static SponsorSegment lastNotifiedSegment;
|
private static SponsorSegment lastNotifiedSegment;
|
||||||
|
@ -51,7 +51,6 @@ import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
|||||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||||
import app.revanced.integrations.sponsorblock.requests.SBRequester;
|
import app.revanced.integrations.sponsorblock.requests.SBRequester;
|
||||||
|
|
||||||
@SuppressWarnings({"LongLogTag"})
|
|
||||||
public abstract class SponsorBlockUtils {
|
public abstract class SponsorBlockUtils {
|
||||||
public static final String DATE_FORMAT = "HH:mm:ss.SSS";
|
public static final String DATE_FORMAT = "HH:mm:ss.SSS";
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
@ -154,7 +153,7 @@ public abstract class SponsorBlockUtils {
|
|||||||
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
appContext = new WeakReference<>(context);
|
appContext = new WeakReference<>(context);
|
||||||
new Thread(submitRunnable).start();
|
new Thread(submitRunnable).start(); // fixme: use ReVancedUtils#runOnBackgroundThread
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static String messageToToast = "";
|
public static String messageToToast = "";
|
||||||
@ -233,13 +232,13 @@ public abstract class SponsorBlockUtils {
|
|||||||
final SponsorBlockSettings.SegmentInfo segmentType = SponsorBlockUtils.newSponsorBlockSegmentType;
|
final SponsorBlockSettings.SegmentInfo segmentType = SponsorBlockUtils.newSponsorBlockSegmentType;
|
||||||
try {
|
try {
|
||||||
if (start < 0 || end < 0 || start >= end || segmentType == null || videoId == null || uuid == null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
SBRequester.submitSegments(videoId, uuid, ((float) start) / 1000f, ((float) end) / 1000f, segmentType.key, toastRunnable);
|
SBRequester.submitSegments(videoId, uuid, ((float) start) / 1000f, ((float) end) / 1000f, segmentType.key, toastRunnable);
|
||||||
newSponsorSegmentEndMillis = newSponsorSegmentStartMillis = -1;
|
newSponsorSegmentEndMillis = newSponsorSegmentStartMillis = -1;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogHelper.printException(() -> ("Unable to submit segment"), e);
|
LogHelper.printException(() -> "Unable to submit segment", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoId != null)
|
if (videoId != null)
|
||||||
@ -403,12 +402,16 @@ public abstract class SponsorBlockUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String appendTimeWithoutSegments(String totalTime) {
|
public static String appendTimeWithoutSegments(String totalTime) {
|
||||||
|
try {
|
||||||
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
|
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
|
||||||
if (timeWithoutSegments.isEmpty()) {
|
if (timeWithoutSegments.isEmpty()) {
|
||||||
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);
|
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);
|
||||||
}
|
}
|
||||||
return totalTime + timeWithoutSegments;
|
return totalTime + timeWithoutSegments;
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "appendTimeWithoutSegments failure", ex);
|
||||||
|
}
|
||||||
|
|
||||||
return totalTime;
|
return totalTime;
|
||||||
}
|
}
|
||||||
@ -436,7 +439,7 @@ public abstract class SponsorBlockUtils {
|
|||||||
PlayerController.setCurrentVideoId(null);
|
PlayerController.setCurrentVideoId(null);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> ("Player type changed caused a crash."), ex);
|
LogHelper.printException(() -> "Player type changed caused a crash.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,8 +561,8 @@ public abstract class SponsorBlockUtils {
|
|||||||
|
|
||||||
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
||||||
} catch (Exception ex) {
|
} 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();
|
Toast.makeText(context, str("settings_import_failed"), Toast.LENGTH_SHORT).show();
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,8 +601,8 @@ public abstract class SponsorBlockUtils {
|
|||||||
|
|
||||||
return json.toString();
|
return json.toString();
|
||||||
} catch (Exception ex) {
|
} 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();
|
Toast.makeText(context, str("settings_export_failed"), Toast.LENGTH_SHORT).show();
|
||||||
ex.printStackTrace();
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,11 +103,11 @@ public class StringRef {
|
|||||||
if (resources != null) {
|
if (resources != null) {
|
||||||
final int identifier = resources.getIdentifier(value, "string", packageName);
|
final int identifier = resources.getIdentifier(value, "string", packageName);
|
||||||
if (identifier == 0)
|
if (identifier == 0)
|
||||||
LogHelper.printException(() -> ("Resource not found: " + value));
|
LogHelper.printException(() -> "Resource not found: " + value);
|
||||||
else
|
else
|
||||||
value = resources.getString(identifier);
|
value = resources.getString(identifier);
|
||||||
} else {
|
} else {
|
||||||
LogHelper.printException(() -> ("Could not resolve resources!"));
|
LogHelper.printException(() -> "Could not resolve resources!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -25,7 +25,7 @@ public class SwipeHelper {
|
|||||||
isTabletMode = true;
|
isTabletMode = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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 {
|
try {
|
||||||
nextGenWatchLayout = (ViewGroup) obj;
|
nextGenWatchLayout = (ViewGroup) obj;
|
||||||
} catch (Exception e) {
|
} 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 {
|
try {
|
||||||
} catch (Exception e) {
|
} 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) {
|
if (_frameLayout.getChildCount() > 0) {
|
||||||
return _frameLayout.getChildAt(0).getVisibility() == View.VISIBLE;
|
return _frameLayout.getChildAt(0).getVisibility() == View.VISIBLE;
|
||||||
@ -61,7 +61,7 @@ public class SwipeHelper {
|
|||||||
LogHelper.printDebug(() -> "related_endscreen_results refreshed");
|
LogHelper.printDebug(() -> "related_endscreen_results refreshed");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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;
|
isShowing = true;
|
||||||
changeVisibilityImmediate(false);
|
changeVisibilityImmediate(false);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> ("Unable to set RelativeLayout"), ex);
|
LogHelper.printException(() -> "Unable to set RelativeLayout", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +68,7 @@ public class VotingButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void changeVisibility(boolean visible, boolean immediate) {
|
public static void changeVisibility(boolean visible, boolean immediate) {
|
||||||
|
try {
|
||||||
if (isShowing == visible) return;
|
if (isShowing == visible) return;
|
||||||
isShowing = visible;
|
isShowing = visible;
|
||||||
|
|
||||||
@ -91,6 +92,9 @@ public class VotingButton {
|
|||||||
iView.startAnimation(fadeOut);
|
iView.startAnimation(fadeOut);
|
||||||
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
iView.setVisibility(shouldBeShown() ? View.INVISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "changeVisibility failure", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean shouldBeShown() {
|
static boolean shouldBeShown() {
|
||||||
|
@ -48,7 +48,7 @@ public abstract class SlimButton implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
setContainerVisibility();
|
setContainerVisibility();
|
||||||
} catch (Exception ex) {
|
} 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();
|
addView();
|
||||||
} catch (Exception ex) {
|
} 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);
|
setSkipBtnMargins(false);
|
||||||
setNewSegmentLayoutMargins(false);
|
setNewSegmentLayoutMargins(false);
|
||||||
} catch (Exception ex) {
|
} 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) {
|
private static void setSkipBtnMargins(boolean fullScreen) {
|
||||||
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
||||||
if (skipSponsorButton == null) {
|
if (skipSponsorButton == null) {
|
||||||
LogHelper.printException(() -> ("Unable to setSkipBtnMargins"));
|
LogHelper.printException(() -> "Unable to setSkipBtnMargins");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) skipSponsorButton.getLayoutParams();
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) skipSponsorButton.getLayoutParams();
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
LogHelper.printException(() -> ("Unable to setSkipBtnMargins"));
|
LogHelper.printException(() -> "Unable to setSkipBtnMargins");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
params.bottomMargin = fullScreen ? skipSponsorButton.ctaBottomMargin : skipSponsorButton.defaultBottomMargin;
|
params.bottomMargin = fullScreen ? skipSponsorButton.ctaBottomMargin : skipSponsorButton.defaultBottomMargin;
|
||||||
@ -103,7 +103,7 @@ public class SponsorBlockView {
|
|||||||
private static void skipSponsorButtonVisibility(boolean visible) {
|
private static void skipSponsorButtonVisibility(boolean visible) {
|
||||||
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
SkipSponsorButton skipSponsorButton = _skipSponsorButton.get();
|
||||||
if (skipSponsorButton == null) {
|
if (skipSponsorButton == null) {
|
||||||
LogHelper.printException(() -> ("Unable to skipSponsorButtonVisibility"));
|
LogHelper.printException(() -> "Unable to skipSponsorButtonVisibility");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +116,13 @@ public class SponsorBlockView {
|
|||||||
private static void setNewSegmentLayoutMargins(boolean fullScreen) {
|
private static void setNewSegmentLayoutMargins(boolean fullScreen) {
|
||||||
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
||||||
if (newSegmentLayout == null) {
|
if (newSegmentLayout == null) {
|
||||||
LogHelper.printException(() -> ("Unable to setNewSegmentLayoutMargins"));
|
LogHelper.printException(() -> "Unable to setNewSegmentLayoutMargins");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) newSegmentLayout.getLayoutParams();
|
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) newSegmentLayout.getLayoutParams();
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
LogHelper.printException(() -> ("Unable to setNewSegmentLayoutMargins"));
|
LogHelper.printException(() -> "Unable to setNewSegmentLayoutMargins");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
params.bottomMargin = fullScreen ? newSegmentLayout.ctaBottomMargin : newSegmentLayout.defaultBottomMargin;
|
params.bottomMargin = fullScreen ? newSegmentLayout.ctaBottomMargin : newSegmentLayout.defaultBottomMargin;
|
||||||
@ -132,7 +132,7 @@ public class SponsorBlockView {
|
|||||||
private static void newSegmentLayoutVisibility(boolean visible) {
|
private static void newSegmentLayoutVisibility(boolean visible) {
|
||||||
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
NewSegmentLayout newSegmentLayout = _newSegmentLayout.get();
|
||||||
if (newSegmentLayout == null) {
|
if (newSegmentLayout == null) {
|
||||||
LogHelper.printException(() -> ("Unable to newSegmentLayoutVisibility"));
|
LogHelper.printException(() -> "Unable to newSegmentLayoutVisibility");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
|
|||||||
import app.revanced.integrations.sponsorblock.SponsorBlockUtils.VoteOption;
|
import app.revanced.integrations.sponsorblock.SponsorBlockUtils.VoteOption;
|
||||||
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
||||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||||
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
public class SBRequester {
|
public class SBRequester {
|
||||||
private static final String TIME_TEMPLATE = "%.3f";
|
private static final String TIME_TEMPLATE = "%.3f";
|
||||||
@ -79,7 +80,7 @@ public class SBRequester {
|
|||||||
}
|
}
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to get segments", ex);
|
||||||
}
|
}
|
||||||
return segments.toArray(new SponsorSegment[0]);
|
return segments.toArray(new SponsorSegment[0]);
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ public class SBRequester {
|
|||||||
runOnMainThread(toastRunnable);
|
runOnMainThread(toastRunnable);
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to submit segments", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +125,12 @@ public class SBRequester {
|
|||||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.VIEWED_SEGMENT, segment.UUID);
|
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.VIEWED_SEGMENT, segment.UUID);
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} 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) {
|
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, String... args) {
|
||||||
new Thread(() -> {
|
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
||||||
try {
|
try {
|
||||||
String segmentUuid = segment.UUID;
|
String segmentUuid = segment.UUID;
|
||||||
String uuid = SettingsEnum.SB_UUID.getString();
|
String uuid = SettingsEnum.SB_UUID.getString();
|
||||||
@ -156,7 +157,7 @@ public class SBRequester {
|
|||||||
runOnMainThread(() -> Toast.makeText(context, SponsorBlockUtils.messageToToast, Toast.LENGTH_LONG).show());
|
runOnMainThread(() -> Toast.makeText(context, SponsorBlockUtils.messageToToast, Toast.LENGTH_LONG).show());
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to vote for segment", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
@ -167,20 +168,20 @@ public class SBRequester {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
||||||
try {
|
try {
|
||||||
JSONObject json = getJSONObject(SBRoutes.GET_USER_STATS, SettingsEnum.SB_UUID.getString());
|
JSONObject json = getJSONObject(SBRoutes.GET_USER_STATS, SettingsEnum.SB_UUID.getString());
|
||||||
UserStats stats = new UserStats(json.getString("userName"), json.getDouble("minutesSaved"), json.getInt("segmentCount"),
|
UserStats stats = new UserStats(json.getString("userName"), json.getDouble("minutesSaved"), json.getInt("segmentCount"),
|
||||||
json.getInt("viewCount"));
|
json.getInt("viewCount"));
|
||||||
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to retrieve user stats", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
||||||
new Thread(() -> {
|
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SettingsEnum.SB_UUID.getString(), username);
|
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SettingsEnum.SB_UUID.getString(), username);
|
||||||
int responseCode = connection.getResponseCode();
|
int responseCode = connection.getResponseCode();
|
||||||
@ -197,7 +198,7 @@ public class SBRequester {
|
|||||||
runOnMainThread(toastRunnable);
|
runOnMainThread(toastRunnable);
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to set username", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
@ -213,7 +214,7 @@ public class SBRequester {
|
|||||||
SettingsEnum.SB_IS_VIP.saveValue(vip);
|
SettingsEnum.SB_IS_VIP.saveValue(vip);
|
||||||
SettingsEnum.SB_LAST_VIP_CHECK.saveValue(now);
|
SettingsEnum.SB_LAST_VIP_CHECK.saveValue(now);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
LogHelper.printException(() -> "failed to check VIP", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import android.content.Context
|
|||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import app.revanced.integrations.swipecontrols.misc.clamp
|
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
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +29,7 @@ class AudioVolumeController(
|
|||||||
// bind audio service
|
// bind audio service
|
||||||
val mgr = context.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
val mgr = context.getSystemService(Context.AUDIO_SERVICE) as? AudioManager
|
||||||
if (mgr == null) {
|
if (mgr == null) {
|
||||||
printDebug { "failed to acquire AUDIO_SERVICE" }
|
printException { "failed to acquire AUDIO_SERVICE" }
|
||||||
} else {
|
} else {
|
||||||
audioManager = mgr
|
audioManager = mgr
|
||||||
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
|
maximumVolumeIndex = audioManager.getStreamMaxVolume(targetStream)
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package app.revanced.integrations.utils;
|
package app.revanced.integrations.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
@ -13,16 +18,19 @@ public class LogHelper {
|
|||||||
* Log messages using lambdas.
|
* Log messages using lambdas.
|
||||||
*/
|
*/
|
||||||
public interface LogMessage {
|
public interface LogMessage {
|
||||||
|
@NonNull
|
||||||
String buildMessageString();
|
String buildMessageString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return For non inner classes, this returns {@link Class#getSimpleName()}.
|
* @return For outer classes, this returns {@link Class#getSimpleName()}.
|
||||||
* For inner classes (static and anonymous), this returns the enclosing class simple name.<br>
|
* For inner, static, or anonymous classes, this returns the simple name of the enclosing class.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* For example, each of these classes return 'SomethingView':<br>
|
* For example, each of these classes return 'SomethingView':
|
||||||
* com.company.SomethingView<br>
|
* <code>
|
||||||
* com.company.SomethingView$StaticClass<br>
|
* com.company.SomethingView
|
||||||
* com.company.SomethingView$1<br>
|
* com.company.SomethingView$StaticClass
|
||||||
|
* com.company.SomethingView$1
|
||||||
|
* </code>
|
||||||
*/
|
*/
|
||||||
private String findOuterClassSimpleName() {
|
private String findOuterClassSimpleName() {
|
||||||
var selfClass = this.getClass();
|
var selfClass = this.getClass();
|
||||||
@ -32,8 +40,8 @@ public class LogHelper {
|
|||||||
if (dollarSignIndex == -1) {
|
if (dollarSignIndex == -1) {
|
||||||
return selfClass.getSimpleName(); // already an outer class
|
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
|
// parse the simple name full name
|
||||||
// a class with no package returns index of -1, but incrementing gives index zero which is correct
|
// a class with no package returns index of -1, but incrementing gives index zero which is correct
|
||||||
final int simpleClassNameStartIndex = fullClassName.lastIndexOf('.') + 1;
|
final int simpleClassNameStartIndex = fullClassName.lastIndexOf('.') + 1;
|
||||||
@ -41,17 +49,14 @@ public class LogHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static final String REVANCED_LOG_PREFIX = "revanced: ";
|
||||||
* 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());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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()) {
|
if (SettingsEnum.DEBUG.getBoolean()) {
|
||||||
var messageString = message.buildMessageString();
|
var messageString = message.buildMessageString();
|
||||||
|
|
||||||
@ -60,62 +65,79 @@ public class LogHelper {
|
|||||||
var sw = new StringWriter();
|
var sw = new StringWriter();
|
||||||
new Throwable().printStackTrace(new PrintWriter(sw));
|
new Throwable().printStackTrace(new PrintWriter(sw));
|
||||||
|
|
||||||
builder.append(String.format("\n%s", sw));
|
builder.append('\n').append(sw);
|
||||||
messageString = builder.toString();
|
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) {
|
public static void printInfo(@NonNull LogMessage message) {
|
||||||
Log.e("revanced: " + message.findOuterClassSimpleName(), message.buildMessageString());
|
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) {
|
public static void printInfo(@NonNull LogMessage message, @Nullable Exception ex) {
|
||||||
Log.e("revanced: " + message.findOuterClassSimpleName(), message.buildMessageString(), 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)},
|
* Logs exceptions under the outer class name of the code calling this method.
|
||||||
* which does not cause log messages to be constructed unless logging is enabled.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public static void printException(@NonNull LogMessage message) {
|
||||||
public static void debug(Class _clazz, String message) {
|
printException(message, null, null);
|
||||||
printDebug(() -> message); // this fails to show the correct calling class name, but it's deprecated who cares
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated. Instead call {@link #printException(LogMessage, Throwable)}
|
* Logs exceptions under the outer class name of the code calling this method.
|
||||||
* or {@link #printException(LogMessage)}
|
|
||||||
* which does not cause log messages to be constructed unless logging is enabled.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
public static void printException(@NonNull LogMessage message, @Nullable Throwable ex) {
|
||||||
public static void printException(Class _clazz, String message, Throwable ex) {
|
printException(message, ex, null);
|
||||||
printException(() -> message, ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deprecated. Instead call {@link #printException(LogMessage)},
|
* Logs exceptions under the outer class name of the code calling this method.
|
||||||
* which does not cause log messages to be constructed unless logging is enabled.
|
* <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(@NonNull LogMessage message, @Nullable Throwable ex,
|
||||||
public static void printException(Class _clazz, String message) {
|
@Nullable String userToastMessage) {
|
||||||
printException(() -> message);
|
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.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.text.Bidi;
|
import java.text.Bidi;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@ -58,10 +60,6 @@ public class ReVancedUtils {
|
|||||||
// or some ReVanced code is submitting an unexpected number of background tasks.
|
// or some ReVanced code is submitting an unexpected number of background tasks.
|
||||||
LogHelper.printException(() -> "Reached maximum background thread count of "
|
LogHelper.printException(() -> "Reached maximum background thread count of "
|
||||||
+ SHARED_THREAD_POOL_MAXIMUM_BACKGROUND_THREADS + " threads");
|
+ 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();
|
Resources res = context.getResources();
|
||||||
return res.getIdentifier(name, type, context.getPackageName());
|
return res.getIdentifier(name, type, context.getPackageName());
|
||||||
} catch (Throwable exception) {
|
} catch (Throwable exception) {
|
||||||
LogHelper.printException(() -> ("Resource not found."), exception);
|
LogHelper.printException(() -> "Resource not found.", exception);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +116,7 @@ public class ReVancedUtils {
|
|||||||
if (context != null) {
|
if (context != null) {
|
||||||
return context;
|
return context;
|
||||||
} else {
|
} else {
|
||||||
LogHelper.printException(() -> ("Context is null, returning null!"));
|
LogHelper.printException(() -> "Context is null, returning null!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,37 +147,44 @@ public class ReVancedUtils {
|
|||||||
* Automatically logs any exceptions the runnable throws
|
* Automatically logs any exceptions the runnable throws
|
||||||
*/
|
*/
|
||||||
public static void runOnMainThread(Runnable runnable) {
|
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 {
|
try {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
} catch (Exception ex) {
|
} 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
|
* @return if the calling thread is on the main thread
|
||||||
*/
|
*/
|
||||||
public static boolean currentIsOnMainThread() {
|
public static boolean currentlyIsOnMainThread() {
|
||||||
return Looper.getMainLooper().isCurrentThread();
|
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 {
|
public static void verifyOnMainThread() throws IllegalStateException {
|
||||||
if (!currentIsOnMainThread()) {
|
if (!currentlyIsOnMainThread()) {
|
||||||
throw new IllegalStateException("Must call _on_ the main thread");
|
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 {
|
public static void verifyOffMainThread() throws IllegalStateException {
|
||||||
if (currentIsOnMainThread()) {
|
if (currentlyIsOnMainThread()) {
|
||||||
throw new IllegalStateException("Must call _off_ the main thread");
|
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);
|
LogHelper.printDebug(() -> "Launched the intent with the content: " + content);
|
||||||
} catch (Exception error) {
|
} catch (Exception error) {
|
||||||
LogHelper.printDebug(() -> "Failed to launch the intent: " + error);
|
LogHelper.printException(() -> "Failed to launch the intent: " + error, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@ import android.util.Log;
|
|||||||
|
|
||||||
import app.revanced.tiktok.settings.SettingsEnum;
|
import app.revanced.tiktok.settings.SettingsEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: replace this with the higher performance logging code from {@link app.revanced.integrations.utils.LogHelper}
|
||||||
|
*/
|
||||||
public class LogHelper {
|
public class LogHelper {
|
||||||
|
|
||||||
//ToDo: Get Calling classname using Reflection
|
|
||||||
|
|
||||||
public static void debug(Class clazz, String message) {
|
public static void debug(Class clazz, String message) {
|
||||||
if (SettingsEnum.TIK_DEBUG.getBoolean()) {
|
if (SettingsEnum.TIK_DEBUG.getBoolean()) {
|
||||||
Log.d("revanced: " + (clazz != null ? clazz.getSimpleName() : ""), message);
|
Log.d("revanced: " + (clazz != null ? clazz.getSimpleName() : ""), message);
|
||||||
|
@ -5,8 +5,14 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import app.revanced.twitch.settings.SettingsEnum;
|
import app.revanced.twitch.settings.SettingsEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: replace this with the higher performance logging code from {@link app.revanced.integrations.utils.LogHelper}
|
||||||
|
*/
|
||||||
public class LogHelper {
|
public class LogHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: replace this with {@link app.revanced.integrations.utils.LogHelper.LogMessage#findOuterClassSimpleName()}
|
||||||
|
*/
|
||||||
public static String getCallOrigin()
|
public static String getCallOrigin()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user