Skip to content

Commit

Permalink
Merge branch 'dev' into revanced-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jan 22, 2025
2 parents 8db38af + eb24578 commit 9146d92
Show file tree
Hide file tree
Showing 213 changed files with 6,526 additions and 2,364 deletions.
99 changes: 51 additions & 48 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@
import android.widget.ImageView;

import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.shared.utils.ResourceUtils;

/**
* @noinspection ALL
*/
@SuppressWarnings("unused")
public class GeneralPatch {

// region [Change header] patch

public static int getHeaderDrawableId(int original) {
final int headerId = ResourceUtils.getDrawableIdentifier("action_bar_logo");

return headerId == 0
? original
: headerId;
}

// endregion

// region [Change start page] patch

public static String changeStartPage(final String browseId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.music.shared.VideoInformation;
import app.revanced.extension.music.utils.VideoUtils;
import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.Utils;

@SuppressWarnings("unused")
public class AlbumMusicVideoPatch {
Expand Down Expand Up @@ -98,8 +100,17 @@ private static void checkVideo(@NonNull String videoId) {
if (request == null) {
return;
}
// This hook is always called off the main thread,
// but this can later be called for the same video id from the main thread.
// This is not a concern, since the fetch will always be finished
// and never block the main thread.
// But if debugging, then still verify this is the situation.
if (BaseSettings.ENABLE_DEBUG_LOGGING.get() && !request.fetchCompleted() && Utils.isCurrentlyOnMainThread()) {
Logger.printException(() -> "Error: Blocking main thread");
}
String songId = request.getStream();
if (songId == null) {
Logger.printDebug(() -> "Official song not found, videoId: " + videoId);
return;
}
synchronized (lastVideoIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -25,38 +24,21 @@
import app.revanced.extension.shared.utils.Utils;

public class PipedRequester {
/**
* How long to keep fetches until they are expired.
*/
private static final long CACHE_RETENTION_TIME_MILLISECONDS = 60 * 1000; // 1 Minute

private static final long MAX_MILLISECONDS_TO_WAIT_FOR_FETCH = 20 * 1000; // 20 seconds
private static final long MAX_MILLISECONDS_TO_WAIT_FOR_FETCH = 4 * 1000; // 4 seconds

@GuardedBy("itself")
private static final Map<String, PipedRequester> cache = new HashMap<>();
private static final Map<String, PipedRequester> cache = new LinkedHashMap<>() {
private static final int NUMBER_OF_LAST_VIDEO_IDS_TO_TRACK = 10;

@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > NUMBER_OF_LAST_VIDEO_IDS_TO_TRACK;
}
};

@SuppressLint("ObsoleteSdkInt")
public static void fetchRequestIfNeeded(@NonNull String videoId, @NonNull String playlistId, final int playlistIndex) {
synchronized (cache) {
final long now = System.currentTimeMillis();

if (Utils.isSDKAbove(25)) {
cache.values().removeIf(request -> {
final boolean expired = request.isExpired(now);
if (expired) Logger.printDebug(() -> "Removing expired stream: " + request.videoId);
return expired;
});
} else {
Iterator<Map.Entry<String, PipedRequester>> itr = cache.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, PipedRequester> entry = itr.next();
if (entry.getValue().isExpired(now)) {
Logger.printDebug(() -> "Removing expired fetch: " + entry.getValue().videoId);
itr.remove();
}
}
}

if (!cache.containsKey(videoId)) {
PipedRequester pipedRequester = new PipedRequester(videoId, playlistId, playlistIndex);
cache.put(videoId, pipedRequester);
Expand Down Expand Up @@ -85,7 +67,7 @@ public static PipedRequester getRequestForVideoId(@Nullable String videoId) {
private static JSONObject send(@NonNull String videoId, @NonNull String playlistId, final int playlistIndex) {
final long startTime = System.currentTimeMillis();
Logger.printDebug(() -> "Fetching piped instances (videoId: '" + videoId +
"', playlistId: '" + playlistId + "', playlistIndex: '" + playlistIndex + "'");
"', playlistId: '" + playlistId + "', playlistIndex: '" + playlistIndex + "')");

try {
HttpURLConnection connection = PipedRoutes.getPlaylistConnectionFromRoute(playlistId);
Expand Down Expand Up @@ -121,6 +103,8 @@ private static String fetch(@NonNull String videoId, @NonNull String playlistId,
if (songId.isEmpty()) {
handleConnectionError("Url is empty!");
} else if (!songId.equals(videoId)) {
Logger.printDebug(() -> "Video found (videoId: '" + videoId +
"', songId: '" + songId + "')");
return songId;
}
} catch (JSONException e) {
Expand All @@ -145,26 +129,12 @@ private static void handleConnectionError(@NonNull String errorMessage, @Nullabl
/**
* Time this instance and the fetch future was created.
*/
private final long timeFetched;
private final String videoId;
private final Future<String> future;

private PipedRequester(@NonNull String videoId, @NonNull String playlistId, final int playlistIndex) {
this.timeFetched = System.currentTimeMillis();
this.videoId = videoId;
this.future = Utils.submitOnBackgroundThread(() -> fetch(videoId, playlistId, playlistIndex));
}

public boolean isExpired(long now) {
final long timeSinceCreation = now - timeFetched;
if (timeSinceCreation > CACHE_RETENTION_TIME_MILLISECONDS) {
return true;
}

// Only expired if the fetch failed (API null response).
return (fetchCompleted() && getStream() == null);
}

/**
* @return if the fetch call has completed.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.extension.music.patches.navigation;

import static app.revanced.extension.shared.utils.StringRef.str;
import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;

import android.graphics.Color;
Expand All @@ -11,6 +12,7 @@
import app.revanced.extension.music.patches.utils.PatchStatus;
import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.shared.utils.ResourceUtils;
import app.revanced.extension.shared.utils.Utils;

@SuppressWarnings("unused")
public class NavigationPatch {
Expand All @@ -20,10 +22,18 @@ public class NavigationPatch {

public static Enum<?> lastPivotTab;

public static int enableBlackNavigationBar() {
return Settings.ENABLE_BLACK_NAVIGATION_BAR.get()
? Color.BLACK
: colorGrey12;
public static int enableCustomNavigationBarColor() {
try {
if (Settings.ENABLE_CUSTOM_NAVIGATION_BAR_COLOR.get()) {
return Color.parseColor(Settings.ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE.get());
}
} catch (Exception ex) {
Utils.showToastShort(str("revanced_custom_navigation_bar_color_value_invalid_invalid_toast"));
Utils.showToastShort(str("revanced_extended_reset_to_default_toast"));
Settings.ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE.resetToDefault();
}

return colorGrey12;
}

public static void hideNavigationLabel(TextView textview) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

@SuppressWarnings("unused")
public class DrawableColorPatch {
private static final int[] DARK_VALUES = {
-14606047, // comments box background
-16579837, // button container background in album
-16777216, // button container background in playlist
private static final int[] DARK_COLORS = {
0xFF212121, // comments box background
0xFF030303, // button container background in album
0xFF000000, // button container background in playlist
};

// background colors
Expand All @@ -26,10 +26,10 @@ public class DrawableColorPatch {
private static final int elementsContainerIdentifier =
ResourceUtils.getIdIdentifier("elements_container");

public static int getLithoColor(int originalValue) {
return ArrayUtils.contains(DARK_VALUES, originalValue)
public static int getLithoColor(int colorValue) {
return ArrayUtils.contains(DARK_COLORS, colorValue)
? blackColor
: originalValue;
: colorValue;
}

public static void setHeaderGradient(ViewGroup viewGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public class Settings extends BaseSettings {
PatchStatus.SpoofAppVersionDefaultString(), true);


// PreferenceScreen: Navigation bar
public static final BooleanSetting ENABLE_BLACK_NAVIGATION_BAR = new BooleanSetting("revanced_enable_black_navigation_bar", FALSE);
// PreferenceScreen: Navigation Bar
public static final BooleanSetting ENABLE_CUSTOM_NAVIGATION_BAR_COLOR = new BooleanSetting("revanced_enable_custom_navigation_bar_color", FALSE, true);
public static final StringSetting ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE = new StringSetting("revanced_custom_navigation_bar_color_value", "#000000", true);
public static final BooleanSetting HIDE_NAVIGATION_HOME_BUTTON = new BooleanSetting("revanced_hide_navigation_home_button", FALSE, true);
public static final BooleanSetting HIDE_NAVIGATION_SAMPLES_BUTTON = new BooleanSetting("revanced_hide_navigation_samples_button", FALSE, true);
public static final BooleanSetting HIDE_NAVIGATION_EXPLORE_BUTTON = new BooleanSetting("revanced_hide_navigation_explore_button", FALSE, true);
Expand Down Expand Up @@ -251,6 +252,7 @@ public class Settings extends BaseSettings {
CUSTOM_FILTER_STRINGS.key,
CUSTOM_PLAYBACK_SPEEDS.key,
DISABLE_MUSIC_VIDEO_IN_ALBUM_REDIRECT_TYPE.key,
ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE.key,
EXTERNAL_DOWNLOADER_PACKAGE_NAME.key,
HIDE_ACCOUNT_MENU_FILTER_STRINGS.key,
SB_API_URL.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static app.revanced.extension.music.settings.Settings.CUSTOM_FILTER_STRINGS;
import static app.revanced.extension.music.settings.Settings.CUSTOM_PLAYBACK_SPEEDS;
import static app.revanced.extension.music.settings.Settings.DISABLE_MUSIC_VIDEO_IN_ALBUM_REDIRECT_TYPE;
import static app.revanced.extension.music.settings.Settings.ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE;
import static app.revanced.extension.music.settings.Settings.EXTERNAL_DOWNLOADER_PACKAGE_NAME;
import static app.revanced.extension.music.settings.Settings.HIDE_ACCOUNT_MENU_FILTER_STRINGS;
import static app.revanced.extension.music.settings.Settings.OPEN_DEFAULT_APP_SETTINGS;
Expand Down Expand Up @@ -140,6 +141,7 @@ public void onCreate(Bundle savedInstanceState) {
} else if (settings.equals(BYPASS_IMAGE_REGION_RESTRICTIONS_DOMAIN)
|| settings.equals(CUSTOM_FILTER_STRINGS)
|| settings.equals(CUSTOM_PLAYBACK_SPEEDS)
|| settings.equals(ENABLE_CUSTOM_NAVIGATION_BAR_COLOR_VALUE)
|| settings.equals(HIDE_ACCOUNT_MENU_FILTER_STRINGS)
|| settings.equals(RETURN_YOUTUBE_USERNAME_YOUTUBE_DATA_API_V3_DEVELOPER_KEY)) {
ResettableEditTextPreference.showDialog(mActivity, stringSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import androidx.annotation.NonNull;

import app.revanced.extension.reddit.settings.Settings;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.Utils;

@SuppressWarnings("unused")
Expand All @@ -31,20 +30,12 @@ public static void dismissDialog(View cancelButtonView) {
clickViewDelayed(cancelButtonView);
}

public static void dismissDialogV2(Object object) {
if (!Settings.REMOVE_NOTIFICATION_DIALOG.get())
return;

Utils.runOnMainThreadDelayed(() -> {
try {
dismissRedditDialogV2(object);
} catch (Exception ex) {
Logger.printException(() -> "dismissDialogV2 failed", ex);
}
}, 0);
public static boolean spoofHasBeenVisitedStatus(boolean hasBeenVisited) {
return Settings.REMOVE_NSFW_DIALOG.get() || hasBeenVisited;
}

private static void dismissRedditDialogV2(Object object) {
public static boolean spoofLoggedInStatus(boolean isLoggedIn) {
return !Settings.REMOVE_NOTIFICATION_DIALOG.get() && isLoggedIn;
}

private static void clickViewDelayed(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void addPreferences(Context context) {
addPreference(new TogglePreference(
context,
"Sanitize sharing links",
"Removes tracking query parameters from URLs when sharing links.",
"Sanitizes sharing links by removing tracking query parameters.",
Settings.SANITIZE_URL_QUERY
));
}
Expand Down
Loading

0 comments on commit 9146d92

Please sign in to comment.