mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-05 17:45:49 +01:00
SB request fixes
This commit is contained in:
parent
2ebad96acf
commit
b3768cb2c4
@ -3,11 +3,10 @@ package fi.vanced.libraries.youtube.whitelisting.requests;
|
||||
import static fi.razerman.youtube.XGlobals.debug;
|
||||
import static fi.vanced.libraries.youtube.player.VideoInformation.currentVideoId;
|
||||
import static fi.vanced.libraries.youtube.ui.AdButton.TAG;
|
||||
import static fi.vanced.utils.VancedUtils.runOnMainThread;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@ -89,10 +88,6 @@ public class WhitelistRequester {
|
||||
|
||||
// helpers
|
||||
|
||||
private static void runOnMainThread(Runnable runnable) {
|
||||
new Handler(Looper.getMainLooper()).post(runnable);
|
||||
}
|
||||
|
||||
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
||||
return Requester.getConnectionFromRoute(YT_API_URL, route, params);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package fi.vanced.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||
|
||||
@ -40,4 +42,8 @@ public class VancedUtils {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void runOnMainThread(Runnable runnable) {
|
||||
new Handler(Looper.getMainLooper()).post(runnable);
|
||||
}
|
||||
}
|
@ -223,10 +223,10 @@ public abstract class SponsorBlockUtils {
|
||||
appContext = new WeakReference<>(context.getApplicationContext());
|
||||
switch (voteOptions[which1]) {
|
||||
case UPVOTE:
|
||||
voteForSegment(segment, VoteOption.UPVOTE, appContext.get(), toastRunnable);
|
||||
voteForSegment(segment, VoteOption.UPVOTE, appContext.get());
|
||||
break;
|
||||
case DOWNVOTE:
|
||||
voteForSegment(segment, VoteOption.DOWNVOTE, appContext.get(), toastRunnable);
|
||||
voteForSegment(segment, VoteOption.DOWNVOTE, appContext.get());
|
||||
break;
|
||||
case CATEGORY_CHANGE:
|
||||
onNewCategorySelect(segment, context);
|
||||
@ -401,7 +401,7 @@ public abstract class SponsorBlockUtils {
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(str("new_segment_choose_category"))
|
||||
.setItems(titles, (dialog, which) -> voteForSegment(segment, VoteOption.CATEGORY_CHANGE, appContext.get(), toastRunnable, values[which].key))
|
||||
.setItems(titles, (dialog, which) -> voteForSegment(segment, VoteOption.CATEGORY_CHANGE, appContext.get(), values[which].key))
|
||||
.show();
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ public abstract class SponsorBlockUtils {
|
||||
preference.setText(userName);
|
||||
preference.setOnPreferenceChangeListener((preference1, newUsername) -> {
|
||||
appContext = new WeakReference<>(context.getApplicationContext());
|
||||
SBRequester.setUsername((String) newUsername, toastRunnable);
|
||||
SBRequester.setUsername((String) newUsername, preference, toastRunnable);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package pl.jakubweg.requests;
|
||||
|
||||
import static android.text.Html.fromHtml;
|
||||
import static fi.vanced.utils.VancedUtils.runOnMainThread;
|
||||
import static pl.jakubweg.SponsorBlockUtils.timeWithoutSegments;
|
||||
import static pl.jakubweg.SponsorBlockUtils.videoHasSegments;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.widget.Toast;
|
||||
@ -92,7 +93,7 @@ public class SBRequester {
|
||||
SponsorBlockUtils.messageToToast = str("submit_failed_unknown_error", responseCode, connection.getResponseMessage());
|
||||
break;
|
||||
}
|
||||
new Handler(Looper.getMainLooper()).post(toastRunnable);
|
||||
runOnMainThread(toastRunnable);
|
||||
connection.disconnect();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -110,36 +111,38 @@ public class SBRequester {
|
||||
}
|
||||
}
|
||||
|
||||
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, Runnable toastRunnable, String... args) {
|
||||
try {
|
||||
String segmentUuid = segment.UUID;
|
||||
String uuid = SponsorBlockSettings.uuid;
|
||||
String vote = Integer.toString(voteOption == VoteOption.UPVOTE ? 1 : 0);
|
||||
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, String... args) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
String segmentUuid = segment.UUID;
|
||||
String uuid = SponsorBlockSettings.uuid;
|
||||
String vote = Integer.toString(voteOption == VoteOption.UPVOTE ? 1 : 0);
|
||||
|
||||
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
|
||||
runOnMainThread(() -> Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show());
|
||||
|
||||
HttpURLConnection connection = voteOption == VoteOption.CATEGORY_CHANGE
|
||||
? getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_CATEGORY, segmentUuid, uuid, args[0])
|
||||
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, segmentUuid, uuid, vote);
|
||||
int responseCode = connection.getResponseCode();
|
||||
HttpURLConnection connection = voteOption == VoteOption.CATEGORY_CHANGE
|
||||
? getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_CATEGORY, segmentUuid, uuid, args[0])
|
||||
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, segmentUuid, uuid, vote);
|
||||
int responseCode = connection.getResponseCode();
|
||||
|
||||
switch (responseCode) {
|
||||
case 200:
|
||||
SponsorBlockUtils.messageToToast = str("vote_succeeded");
|
||||
break;
|
||||
case 403:
|
||||
SponsorBlockUtils.messageToToast = str("vote_failed_forbidden");
|
||||
break;
|
||||
default:
|
||||
SponsorBlockUtils.messageToToast = str("vote_failed_unknown_error", responseCode, connection.getResponseMessage());
|
||||
break;
|
||||
switch (responseCode) {
|
||||
case 200:
|
||||
SponsorBlockUtils.messageToToast = str("vote_succeeded");
|
||||
break;
|
||||
case 403:
|
||||
SponsorBlockUtils.messageToToast = str("vote_failed_forbidden");
|
||||
break;
|
||||
default:
|
||||
SponsorBlockUtils.messageToToast = str("vote_failed_unknown_error", responseCode, connection.getResponseMessage());
|
||||
break;
|
||||
}
|
||||
runOnMainThread(() -> Toast.makeText(context, SponsorBlockUtils.messageToToast, Toast.LENGTH_LONG).show());
|
||||
connection.disconnect();
|
||||
}
|
||||
new Handler(Looper.getMainLooper()).post(toastRunnable);
|
||||
connection.disconnect();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void retrieveUserStats(PreferenceCategory category, Preference loadingPreference) {
|
||||
@ -161,23 +164,29 @@ public class SBRequester {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void setUsername(String username, Runnable toastRunnable) {
|
||||
try {
|
||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SponsorBlockSettings.uuid, username);
|
||||
int responseCode = connection.getResponseCode();
|
||||
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SponsorBlockSettings.uuid, username);
|
||||
int responseCode = connection.getResponseCode();
|
||||
|
||||
if (responseCode == 200) {
|
||||
SponsorBlockUtils.messageToToast = str("stats_username_changed");
|
||||
if (responseCode == 200) {
|
||||
SponsorBlockUtils.messageToToast = str("stats_username_changed");
|
||||
runOnMainThread(() -> {
|
||||
preference.setTitle(fromHtml(str("stats_username", username)));
|
||||
preference.setText(username);
|
||||
});
|
||||
}
|
||||
else {
|
||||
SponsorBlockUtils.messageToToast = str("stats_username_change_unknown_error", responseCode, connection.getResponseMessage());
|
||||
}
|
||||
runOnMainThread(toastRunnable);
|
||||
connection.disconnect();
|
||||
}
|
||||
else {
|
||||
SponsorBlockUtils.messageToToast = str("stats_username_change_unknown_error", responseCode, connection.getResponseMessage());
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
new Handler(Looper.getMainLooper()).post(toastRunnable);
|
||||
connection.disconnect();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user