Video info testing

This commit is contained in:
VancedOfficial 2022-01-24 18:10:33 +02:00
parent 61b6c6a371
commit 3a1bc1596a
1 changed files with 44 additions and 5 deletions

View File

@ -10,22 +10,29 @@ public class VideoInformation {
private static final String TAG = "VI - VideoInfo";
public static String currentVideoId;
public static Integer dislikeCount = null;
public static String channelName = null;
public static Integer dislikeCount;
public static String channelName;
public static long lastKnownVideoTime = -1L;
private static boolean tempInfoSaved = false;
private static String tempVideoId;
private static Integer tempDislikeCount;
// Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) {
if (videoId == null) {
if (debug) {
Log.d(TAG, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
}
currentVideoId = null;
dislikeCount = null;
channelName = null;
clearInformation();
return;
}
// Restore temporary information that was stored from the last watched video
if (tempInfoSaved) {
restoreTempInformation();
}
if (videoId.equals(currentVideoId)) {
if (debug) {
Log.d(TAG, "setCurrentVideoId - new and current video were equal - " + videoId);
@ -42,4 +49,36 @@ public class VideoInformation {
// New video
ReturnYouTubeDislikes.newVideoLoaded(videoId);
}
// Call hook in the YT code when the video ends
public static void videoEnded() {
saveTempInformation();
clearInformation();
}
// 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;
channelName = null;
}
// Temporary information is saved once a video ends
// so that if the user watches the same video again,
// the information can be restored without having to fetch again
private static void saveTempInformation() {
tempVideoId = currentVideoId;
tempDislikeCount = dislikeCount;
tempInfoSaved = true;
}
private static void restoreTempInformation() {
currentVideoId = tempVideoId;
dislikeCount = tempDislikeCount;
tempVideoId = null;
tempDislikeCount = null;
tempInfoSaved = false;
}
}