style: naming for ReturnYouTubeDislike patch

This commit is contained in:
oSumAtrIX 2022-07-16 17:42:51 +02:00
parent 7e236b01fb
commit fb102cfafe
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
9 changed files with 65 additions and 65 deletions

View File

@ -2,7 +2,7 @@ package app.revanced.integrations.patches;
import java.util.concurrent.atomic.AtomicReference;
import app.revanced.integrations.ryd.ReturnYouTubeDislikes;
import app.revanced.integrations.returnyoutubedislike.ReturnYouTubeDislike;
/**
* Used by app.revanced.patches.youtube.layout.returnyoutubedislikes.patch.RYDPatch
@ -13,14 +13,14 @@ public class ReturnYouTubeDislikesPatch {
* Called when the video id changes
*/
public static void newVideoLoaded(String videoId) {
ReturnYouTubeDislikes.newVideoLoaded(videoId);
ReturnYouTubeDislike.newVideoLoaded(videoId);
}
/**
* Called when a litho text component is created
*/
public static void onComponentCreated(Object conversionContext, AtomicReference<Object> textRef) {
ReturnYouTubeDislikes.onComponentCreated(conversionContext, textRef);
ReturnYouTubeDislike.onComponentCreated(conversionContext, textRef);
}
/**
@ -28,6 +28,6 @@ public class ReturnYouTubeDislikesPatch {
* @param vote -1 (dislike), 0 (none) or 1 (like)
*/
public static void sendVote(int vote) {
ReturnYouTubeDislikes.sendVote(vote);
ReturnYouTubeDislike.sendVote(vote);
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.ryd;
package app.revanced.integrations.returnyoutubedislike;
import android.util.Base64;
@ -8,7 +8,7 @@ import java.security.SecureRandom;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.ryd.requests.RYDRequester;
import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
public class Registration {
@ -58,7 +58,7 @@ public class Registration {
private String register() {
String userId = randomString(36);
LogHelper.debug(Registration.class, "Trying to register the following userId: " + userId);
return RYDRequester.register(userId, this);
return ReturnYouTubeDislikeApi.register(userId, this);
}
private String randomString(int len) {

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.ryd;
package app.revanced.integrations.returnyoutubedislike;
import static app.revanced.integrations.videoplayer.VideoInformation.currentVideoId;
import static app.revanced.integrations.videoplayer.VideoInformation.dislikeCount;
@ -12,13 +12,13 @@ import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import app.revanced.integrations.ryd.requests.RYDRequester;
import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
public class ReturnYouTubeDislikes {
public class ReturnYouTubeDislike {
private static boolean isEnabled;
private static Thread _dislikeFetchThread = null;
private static Thread _votingThread = null;
@ -35,7 +35,7 @@ public class ReturnYouTubeDislikes {
}
Locale locale = context.getResources().getConfiguration().locale;
LogHelper.debug(ReturnYouTubeDislikes.class, "locale - " + locale);
LogHelper.debug(ReturnYouTubeDislike.class, "locale - " + locale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
compactNumberFormatter = CompactDecimalFormat.getInstance(
locale,
@ -55,21 +55,21 @@ public class ReturnYouTubeDislikes {
}
public static void newVideoLoaded(String videoId) {
LogHelper.debug(ReturnYouTubeDislikes.class, "newVideoLoaded - " + videoId);
LogHelper.debug(ReturnYouTubeDislike.class, "newVideoLoaded - " + videoId);
dislikeCount = null;
if (!isEnabled) return;
try {
if (_dislikeFetchThread != null && _dislikeFetchThread.getState() != Thread.State.TERMINATED) {
LogHelper.debug(ReturnYouTubeDislikes.class, "Interrupting the thread. Current state " + _dislikeFetchThread.getState());
LogHelper.debug(ReturnYouTubeDislike.class, "Interrupting the thread. Current state " + _dislikeFetchThread.getState());
_dislikeFetchThread.interrupt();
}
} catch (Exception ex) {
LogHelper.printException(ReturnYouTubeDislikes.class, "Error in the dislike fetch thread", ex);
LogHelper.printException(ReturnYouTubeDislike.class, "Error in the dislike fetch thread", ex);
}
_dislikeFetchThread = new Thread(() -> RYDRequester.fetchDislikes(videoId));
_dislikeFetchThread = new Thread(() -> ReturnYouTubeDislikeApi.fetchDislikes(videoId));
_dislikeFetchThread.start();
}
@ -80,7 +80,7 @@ public class ReturnYouTubeDislikes {
// Contains a pathBuilder string, used to distinguish from other litho components
if (!conversionContext.toString().contains("dislike_button")) return;
LogHelper.debug(ReturnYouTubeDislikes.class, "dislike button was created");
LogHelper.debug(ReturnYouTubeDislike.class, "dislike button was created");
// Have to block the current thread until fetching is done
// There's no known way to edit the text after creation yet
@ -90,7 +90,7 @@ public class ReturnYouTubeDislikes {
updateDislikeText(textRef, formatDislikes(dislikeCount));
}
} catch (Exception ex) {
LogHelper.printException(ReturnYouTubeDislikes.class, "Error while trying to set dislikes text", ex);
LogHelper.printException(ReturnYouTubeDislike.class, "Error while trying to set dislikes text", ex);
}
}
@ -101,22 +101,22 @@ public class ReturnYouTubeDislikes {
if (SharedPrefHelper.getBoolean(Objects.requireNonNull(context), SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true))
return;
LogHelper.debug(ReturnYouTubeDislikes.class, "sending vote - " + vote + " for video " + currentVideoId);
LogHelper.debug(ReturnYouTubeDislike.class, "sending vote - " + vote + " for video " + currentVideoId);
try {
if (_votingThread != null && _votingThread.getState() != Thread.State.TERMINATED) {
LogHelper.debug(ReturnYouTubeDislikes.class, "Interrupting the thread. Current state " + _votingThread.getState());
LogHelper.debug(ReturnYouTubeDislike.class, "Interrupting the thread. Current state " + _votingThread.getState());
_votingThread.interrupt();
}
} catch (Exception ex) {
LogHelper.printException(ReturnYouTubeDislikes.class, "Error in the voting thread", ex);
LogHelper.printException(ReturnYouTubeDislike.class, "Error in the voting thread", ex);
}
_votingThread = new Thread(() -> {
try {
boolean result = voting.sendVote(currentVideoId, vote);
LogHelper.debug(ReturnYouTubeDislikes.class, "sendVote status " + result);
LogHelper.debug(ReturnYouTubeDislike.class, "sendVote status " + result);
} catch (Exception ex) {
LogHelper.printException(ReturnYouTubeDislikes.class, "Failed to send vote", ex);
LogHelper.printException(ReturnYouTubeDislike.class, "Failed to send vote", ex);
}
});
_votingThread.start();
@ -139,10 +139,10 @@ public class ReturnYouTubeDislikes {
private static String formatDislikes(int dislikes) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && compactNumberFormatter != null) {
final String formatted = compactNumberFormatter.format(dislikes);
LogHelper.debug(ReturnYouTubeDislikes.class, "Formatting dislikes - " + dislikes + " - " + formatted);
LogHelper.debug(ReturnYouTubeDislike.class, "Formatting dislikes - " + dislikes + " - " + formatted);
return formatted;
}
LogHelper.debug(ReturnYouTubeDislikes.class, "Couldn't format dislikes, using the unformatted count - " + dislikes);
LogHelper.debug(ReturnYouTubeDislike.class, "Couldn't format dislikes, using the unformatted count - " + dislikes);
return String.valueOf(dislikes);
}
}

View File

@ -1,7 +1,7 @@
package app.revanced.integrations.ryd;
package app.revanced.integrations.returnyoutubedislike;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.ryd.requests.RYDRequester;
import app.revanced.integrations.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
public class Voting {
private Registration registration;
@ -13,6 +13,6 @@ public class Voting {
public boolean sendVote(String videoId, int vote) {
String userId = registration.getUserId();
LogHelper.debug(Voting.class, "Trying to vote the following video: " + videoId + " with vote " + vote + " and userId: " + userId);
return RYDRequester.sendVote(videoId, userId, vote);
return ReturnYouTubeDislikeApi.sendVote(videoId, userId, vote);
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.ryd.dialog;
package app.revanced.integrations.returnyoutubedislike.dialog;
import static app.revanced.integrations.sponsorblock.StringRef.str;

View File

@ -1,4 +1,4 @@
package app.revanced.integrations.ryd.requests;
package app.revanced.integrations.returnyoutubedislike.requests;
import static app.revanced.integrations.videoplayer.VideoInformation.dislikeCount;
import static app.revanced.integrations.whitelist.requests.Requester.parseJson;
@ -12,65 +12,65 @@ import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.ryd.Registration;
import app.revanced.integrations.returnyoutubedislike.Registration;
import app.revanced.integrations.whitelist.requests.Requester;
import app.revanced.integrations.whitelist.requests.Route;
public class RYDRequester {
public class ReturnYouTubeDislikeApi {
private static final String RYD_API_URL = "https://returnyoutubedislikeapi.com/";
private RYDRequester() {
private ReturnYouTubeDislikeApi() {
}
public static void fetchDislikes(String videoId) {
try {
LogHelper.debug(RYDRequester.class, "Fetching dislikes for " + videoId);
HttpURLConnection connection = getConnectionFromRoute(RYDRoutes.GET_DISLIKES, videoId);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Fetching dislikes for " + videoId);
HttpURLConnection connection = getConnectionFromRoute(ReturnYouTubeDislikeRoutes.GET_DISLIKES, videoId);
connection.setConnectTimeout(5 * 1000);
if (connection.getResponseCode() == 200) {
JSONObject json = getJSONObject(connection);
dislikeCount = json.getInt("dislikes");
LogHelper.debug(RYDRequester.class, "dislikes fetched - " + dislikeCount);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "dislikes fetched - " + dislikeCount);
} else {
LogHelper.debug(RYDRequester.class, "dislikes fetch response was " + connection.getResponseCode());
LogHelper.debug(ReturnYouTubeDislikeApi.class, "dislikes fetch response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
dislikeCount = null;
LogHelper.printException(RYDRequester.class, "Failed to fetch dislikes", ex);
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to fetch dislikes", ex);
}
}
public static String register(String userId, Registration registration) {
try {
HttpURLConnection connection = getConnectionFromRoute(RYDRoutes.GET_REGISTRATION, userId);
HttpURLConnection connection = getConnectionFromRoute(ReturnYouTubeDislikeRoutes.GET_REGISTRATION, userId);
connection.setConnectTimeout(5 * 1000);
if (connection.getResponseCode() == 200) {
JSONObject json = getJSONObject(connection);
String challenge = json.getString("challenge");
int difficulty = json.getInt("difficulty");
LogHelper.debug(RYDRequester.class, "Registration challenge - " + challenge + " with difficulty of " + difficulty);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration challenge - " + challenge + " with difficulty of " + difficulty);
// Solve the puzzle
String solution = Registration.solvePuzzle(challenge, difficulty);
LogHelper.debug(RYDRequester.class, "Registration confirmation solution is " + solution);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration confirmation solution is " + solution);
return confirmRegistration(userId, solution, registration);
} else {
LogHelper.debug(RYDRequester.class, "Registration response was " + connection.getResponseCode());
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
LogHelper.printException(RYDRequester.class, "Failed to register userId", ex);
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to register userId", ex);
}
return null;
}
private static String confirmRegistration(String userId, String solution, Registration registration) {
try {
LogHelper.debug(RYDRequester.class, "Trying to confirm registration for the following userId: " + userId + " with solution: " + solution);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Trying to confirm registration for the following userId: " + userId + " with solution: " + solution);
HttpURLConnection connection = getConnectionFromRoute(RYDRoutes.CONFIRM_REGISTRATION, userId);
HttpURLConnection connection = getConnectionFromRoute(ReturnYouTubeDislikeRoutes.CONFIRM_REGISTRATION, userId);
applyCommonRequestSettings(connection);
String jsonInputString = "{\"solution\": \"" + solution + "\"}";
@ -80,20 +80,20 @@ public class RYDRequester {
}
if (connection.getResponseCode() == 200) {
String result = parseJson(connection);
LogHelper.debug(RYDRequester.class, "Registration confirmation result was " + result);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration confirmation result was " + result);
if (result.equalsIgnoreCase("true")) {
registration.saveUserId(userId);
LogHelper.debug(RYDRequester.class, "Registration was successful for user " + userId);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration was successful for user " + userId);
return userId;
}
} else {
LogHelper.debug(RYDRequester.class, "Registration confirmation response was " + connection.getResponseCode());
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Registration confirmation response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
LogHelper.printException(RYDRequester.class, "Failed to confirm registration", ex);
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to confirm registration", ex);
}
return null;
@ -101,7 +101,7 @@ public class RYDRequester {
public static boolean sendVote(String videoId, String userId, int vote) {
try {
HttpURLConnection connection = getConnectionFromRoute(RYDRoutes.SEND_VOTE);
HttpURLConnection connection = getConnectionFromRoute(ReturnYouTubeDislikeRoutes.SEND_VOTE);
applyCommonRequestSettings(connection);
String voteJsonString = "{\"userId\": \"" + userId + "\", \"videoId\": \"" + videoId + "\", \"value\": \"" + vote + "\"}";
@ -114,27 +114,27 @@ public class RYDRequester {
JSONObject json = getJSONObject(connection);
String challenge = json.getString("challenge");
int difficulty = json.getInt("difficulty");
LogHelper.debug(RYDRequester.class, "Vote challenge - " + challenge + " with difficulty of " + difficulty);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote challenge - " + challenge + " with difficulty of " + difficulty);
// Solve the puzzle
String solution = Registration.solvePuzzle(challenge, difficulty);
LogHelper.debug(RYDRequester.class, "Vote confirmation solution is " + solution);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote confirmation solution is " + solution);
// Confirm vote
return confirmVote(videoId, userId, solution);
} else {
LogHelper.debug(RYDRequester.class, "Vote response was " + connection.getResponseCode());
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
LogHelper.printException(RYDRequester.class, "Failed to send vote", ex);
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to send vote", ex);
}
return false;
}
private static boolean confirmVote(String videoId, String userId, String solution) {
try {
HttpURLConnection connection = getConnectionFromRoute(RYDRoutes.CONFIRM_VOTE);
HttpURLConnection connection = getConnectionFromRoute(ReturnYouTubeDislikeRoutes.CONFIRM_VOTE);
applyCommonRequestSettings(connection);
String jsonInputString = "{\"userId\": \"" + userId + "\", \"videoId\": \"" + videoId + "\", \"solution\": \"" + solution + "\"}";
@ -144,20 +144,20 @@ public class RYDRequester {
}
if (connection.getResponseCode() == 200) {
String result = parseJson(connection);
LogHelper.debug(RYDRequester.class, "Vote confirmation result was " + result);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote confirmation result was " + result);
if (result.equalsIgnoreCase("true")) {
LogHelper.debug(RYDRequester.class, "Vote was successful for user " + userId);
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote was successful for user " + userId);
return true;
}
} else {
LogHelper.debug(RYDRequester.class, "Vote confirmation response was " + connection.getResponseCode());
LogHelper.debug(ReturnYouTubeDislikeApi.class, "Vote confirmation response was " + connection.getResponseCode());
}
connection.disconnect();
} catch (Exception ex) {
LogHelper.printException(RYDRequester.class, "Failed to confirm vote", ex);
LogHelper.printException(ReturnYouTubeDislikeApi.class, "Failed to confirm vote", ex);
}
return false;
}

View File

@ -1,17 +1,17 @@
package app.revanced.integrations.ryd.requests;
package app.revanced.integrations.returnyoutubedislike.requests;
import static app.revanced.integrations.whitelist.requests.Route.Method.GET;
import static app.revanced.integrations.whitelist.requests.Route.Method.POST;
import app.revanced.integrations.whitelist.requests.Route;
public class RYDRoutes {
public class ReturnYouTubeDislikeRoutes {
public static final Route SEND_VOTE = new Route(POST, "interact/vote");
public static final Route CONFIRM_VOTE = new Route(POST, "interact/confirmVote");
public static final Route GET_DISLIKES = new Route(GET, "votes?videoId={video_id}");
public static final Route GET_REGISTRATION = new Route(GET, "puzzle/registration?userId={user_id}");
public static final Route CONFIRM_REGISTRATION = new Route(POST, "puzzle/registration?userId={user_id}");
private RYDRoutes() {
private ReturnYouTubeDislikeRoutes() {
}
}

View File

@ -37,7 +37,7 @@ public class ReVancedSettingActivity extends Activity {
getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), new SponsorBlockSettingsFragment()).commit();
} else if (dataString.equalsIgnoreCase("ryd_settings")) {
trySetTitle(getIdentifier("revanced_ryd_settings_title", "string"));
getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), new RYDSettingsFragment()).commit();
getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), new ReturnYouTubeDislikeSettingsFragment()).commit();
} else {
trySetTitle(getIdentifier("revanced_settings", "string"));
getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), new ReVancedSettingsFragment()).commit();

View File

@ -13,11 +13,11 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import app.revanced.integrations.ryd.ReturnYouTubeDislikes;
import app.revanced.integrations.returnyoutubedislike.ReturnYouTubeDislike;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.SharedPrefHelper;
public class RYDSettingsFragment extends PreferenceFragment {
public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -39,7 +39,7 @@ public class RYDSettingsFragment extends PreferenceFragment {
preference.setSummary(str("revanced_ryd_summary"));
preference.setOnPreferenceChangeListener((pref, newValue) -> {
final boolean value = (Boolean) newValue;
ReturnYouTubeDislikes.onEnabledChange(value);
ReturnYouTubeDislike.onEnabledChange(value);
return true;
});
}