From dfb25653b209dd156976081a7fac82afd582ad5c Mon Sep 17 00:00:00 2001
From: KevinX8 <pgnmaster24@gmail.com>
Date: Wed, 16 Feb 2022 01:05:23 +0000
Subject: [PATCH] Updated deps + fixed player buttons and dislike formatting

---
 app/build.gradle                                 |  7 +++----
 .../youtube/player/VideoInformation.java         | 12 +++++++-----
 .../youtube/ryd/ReturnYouTubeDislikes.java       | 16 +++++++---------
 app/src/main/res/values/strings.xml              |  4 ++--
 build.gradle                                     |  2 +-
 gradle/wrapper/gradle-wrapper.properties         |  2 +-
 6 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/app/build.gradle b/app/build.gradle
index f6f39a83..f13687c7 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,13 +1,12 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 30
-    buildToolsVersion "30.0.2"
+    compileSdkVersion 32
 
     defaultConfig {
         applicationId "vanced.integrations"
         minSdkVersion 21
-        targetSdkVersion 30
+        targetSdkVersion 31
         versionCode 1
         versionName "1.0"
         multiDexEnabled false
@@ -33,6 +32,6 @@ android {
 }
 
 dependencies {
-    implementation 'androidx.annotation:annotation:1.2.0'
+    implementation 'androidx.annotation:annotation:1.3.0'
 }
 
diff --git a/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java b/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java
index e11d5414..b4ee0138 100644
--- a/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java
+++ b/app/src/main/java/fi/vanced/libraries/youtube/player/VideoInformation.java
@@ -24,7 +24,7 @@ public class VideoInformation {
             if (debug) {
                 Log.d(TAG, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
             }
-            clearInformation();
+            clearInformation(true);
             return;
         }
 
@@ -53,15 +53,17 @@ public class VideoInformation {
     // Call hook in the YT code when the video ends
     public static void videoEnded() {
         saveTempInformation();
-        clearInformation();
+        clearInformation(false);
     }
 
     // Information is cleared once a video ends
     // It's cleared because the setCurrentVideoId isn't called for Shorts
     // so Shorts would otherwise use the information from the last watched video
-    private static void clearInformation() {
-        currentVideoId = null;
-        dislikeCount = null;
+    private static void clearInformation(boolean full) {
+        if (full) {
+            currentVideoId = null;
+            dislikeCount = null;
+        }
         channelName = null;
     }
 
diff --git a/app/src/main/java/fi/vanced/libraries/youtube/ryd/ReturnYouTubeDislikes.java b/app/src/main/java/fi/vanced/libraries/youtube/ryd/ReturnYouTubeDislikes.java
index d8f2a1ee..31724b08 100644
--- a/app/src/main/java/fi/vanced/libraries/youtube/ryd/ReturnYouTubeDislikes.java
+++ b/app/src/main/java/fi/vanced/libraries/youtube/ryd/ReturnYouTubeDislikes.java
@@ -17,6 +17,7 @@ import android.widget.TextView;
 import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
 
 import java.util.Locale;
+import java.util.Objects;
 
 import fi.vanced.libraries.youtube.ryd.requests.RYDRequester;
 import fi.vanced.utils.SharedPrefUtils;
@@ -36,7 +37,7 @@ public class ReturnYouTubeDislikes {
 
     static {
         Context context = YouTubeTikTokRoot_Application.getAppContext();
-        isEnabled = SharedPrefUtils.getBoolean(context, PREFERENCES_NAME, PREFERENCES_KEY_RYD_ENABLED, false);
+        isEnabled = SharedPrefUtils.getBoolean(Objects.requireNonNull(context), PREFERENCES_NAME, PREFERENCES_KEY_RYD_ENABLED, false);
         if (isEnabled) {
             registration = new Registration(context);
             voting = new Voting(context, registration);
@@ -51,9 +52,6 @@ public class ReturnYouTubeDislikes {
                     locale,
                     CompactDecimalFormat.CompactStyle.SHORT
             );
-            compactNumberFormatter.setMaximumIntegerDigits(3);
-            compactNumberFormatter.setMaximumFractionDigits(1);
-            compactNumberFormatter.setSignificantDigitsUsed(false);
         }
     }
 
@@ -199,7 +197,8 @@ public class ReturnYouTubeDislikes {
     }
 
     private static void handleOnClick(View view, boolean previousState) {
-        if (!isEnabled) return;
+        Context context = YouTubeTikTokRoot_Application.getAppContext();
+        if (!isEnabled || SharedPrefUtils.getBoolean(Objects.requireNonNull(context),"youtube","user_signed_out",true)) return;
 
         try {
             String tag = (String) view.getTag();
@@ -210,7 +209,7 @@ public class ReturnYouTubeDislikes {
 
             // If active status was removed, vote should be none
             if (previousState) { votingValue = 0; }
-            if (tag == "like") {
+            if (tag.equals("like")) {
                 dislikeActive = false;
 
                 // Like was activated
@@ -218,9 +217,9 @@ public class ReturnYouTubeDislikes {
                 else { likeActive = false; }
 
                 // Like was activated and dislike was previously activated
-                if (!previousState && dislikeActive) { dislikeCount--; trySetDislikes(formatDislikes(dislikeCount)); }
+                if (!previousState) { dislikeCount--; trySetDislikes(formatDislikes(dislikeCount)); }
             }
-            else if (tag == "dislike") {
+            else if (tag.equals("dislike")) {
                 likeActive = false;
 
                 // Dislike was activated
@@ -274,7 +273,6 @@ public class ReturnYouTubeDislikes {
             }
             catch (Exception ex) {
                 Log.e(TAG, "Failed to send vote", ex);
-                return;
             }
         });
         _votingThread.start();
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c6e5edac..4c8a11c2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -369,11 +369,11 @@
     <string name="vanced_whitelisting_fetch_failed" formatted="false">Failed to retrieve channel details, received code %d</string>
     <string name="vanced_button_location_entry_none">Hidden</string>
     <string name="vanced_button_location_entry_player">In player</string>
-    <string name="vanced_button_location_entry_buttoncontainer">Under player</string>
+    <string name="vanced_button_location_entry_buttoncontainer">Under player (ALPHA)</string>
     <string name="vanced_button_location_entry_both">Both</string>
     <string name="vanced_ryd_settings_title">Return YouTube Dislike settings</string>
     <string name="vanced_ryd_settings_summary">Uses the RYD API</string>
-    <string name="vanced_ryd_title">Enable RYD</string>
+    <string name="vanced_ryd_title">Enable RYD (ALPHA)</string>
     <string name="vanced_ryd_summary">Switch this on to see the dislike counts again</string>
     <string name="vanced_ryd_attribution_title">Return YouTube Dislike Integration</string>
     <string name="vanced_ryd_attribution_summary">This integration uses the RYD API from https://returnyoutubedislike.com. Tap to learn more</string>
diff --git a/build.gradle b/build.gradle
index 4a22cbf3..69833568 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
         mavenCentral()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:7.0.4'
+        classpath 'com.android.tools.build:gradle:7.1.1'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index e7c8788f..25999d56 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
 #Mon Jun 07 19:51:48 CEST 2021
 distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
 distributionPath=wrapper/dists
 zipStorePath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME