Skip to content

Commit

Permalink
chore: Remove obsolete code (#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios authored Oct 26, 2024
1 parent c7216fc commit c9787f5
Show file tree
Hide file tree
Showing 84 changed files with 211 additions and 770 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package app.revanced.extension.youtube.patches;

import static app.revanced.extension.youtube.returnyoutubedislike.ReturnYouTubeDislike.Vote;

import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable;
import android.os.Build;
import android.text.*;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.patches.components.ReturnYouTubeDislikeFilterPatch;
import app.revanced.extension.youtube.patches.spoof.SpoofAppVersionPatch;
import app.revanced.extension.youtube.returnyoutubedislike.ReturnYouTubeDislike;
import app.revanced.extension.youtube.returnyoutubedislike.requests.ReturnYouTubeDislikeApi;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static app.revanced.extension.youtube.returnyoutubedislike.ReturnYouTubeDislike.Vote;

/**
* Handles all interaction of UI patch components.
Expand Down Expand Up @@ -91,98 +94,6 @@ private static void clearData() {
// while a regular video is on screen.
}

//
// 17.x non litho regular video player.
//

/**
* Resource identifier of old UI dislike button.
*/
private static final int OLD_UI_DISLIKE_BUTTON_RESOURCE_ID
= Utils.getResourceIdentifier("dislike_button", "id");

/**
* Dislikes text label used by old UI.
*/
@NonNull
private static WeakReference<TextView> oldUITextViewRef = new WeakReference<>(null);

/**
* Original old UI 'Dislikes' text before patch modifications.
* Required to reset the dislikes when changing videos and RYD is not available.
* Set only once during the first load.
*/
private static Spanned oldUIOriginalSpan;

/**
* Replacement span that contains dislike value. Used by {@link #oldUiTextWatcher}.
*/
@Nullable
private static Spanned oldUIReplacementSpan;

/**
* Old UI dislikes can be set multiple times by YouTube.
* To prevent reverting changes made here, this listener overrides any future changes YouTube makes.
*/
private static final TextWatcher oldUiTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
public void afterTextChanged(Editable s) {
if (oldUIReplacementSpan == null || oldUIReplacementSpan.toString().equals(s.toString())) {
return;
}
s.replace(0, s.length(), oldUIReplacementSpan); // Causes a recursive call back into this listener
}
};

private static void updateOldUIDislikesTextView() {
ReturnYouTubeDislike videoData = currentVideoData;
if (videoData == null) {
return;
}
TextView oldUITextView = oldUITextViewRef.get();
if (oldUITextView == null) {
return;
}
oldUIReplacementSpan = videoData.getDislikesSpanForRegularVideo(oldUIOriginalSpan, false, false);
if (!oldUIReplacementSpan.equals(oldUITextView.getText())) {
oldUITextView.setText(oldUIReplacementSpan);
}
}

/**
* Injection point. Called on main thread.
*
* Used when spoofing to 16.x and 17.x versions.
*/
public static void setOldUILayoutDislikes(int buttonViewResourceId, @Nullable TextView textView) {
try {
if (!Settings.RYD_ENABLED.get()
|| buttonViewResourceId != OLD_UI_DISLIKE_BUTTON_RESOURCE_ID
|| textView == null) {
return;
}
Logger.printDebug(() -> "setOldUILayoutDislikes");

if (oldUIOriginalSpan == null) {
// Use value of the first instance, as it appears TextViews can be recycled
// and might contain dislikes previously added by the patch.
oldUIOriginalSpan = (Spanned) textView.getText();
}
oldUITextViewRef = new WeakReference<>(textView);
// No way to check if a listener is already attached, so remove and add again.
textView.removeTextChangedListener(oldUiTextWatcher);
textView.addTextChangedListener(oldUiTextWatcher);

updateOldUIDislikesTextView();

} catch (Exception ex) {
Logger.printException(() -> "setOldUILayoutDislikes failure", ex);
}
}


//
// Litho player for both regular videos and Shorts.
Expand Down Expand Up @@ -719,7 +630,6 @@ public static void sendVote(int vote) {
if (lastLithoShortsVideoData != null) {
lithoShortsShouldUseCurrentData = true;
}
updateOldUIDislikesTextView();
}

return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package app.revanced.extension.youtube.patches.announcements;

import static android.text.Html.FROM_HTML_MODE_COMPACT;
import static app.revanced.extension.shared.StringRef.str;
import static app.revanced.extension.youtube.patches.announcements.requests.AnnouncementsRoutes.GET_LATEST_ANNOUNCEMENT;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Build;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.patches.announcements.requests.AnnouncementsRoutes;
import app.revanced.extension.youtube.requests.Requester;
import app.revanced.extension.youtube.settings.Settings;
import org.json.JSONObject;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Locale;

import static android.text.Html.FROM_HTML_MODE_COMPACT;
import static app.revanced.extension.shared.StringRef.str;
import static app.revanced.extension.youtube.patches.announcements.requests.AnnouncementsRoutes.GET_LATEST_ANNOUNCEMENT;
import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.patches.announcements.requests.AnnouncementsRoutes;
import app.revanced.extension.youtube.requests.Requester;
import app.revanced.extension.youtube.settings.Settings;

@SuppressWarnings("unused")
public final class AnnouncementsPatch {
Expand Down Expand Up @@ -56,15 +56,12 @@ public static void showAnnouncement(final Activity context) {
return;
}
} catch (IOException ex) {
final var message = "Failed connecting to announcements provider";

Logger.printException(() -> message, ex);
Logger.printException(() -> "Could not connect to announcements provider", ex);
return;
}

var jsonString = Requester.parseStringAndDisconnect(connection);


// Parse the announcement. Fall-back to raw string if it fails.
int id = Settings.ANNOUNCEMENT_LAST_ID.defaultValue;
String title;
Expand All @@ -85,22 +82,6 @@ public static void showAnnouncement(final Activity context) {
message = jsonString;
}

// TODO: Remove this migration code after a few months.
if (!Settings.DEPRECATED_ANNOUNCEMENT_LAST_HASH.isSetToDefault()){
final byte[] hashBytes = MessageDigest
.getInstance("SHA-256")
.digest(jsonString.getBytes(StandardCharsets.UTF_8));

final var hash = java.util.Base64.getEncoder().encodeToString(hashBytes);

// Migrate to saving the id instead of the hash.
if (hash.equals(Settings.DEPRECATED_ANNOUNCEMENT_LAST_HASH.get())) {
Settings.ANNOUNCEMENT_LAST_ID.save(id);
}

Settings.DEPRECATED_ANNOUNCEMENT_LAST_HASH.resetToDefault();
}

// Do not show the announcement, if the last announcement id is the same as the current one.
if (Settings.ANNOUNCEMENT_LAST_ID.get() == id) return;

Expand Down
Loading

0 comments on commit c9787f5

Please sign in to comment.