Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

feat(YouTube - Alternative Thumbnails): Add option to use DeArrow #534

Merged
merged 39 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fca67db
add dearrow option to alternative thumbnails
shadow578 Dec 5, 2023
78a5323
Merge branch 'dev' into add/dearrow-alt-thumbnail
oSumAtrIX Dec 5, 2023
25fa498
refactor & fix strings
oSumAtrIX Dec 5, 2023
424a76d
prevent network call if possible
oSumAtrIX Dec 5, 2023
8029a32
refactor
oSumAtrIX Dec 5, 2023
aaaaa95
restart if api url changes
oSumAtrIX Dec 5, 2023
a935fe3
improve wording
oSumAtrIX Dec 5, 2023
57f2bf9
Handle if a thumbnail fails to load when using both fast still and De…
LisoUseInAIKyrios Dec 5, 2023
6f8c6f7
- Handle DeArrow connection errors.
LisoUseInAIKyrios Dec 5, 2023
be0301c
comments, rename setting path
LisoUseInAIKyrios Dec 5, 2023
67a8067
adjust logging
LisoUseInAIKyrios Dec 5, 2023
19559f9
refactor
LisoUseInAIKyrios Dec 5, 2023
bd51f08
Use background thread to send dummy calls for view tracking. This ma…
LisoUseInAIKyrios Dec 5, 2023
0b404c6
Revert "Use background thread to send dummy calls for view tracking. …
LisoUseInAIKyrios Dec 5, 2023
efe12e9
refactor
LisoUseInAIKyrios Dec 5, 2023
b1fd216
don't back off API if non DeArrow error happens
LisoUseInAIKyrios Dec 6, 2023
8881daa
fix logic, cleanup
LisoUseInAIKyrios Dec 6, 2023
224fda7
Use dynamically updated about summary
LisoUseInAIKyrios Dec 6, 2023
bff6bf7
DeArrow toast option.
LisoUseInAIKyrios Dec 6, 2023
3ffe4dd
fixing oversight. The request url is not the same as the response if …
LisoUseInAIKyrios Dec 6, 2023
054d7ff
fix logging, comments, cleanup
LisoUseInAIKyrios Dec 7, 2023
b9172b8
Prevent DeArrow 502 status error when it tries to fetch a storyboard …
LisoUseInAIKyrios Dec 7, 2023
1047372
Adjust backoff and use api timeout for toast backoff as well.
LisoUseInAIKyrios Dec 7, 2023
e87e344
Use separate about section for each thumbnail type.
LisoUseInAIKyrios Dec 7, 2023
5ad69e2
custom thumbnails can be any kind of image. Replace them if found.
LisoUseInAIKyrios Dec 8, 2023
f28ef9c
simplify logic
LisoUseInAIKyrios Dec 8, 2023
8ae7aab
cleanup
LisoUseInAIKyrios Dec 8, 2023
9e4d137
null check is not needed
LisoUseInAIKyrios Dec 8, 2023
a5bd27d
adjust setting name
LisoUseInAIKyrios Dec 8, 2023
9b7a663
more complex check is needed
LisoUseInAIKyrios Dec 8, 2023
b988a87
fixing strings
LisoUseInAIKyrios Dec 8, 2023
bbe423b
logging, comments
LisoUseInAIKyrios Dec 8, 2023
3b8a486
use new method
LisoUseInAIKyrios Dec 8, 2023
b719017
Include status code with the toast
LisoUseInAIKyrios Dec 9, 2023
fc56d52
cleanup
LisoUseInAIKyrios Dec 9, 2023
a9f8695
Merge branch 'dev' into add/dearrow-alt-thumbnail
LisoUseInAIKyrios Dec 9, 2023
20fc977
refactor: Use initializer block
oSumAtrIX Dec 10, 2023
b839cda
chore: Remove unnecessary query parameter
oSumAtrIX Dec 10, 2023
9e3fa47
chore: Fix typos
oSumAtrIX Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void showAnnouncement(final Activity context) {
if (connection.getResponseCode() != 200) {
if (SettingsEnum.ANNOUNCEMENT_LAST_HASH.getString().isEmpty()) return;

SettingsEnum.ANNOUNCEMENT_LAST_HASH.saveValue("");
SettingsEnum.ANNOUNCEMENT_LAST_HASH.resetToDefault();
ReVancedUtils.showToastLong("Failed to get announcement");

return;
Expand Down Expand Up @@ -118,7 +118,7 @@ public static void showAnnouncement(final Activity context) {
*/
private static boolean emptyLastAnnouncementHash() {
if (SettingsEnum.ANNOUNCEMENT_LAST_HASH.getString().isEmpty()) return true;
SettingsEnum.ANNOUNCEMENT_LAST_HASH.saveValue("");
SettingsEnum.ANNOUNCEMENT_LAST_HASH.resetToDefault();

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static String[] getFilterPatterns(SettingsEnum setting) {
for (String pattern : patterns) {
if (!StringTrieSearch.isValidPattern(pattern)) {
ReVancedUtils.showToastLong("Invalid custom filter, resetting to default");
setting.saveValue(setting.defaultValue);
setting.resetToDefault();
return getFilterPatterns(setting);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CustomPlaybackSpeedPatch {

private static void resetCustomSpeeds(@NonNull String toastMessage) {
ReVancedUtils.showToastLong(toastMessage);
SettingsEnum.CUSTOM_PLAYBACK_SPEEDS.saveValue(SettingsEnum.CUSTOM_PLAYBACK_SPEEDS.defaultValue);
SettingsEnum.CUSTOM_PLAYBACK_SPEEDS.resetToDefault();
}

private static void loadCustomSpeeds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void loadCustomSeekbarColor() {
Color.colorToHSV(seekbarColor, customSeekbarColorHSV);
} catch (Exception ex) {
ReVancedUtils.showToastShort("Invalid seekbar color value. Using default value.");
SettingsEnum.SEEKBAR_CUSTOM_COLOR_VALUE.saveValue(SettingsEnum.SEEKBAR_CUSTOM_COLOR_VALUE.defaultValue);
SettingsEnum.SEEKBAR_CUSTOM_COLOR_VALUE.resetToDefault();
loadCustomSeekbarColor();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ public enum SettingsEnum {
HIDE_WEB_SEARCH_RESULTS("revanced_hide_web_search_results", BOOLEAN, TRUE),

// Layout
ALT_THUMBNAIL("revanced_alt_thumbnail", BOOLEAN, FALSE),
ALT_THUMBNAIL_TYPE("revanced_alt_thumbnail_type", INTEGER, 2, parents(ALT_THUMBNAIL)),
ALT_THUMBNAIL_FAST_QUALITY("revanced_alt_thumbnail_fast_quality", BOOLEAN, FALSE, parents(ALT_THUMBNAIL)),
ALT_THUMBNAIL_STILLS("revanced_alt_thumbnail_stills", BOOLEAN, FALSE),
ALT_THUMBNAIL_STILLS_TIME("revanced_alt_thumbnail_stills_time", INTEGER, 2, parents(ALT_THUMBNAIL_STILLS)),
ALT_THUMBNAIL_STILLS_FAST("revanced_alt_thumbnail_stills_fast", BOOLEAN, FALSE, parents(ALT_THUMBNAIL_STILLS)),
ALT_THUMBNAIL_DEARROW("revanced_alt_thumbnail_dearrow", BOOLEAN, false),
ALT_THUMBNAIL_DEARROW_API_URL("revanced_alt_thumbnail_dearrow_api_url", STRING,
"https://dearrow-thumb.ajay.app/api/v1/getThumbnail", true, parents(ALT_THUMBNAIL_DEARROW)),
ALT_THUMBNAIL_DEARROW_CONNECTION_TOAST("revanced_alt_thumbnail_dearrow_connection_toast", BOOLEAN, TRUE, parents(ALT_THUMBNAIL_DEARROW)),
CUSTOM_FILTER("revanced_custom_filter", BOOLEAN, FALSE),
CUSTOM_FILTER_STRINGS("revanced_custom_filter_strings", STRING, "", true, parents(CUSTOM_FILTER)),
DISABLE_FULLSCREEN_AMBIENT_MODE("revanced_disable_fullscreen_ambient_mode", BOOLEAN, TRUE, true),
Expand Down Expand Up @@ -430,7 +434,7 @@ private static void migrateOldSettingToNew(SettingsEnum oldSetting, SettingsEnum
LogHelper.printInfo(() -> "Migrating old setting of '" + oldSetting.value
+ "' from: " + oldSetting + " into replacement setting: " + newSetting);
newSetting.saveValue(oldSetting.value);
oldSetting.saveValue(oldSetting.defaultValue); // reset old value
oldSetting.resetToDefault();
}
}

Expand Down Expand Up @@ -522,6 +526,13 @@ public void saveValue(@NonNull Object newValue) {
}
}

/**
* Identical to calling {@link #saveValue(Object)} using {@link #defaultValue}.
*/
public void resetToDefault() {
saveValue(defaultValue);
}

/**
* @return if this setting can be configured and used.
* <p>
Expand Down Expand Up @@ -694,7 +705,7 @@ public static boolean importJSON(@NonNull String settingsJsonString) {
} else if (setting.includeWithImportExport() && !setting.isSetToDefault()) {
LogHelper.printDebug(() -> "Resetting to default: " + setting);
rebootSettingChanged |= setting.rebootApp;
setting.saveValue(setting.defaultValue);
setting.resetToDefault();
}
}
numberOfSettingsImported += SponsorBlockSettings.importCategoriesFromFlatJson(json);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package app.revanced.integrations.settingsmenu;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.preference.Preference;
import android.util.AttributeSet;

/**
* Allows tapping the DeArrow about preference to open the DeArrow website.
*/
@SuppressWarnings("unused")
public class AlternativeThumbnailsAboutDeArrowPreference extends Preference {

private void init() {
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved
setOnPreferenceClickListener(pref -> {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://dearrow.ajay.app"));
pref.getContext().startActivity(i);
return false;
});
}

public AlternativeThumbnailsAboutDeArrowPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
public AlternativeThumbnailsAboutDeArrowPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public AlternativeThumbnailsAboutDeArrowPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public AlternativeThumbnailsAboutDeArrowPreference(Context context) {
super(context);
init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package app.revanced.integrations.settingsmenu;

import static app.revanced.integrations.utils.StringRef.str;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.settings.SharedPrefCategory;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;

/**
* Shows what thumbnails will be used based on the current settings.
*/
@SuppressWarnings("unused")
public class AlternativeThumbnailsStatusPreference extends Preference {

private final SharedPreferences.OnSharedPreferenceChangeListener listener = (sharedPreferences, str) -> {
// Because this listener may run before the ReVanced settings fragment updates SettingsEnum,
// this could show the prior config and not the current.
//
// Push this call to the end of the main run queue,
// so all other listeners are done and SettingsEnum is up to date.
ReVancedUtils.runOnMainThread(this::updateUI);
};

public AlternativeThumbnailsStatusPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public AlternativeThumbnailsStatusPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public AlternativeThumbnailsStatusPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlternativeThumbnailsStatusPreference(Context context) {
super(context);
}

private void addChangeListener() {
LogHelper.printDebug(() -> "addChangeListener");
SharedPrefCategory.YOUTUBE.preferences.registerOnSharedPreferenceChangeListener(listener);
}

private void removeChangeListener() {
LogHelper.printDebug(() -> "removeChangeListener");
SharedPrefCategory.YOUTUBE.preferences.unregisterOnSharedPreferenceChangeListener(listener);
}

@Override
protected void onAttachedToHierarchy(PreferenceManager preferenceManager) {
super.onAttachedToHierarchy(preferenceManager);
updateUI();
addChangeListener();
}

@Override
protected void onPrepareForRemoval() {
super.onPrepareForRemoval();
removeChangeListener();
}

private void updateUI() {
LogHelper.printDebug(() -> "updateUI");
final boolean usingDeArrow = SettingsEnum.ALT_THUMBNAIL_DEARROW.getBoolean();
final boolean usingVideoStills = SettingsEnum.ALT_THUMBNAIL_STILLS.getBoolean();

final String summaryTextKey;
if (usingDeArrow && usingVideoStills) {
summaryTextKey = "revanced_alt_thumbnail_about_status_dearrow_stills";
} else if (usingDeArrow) {
summaryTextKey = "revanced_alt_thumbnail_about_status_dearrow";
} else if (usingVideoStills) {
summaryTextKey = "revanced_alt_thumbnail_about_status_stills";
} else {
summaryTextKey = "revanced_alt_thumbnail_about_status_disabled";
}

setSummary(str(summaryTextKey));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void addGeneralCategory(final Context context, PreferenceScreen screen)

DialogInterface.OnClickListener urlChangeListener = (dialog, buttonPressed) -> {
if (buttonPressed == DialogInterface.BUTTON_NEUTRAL) {
SettingsEnum.SB_API_URL.saveValue(SettingsEnum.SB_API_URL.defaultValue);
SettingsEnum.SB_API_URL.resetToDefault();
ReVancedUtils.showToastLong(str("sb_api_url_reset"));
} else if (buttonPressed == DialogInterface.BUTTON_POSITIVE) {
String serverAddress = editText.getText().toString();
Expand Down Expand Up @@ -583,8 +583,8 @@ private void addLocalUserStats() {
new AlertDialog.Builder(preference1.getContext())
.setTitle(str("sb_stats_self_saved_reset_title"))
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
SettingsEnum.SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS.saveValue(SettingsEnum.SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS.defaultValue);
SettingsEnum.SB_LOCAL_TIME_SAVED_MILLISECONDS.saveValue(SettingsEnum.SB_LOCAL_TIME_SAVED_MILLISECONDS.defaultValue);
SettingsEnum.SB_LOCAL_TIME_SAVED_NUMBER_SEGMENTS.resetToDefault();
SettingsEnum.SB_LOCAL_TIME_SAVED_MILLISECONDS.resetToDefault();
updateStatsSelfSaved.run();
})
.setNegativeButton(android.R.string.no, null).show();
Expand Down
4 changes: 4 additions & 0 deletions dummy/src/main/java/org/chromium/net/UrlRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.chromium.net;

public abstract class UrlRequest {
}
11 changes: 11 additions & 0 deletions dummy/src/main/java/org/chromium/net/impl/CronetUrlRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.chromium.net.impl;

import org.chromium.net.UrlRequest;

public abstract class CronetUrlRequest extends UrlRequest {

/**
* Method is added by patch.
*/
public abstract String getHookedUrl();
}