Video info testing

This commit is contained in:
VancedOfficial 2022-01-24 18:10:33 +02:00
parent 88a7838cd8
commit 8020f1b704

View File

@ -10,22 +10,29 @@ public class VideoInformation {
private static final String TAG = "VI - VideoInfo"; private static final String TAG = "VI - VideoInfo";
public static String currentVideoId; public static String currentVideoId;
public static Integer dislikeCount = null; public static Integer dislikeCount;
public static String channelName = null; public static String channelName;
public static long lastKnownVideoTime = -1L; 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 // Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) { public static void setCurrentVideoId(final String videoId) {
if (videoId == null) { if (videoId == null) {
if (debug) { if (debug) {
Log.d(TAG, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId); Log.d(TAG, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
} }
currentVideoId = null; clearInformation();
dislikeCount = null;
channelName = null;
return; return;
} }
// Restore temporary information that was stored from the last watched video
if (tempInfoSaved) {
restoreTempInformation();
}
if (videoId.equals(currentVideoId)) { if (videoId.equals(currentVideoId)) {
if (debug) { if (debug) {
Log.d(TAG, "setCurrentVideoId - new and current video were equal - " + videoId); Log.d(TAG, "setCurrentVideoId - new and current video were equal - " + videoId);
@ -42,4 +49,36 @@ public class VideoInformation {
// New video // New video
ReturnYouTubeDislikes.newVideoLoaded(videoId); 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;
}
} }