mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-26 07:55:49 +01:00
fix(YouTube - SponsorBlock): Show create new segment error messages using a dialog (#4148)
This commit is contained in:
parent
2694158c3c
commit
587090636d
@ -507,7 +507,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment {
|
|||||||
Utils.showToastLong(str("revanced_sb_stats_username_changed"));
|
Utils.showToastLong(str("revanced_sb_stats_username_changed"));
|
||||||
} else {
|
} else {
|
||||||
preference.setText(userName); // revert to previous
|
preference.setText(userName); // revert to previous
|
||||||
Utils.showToastLong(errorMessage);
|
SponsorBlockUtils.showErrorDialog(errorMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -363,6 +363,16 @@ public class SponsorBlockUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showErrorDialog(String dialogMessage) {
|
||||||
|
Utils.runOnMainThreadNowOrLater(() ->
|
||||||
|
new AlertDialog.Builder(SponsorBlockViewController.getOverLaysViewGroupContext())
|
||||||
|
.setMessage(dialogMessage)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.setCancelable(false)
|
||||||
|
.show()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static void onEditByHandClicked() {
|
public static void onEditByHandClicked() {
|
||||||
try {
|
try {
|
||||||
Utils.verifyOnMainThread();
|
Utils.verifyOnMainThread();
|
||||||
|
@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import app.revanced.extension.youtube.settings.Settings;
|
import app.revanced.extension.youtube.settings.Settings;
|
||||||
import app.revanced.extension.youtube.sponsorblock.SponsorBlockSettings;
|
import app.revanced.extension.youtube.sponsorblock.SponsorBlockSettings;
|
||||||
|
import app.revanced.extension.youtube.sponsorblock.SponsorBlockUtils;
|
||||||
import app.revanced.extension.youtube.sponsorblock.objects.SegmentCategory;
|
import app.revanced.extension.youtube.sponsorblock.objects.SegmentCategory;
|
||||||
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment;
|
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment;
|
||||||
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment.SegmentVote;
|
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment.SegmentVote;
|
||||||
@ -142,6 +143,7 @@ public class SBRequester {
|
|||||||
public static void submitSegments(@NonNull String videoId, @NonNull String category,
|
public static void submitSegments(@NonNull String videoId, @NonNull String category,
|
||||||
long startTime, long endTime, long videoLength) {
|
long startTime, long endTime, long videoLength) {
|
||||||
Utils.verifyOffMainThread();
|
Utils.verifyOffMainThread();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String privateUserId = SponsorBlockSettings.getSBPrivateUserID();
|
String privateUserId = SponsorBlockSettings.getSBPrivateUserID();
|
||||||
String start = String.format(Locale.US, TIME_TEMPLATE, startTime / 1000f);
|
String start = String.format(Locale.US, TIME_TEMPLATE, startTime / 1000f);
|
||||||
@ -151,35 +153,29 @@ public class SBRequester {
|
|||||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.SUBMIT_SEGMENTS, privateUserId, videoId, category, start, end, duration);
|
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.SUBMIT_SEGMENTS, privateUserId, videoId, category, start, end, duration);
|
||||||
final int responseCode = connection.getResponseCode();
|
final int responseCode = connection.getResponseCode();
|
||||||
|
|
||||||
final String messageToToast;
|
String userMessage = switch (responseCode) {
|
||||||
switch (responseCode) {
|
case HTTP_STATUS_CODE_SUCCESS -> str("revanced_sb_submit_succeeded");
|
||||||
case HTTP_STATUS_CODE_SUCCESS:
|
case 409 -> str("revanced_sb_submit_failed_duplicate");
|
||||||
messageToToast = str("revanced_sb_submit_succeeded");
|
case 403 -> str("revanced_sb_submit_failed_forbidden",
|
||||||
break;
|
Requester.parseErrorStringAndDisconnect(connection));
|
||||||
case 409:
|
case 429 -> str("revanced_sb_submit_failed_rate_limit");
|
||||||
messageToToast = str("revanced_sb_submit_failed_duplicate");
|
case 400 -> str("revanced_sb_submit_failed_invalid",
|
||||||
break;
|
Requester.parseErrorStringAndDisconnect(connection));
|
||||||
case 403:
|
default -> str("revanced_sb_submit_failed_unknown_error",
|
||||||
messageToToast = str("revanced_sb_submit_failed_forbidden", Requester.parseErrorStringAndDisconnect(connection));
|
responseCode, connection.getResponseMessage());
|
||||||
break;
|
};
|
||||||
case 429:
|
|
||||||
messageToToast = str("revanced_sb_submit_failed_rate_limit");
|
// Message might be about the users account or an error too large to show in a toast.
|
||||||
break;
|
// Use a dialog instead.
|
||||||
case 400:
|
SponsorBlockUtils.showErrorDialog(userMessage);
|
||||||
messageToToast = str("revanced_sb_submit_failed_invalid", Requester.parseErrorStringAndDisconnect(connection));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
messageToToast = str("revanced_sb_submit_failed_unknown_error", responseCode, connection.getResponseMessage());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Utils.showToastLong(messageToToast);
|
|
||||||
} catch (SocketTimeoutException ex) {
|
} catch (SocketTimeoutException ex) {
|
||||||
// Always show, even if show connection toasts is turned off
|
Logger.printDebug(() -> "Timeout", ex);
|
||||||
Utils.showToastLong(str("revanced_sb_submit_failed_timeout"));
|
Utils.showToastLong(str("revanced_sb_submit_failed_timeout"));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
Logger.printDebug(() -> "IOException", ex);
|
||||||
Utils.showToastLong(str("revanced_sb_submit_failed_unknown_error", 0, ex.getMessage()));
|
Utils.showToastLong(str("revanced_sb_submit_failed_unknown_error", 0, ex.getMessage()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.printException(() -> "failed to submit segments", ex);
|
Logger.printException(() -> "failed to submit segments", ex); // Should never happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,19 +214,22 @@ public class SBRequester {
|
|||||||
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, uuid, segmentUuid, String.valueOf(voteOption.apiVoteType));
|
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, uuid, segmentUuid, String.valueOf(voteOption.apiVoteType));
|
||||||
final int responseCode = connection.getResponseCode();
|
final int responseCode = connection.getResponseCode();
|
||||||
|
|
||||||
|
String userMessage;
|
||||||
switch (responseCode) {
|
switch (responseCode) {
|
||||||
case HTTP_STATUS_CODE_SUCCESS:
|
case HTTP_STATUS_CODE_SUCCESS:
|
||||||
Logger.printDebug(() -> "Vote success for segment: " + segment);
|
Logger.printDebug(() -> "Vote success for segment: " + segment);
|
||||||
break;
|
return;
|
||||||
case 403:
|
case 403:
|
||||||
Utils.showToastLong(
|
userMessage = str("revanced_sb_vote_failed_forbidden",
|
||||||
str("revanced_sb_vote_failed_forbidden", Requester.parseErrorStringAndDisconnect(connection)));
|
Requester.parseErrorStringAndDisconnect(connection));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Utils.showToastLong(
|
userMessage = str("revanced_sb_vote_failed_unknown_error",
|
||||||
str("revanced_sb_vote_failed_unknown_error", responseCode, connection.getResponseMessage()));
|
responseCode, connection.getResponseMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SponsorBlockUtils.showErrorDialog(userMessage);
|
||||||
} catch (SocketTimeoutException ex) {
|
} catch (SocketTimeoutException ex) {
|
||||||
Utils.showToastShort(str("revanced_sb_vote_failed_timeout"));
|
Utils.showToastShort(str("revanced_sb_vote_failed_timeout"));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user