mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-07 10:35:49 +01:00
Added dislike formatting
This commit is contained in:
parent
e48e16ae69
commit
88a7838cd8
@ -7,6 +7,9 @@ import static fi.vanced.libraries.youtube.ryd.RYDSettings.PREFERENCES_NAME;
|
|||||||
import static fi.vanced.utils.VancedUtils.getIdentifier;
|
import static fi.vanced.utils.VancedUtils.getIdentifier;
|
||||||
import static fi.vanced.utils.VancedUtils.parseJson;
|
import static fi.vanced.utils.VancedUtils.parseJson;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.icu.text.CompactDecimalFormat;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -20,6 +23,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static fi.vanced.libraries.youtube.player.VideoInformation.dislikeCount;
|
import static fi.vanced.libraries.youtube.player.VideoInformation.dislikeCount;
|
||||||
|
|
||||||
@ -37,12 +41,28 @@ public class ReturnYouTubeDislikes {
|
|||||||
private static boolean likeActive;
|
private static boolean likeActive;
|
||||||
private static boolean dislikeActive;
|
private static boolean dislikeActive;
|
||||||
private static int votingValue = 0; // 1 = like, -1 = dislike, 0 = no vote
|
private static int votingValue = 0; // 1 = like, -1 = dislike, 0 = no vote
|
||||||
|
private static CompactDecimalFormat compactNumberFormatter;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
isEnabled = SharedPrefUtils.getBoolean(YouTubeTikTokRoot_Application.getAppContext(), PREFERENCES_NAME, PREFERENCES_KEY_RYD_ENABLED, false);
|
Context context = YouTubeTikTokRoot_Application.getAppContext();
|
||||||
|
isEnabled = SharedPrefUtils.getBoolean(context, PREFERENCES_NAME, PREFERENCES_KEY_RYD_ENABLED, false);
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
registration = new Registration(YouTubeTikTokRoot_Application.getAppContext());
|
registration = new Registration(context);
|
||||||
voting = new Voting(YouTubeTikTokRoot_Application.getAppContext(), registration);
|
voting = new Voting(context, registration);
|
||||||
|
}
|
||||||
|
|
||||||
|
Locale locale = context.getResources().getConfiguration().locale;
|
||||||
|
if (debug) {
|
||||||
|
Log.d(TAG, "locale - " + locale);
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
compactNumberFormatter = CompactDecimalFormat.getInstance(
|
||||||
|
locale,
|
||||||
|
CompactDecimalFormat.CompactStyle.SHORT
|
||||||
|
);
|
||||||
|
compactNumberFormatter.setMaximumIntegerDigits(3);
|
||||||
|
compactNumberFormatter.setMaximumFractionDigits(1);
|
||||||
|
compactNumberFormatter.setSignificantDigitsUsed(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +115,7 @@ public class ReturnYouTubeDislikes {
|
|||||||
new Handler(Looper.getMainLooper()).post(new Runnable () {
|
new Handler(Looper.getMainLooper()).post(new Runnable () {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
trySetDislikes(String.valueOf(dislikeCount));
|
trySetDislikes(formatDislikes(dislikeCount));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -181,7 +201,7 @@ public class ReturnYouTubeDislikes {
|
|||||||
return originalText;
|
return originalText;
|
||||||
}
|
}
|
||||||
else if (tag == "dislike") {
|
else if (tag == "dislike") {
|
||||||
return dislikeCount != null ? String.valueOf(dislikeCount) : originalText;
|
return dislikeCount != null ? formatDislikes(dislikeCount) : originalText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@ -239,7 +259,7 @@ public class ReturnYouTubeDislikes {
|
|||||||
else { likeActive = false; }
|
else { likeActive = false; }
|
||||||
|
|
||||||
// Like was activated and dislike was previously activated
|
// Like was activated and dislike was previously activated
|
||||||
if (!previousState && dislikeActive) { dislikeCount--; trySetDislikes(String.valueOf(dislikeCount)); }
|
if (!previousState && dislikeActive) { dislikeCount--; trySetDislikes(formatDislikes(dislikeCount)); }
|
||||||
}
|
}
|
||||||
else if (tag == "dislike") {
|
else if (tag == "dislike") {
|
||||||
likeActive = false;
|
likeActive = false;
|
||||||
@ -248,7 +268,7 @@ public class ReturnYouTubeDislikes {
|
|||||||
if (!previousState) { votingValue = -1; dislikeActive = true; dislikeCount++; }
|
if (!previousState) { votingValue = -1; dislikeActive = true; dislikeCount++; }
|
||||||
// Dislike was removed
|
// Dislike was removed
|
||||||
else { dislikeActive = false; dislikeCount--; }
|
else { dislikeActive = false; dislikeCount--; }
|
||||||
trySetDislikes(String.valueOf(dislikeCount));
|
trySetDislikes(formatDislikes(dislikeCount));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Unknown tag
|
// Unknown tag
|
||||||
@ -324,4 +344,20 @@ public class ReturnYouTubeDislikes {
|
|||||||
Log.e(TAG, "Error while trying to set tag to view", ex);
|
Log.e(TAG, "Error while trying to set tag to view", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String formatDislikes(int dislikes) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && compactNumberFormatter != null) {
|
||||||
|
final String formatted = compactNumberFormatter.format(dislikes);
|
||||||
|
if (debug) {
|
||||||
|
Log.d(TAG, "Formatting dislikes - " + dislikes + " - " + formatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
Log.d(TAG, "Couldn't format dislikes, using the unformatted count - " + dislikes);
|
||||||
|
}
|
||||||
|
return String.valueOf(dislikes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user