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

Commit

Permalink
fix: some more refactoring and cleanup (#21)
Browse files Browse the repository at this point in the history
* refactor: integrations and prepare new patches

* bugfixes

* fix critical bug

* prepare BrandingWaterMark patch

* fixing create button

* dont use Strings in ReVancedSettingsFragment when we have a wonderful enum for that

* rename classes from fenster to Swipe

* push

* exclude android packages from build
  • Loading branch information
TheJeterLP authored Jun 27, 2022
1 parent 0938f6c commit 9b1dce4
Show file tree
Hide file tree
Showing 47 changed files with 990 additions and 1,227 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
}

dependencies {
implementation 'androidx.annotation:annotation:1.3.0'
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
compileOnly 'androidx.annotation:annotation:1.3.0'
compileOnly 'androidx.constraintlayout:constraintlayout:2.1.4'
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public static void HideViewWithLayout1dp(View view) {
* @param view
*/
public static void hideCreateButton(View view) {
String message = SettingsEnum.CREATE_BUTTON_SHOWN_BOOLEAN.getBoolean() ? "Create button: shown" : "Create button: hidden";
String message = SettingsEnum.CREATE_BUTTON_SHOWN_BOOLEAN.getBoolean() ? "Create button: Shown" : "Create button: Hidden";
LogHelper.debug("HideCreateButton", message);
if (!SettingsEnum.CREATE_BUTTON_SHOWN_BOOLEAN.getBoolean()) {
view.setVisibility(View.GONE);
} else {
if (SettingsEnum.CREATE_BUTTON_SHOWN_BOOLEAN.getBoolean()) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import androidx.annotation.RequiresApi;

import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand All @@ -15,12 +13,12 @@

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;
import app.revanced.integrations.settings.Settings;

public class LithoAdRemoval {
private static boolean getBoolean(String key, boolean _default) {
return SharedPrefHelper.getBoolean(Objects.requireNonNull(YouTubeTikTokRoot_Application.getAppContext()), SharedPrefHelper.SharedPrefNames.YOUTUBE, key, _default);
return SharedPrefHelper.getBoolean(Objects.requireNonNull(ReVancedUtils.getContext()), SharedPrefHelper.SharedPrefNames.YOUTUBE, key, _default);
}

private static boolean isExperimentalInfoPanelRemoval() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import android.widget.Toast;

import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -22,16 +20,16 @@

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.settings.Settings;
import app.revanced.integrations.sponsorblock.player.ChannelModel;
import app.revanced.integrations.sponsorblock.player.VideoInformation;
import app.revanced.integrations.utils.ObjectSerializer;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;

public class Whitelist {
private static final String TAG = "VI - Whitelisting";
private static final Map<WhitelistType, ArrayList<ChannelModel>> whitelistMap = parseWhitelist(YouTubeTikTokRoot_Application.getAppContext());
private static final Map<WhitelistType, Boolean> enabledMap = parseEnabledMap(YouTubeTikTokRoot_Application.getAppContext());
private static final Map<WhitelistType, ArrayList<ChannelModel>> whitelistMap = parseWhitelist(ReVancedUtils.getContext());
private static final Map<WhitelistType, Boolean> enabledMap = parseEnabledMap(ReVancedUtils.getContext());

private Whitelist() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import android.content.Context;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
Expand All @@ -17,7 +19,6 @@
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;

import app.revanced.integrations.settings.Settings;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.sponsorblock.player.ChannelModel;
import app.revanced.integrations.adremover.whitelist.Whitelist;
Expand All @@ -38,7 +39,7 @@ public static void addChannelToWhitelist(WhitelistType whitelistType, View view,
connection.setDoOutput(true);
connection.setConnectTimeout(2 * 1000);

String versionName = Settings.getVersionName(context);
String versionName = getVersionName(context);
String jsonInputString = "{\"context\": {\"client\": { \"clientName\": \"Android\", \"clientVersion\": \"" + versionName + "\" } }, \"videoId\": \"" + currentVideoId + "\"}";
try (OutputStream os = connection.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
Expand Down Expand Up @@ -88,4 +89,15 @@ private static HttpURLConnection getConnectionFromRoute(Route route, String... p
private static JSONObject getJSONObject(HttpURLConnection connection) throws Exception {
return Requester.getJSONObject(connection);
}

private static String getVersionName(Context context) {
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String version = pInfo.versionName;
return (version);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return ("17.24.34");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;

public class AutoRepeatPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1hLl71Mm3oAtgTjNvsYZi3CUutCPx2gjS/view?usp=sharing for where it needs to be used.
public static boolean shouldAutoRepeat() {
return SettingsEnum.PREFERRED_AUTO_REPEAT_BOOLEAN.getBoolean();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.adremover.AdRemoverAPI;
import app.revanced.integrations.settings.SettingsEnum;

public class BrandingWaterMarkPatch {

//Used by: app.revanced.patches.youtube.layout.watermark.patch.HideWatermarkPatch
public static boolean isBrandingWatermarkShown() {
return SettingsEnum.BRANDING_SHOWN_BOOLEAN.getBoolean();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.videoswipecontrols.helpers.BrightnessHelper;

public class HDRMaxBrightnessPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1rIJzsaMQouH_2__EcVY5Dg6l7ji9vsyP/view?usp=sharing for where it needs to be used.
public static float getHDRBrightness(float original) {
if (!SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getBoolean()) return original;
return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean() ? BrightnessHelper.getBrightness() : -1.0f;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;

public class MiniplayerOverridePatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1G7jn2EdWgNls0Htgs-wPPjjObZL1emzK/view?usp=sharing
//And https://drive.google.com/file/d/1-QlgSiKzqQ5lHXQnvRUpijk0GH9T1Sn7/view?usp=sharing
// for where it needs to be used.
public static boolean getTabletMiniplayerOverride() {
return SettingsEnum.USE_TABLET_MINIPLAYER_BOOLEAN.getBoolean();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;

public class NewActionbarPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1Jg2WK9wwSABCiIcqclzhedy3J3RCf3Hn/view?usp=sharing for where it needs to be used.
public static boolean getNewActionBar() {
return SettingsEnum.USE_NEW_ACTIONBAR_BOOLEAN.getBoolean();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;

public class OverrideCodecPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/14d2R-5JF97gOZggoobVEVazPWbORbZVp/view?usp=sharing for where it needs to be used.
public static boolean isOverrideCodedUsed() {
return SettingsEnum.CODEC_OVERRIDE_BOOLEAN.getBoolean();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.settings.SettingsEnum;

public class VideoBufferPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1LSZZX4NgBIlN0dDCzyI7cECtgbXVg_1j/view?usp=sharing for where it needs to be used.
public static int getMaxBuffer(int original) {
return SettingsEnum.MAX_BUFFER_INTEGER.getInt();
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1gIUqPIMq-XP-edT_9wQN1RbmVnk9tJN8/view?usp=sharing for where it needs to be used.
public static int getPlaybackBuffer(int original) {
return SettingsEnum.PLAYBACK_MAX_BUFFER_INTEGER.getInt();
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1ywL7SxvWrBIIbuZ1YoUIKdZM-U8H_w-p/view?usp=sharing for where it needs to be used.
public static int getReBuffer(int original) {
return SettingsEnum.MAX_PLAYBACK_BUFFER_AFTER_REBUFFER_INTEGER.getInt();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.integrations.patches;

import app.revanced.integrations.videoplayer.videosettings.VideoQuality;

public class VideoQualityPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1goodaU0JWrO9BAOUn6El-Id1SNuMGHR9/view?usp=sharing for where it needs to be used.
public static int setVideoQuality(Object[] qualities, int quality, Object qInterface) {
return VideoQuality.setVideoQuality(qualities, quality, qInterface);
}

//See https://drive.google.com/file/d/1_cgCf603XKk4gEbbsmWGtndNt5UJ0np7/view?usp=sharing for usage
public static void userChangedQuality() {
VideoQuality.userChangedQuality();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package app.revanced.integrations.patches;

import android.content.Context;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.view.ViewGroup;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.sponsorblock.player.PlayerType;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SwipeHelper;
import app.revanced.integrations.videoswipecontrols.SwipeControlAPI;

public class VideoSwipeControlsPatch {

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1FTPRrp6NcIF5LC_ByST1a0wcNoGKcAYS/view?usp=sharing for where it needs to be used.
public static void InitializeFensterController(Context context, ViewGroup viewGroup, ViewConfiguration viewConfiguration) {
SwipeControlAPI.InitializeFensterController(context, viewGroup, viewConfiguration);
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1Q9TIDDKvc-nQuJWLmCh7jx3ohxPdFIrZ/view?usp=sharing
//And https://drive.google.com/file/d/1byP5SItks9MYB3fDVC39xH_6nBbaH9NY/view?usp=sharing
// for where it needs to be used.
public static boolean FensterTouchEvent(MotionEvent motionEvent) {
return SwipeControlAPI.FensterTouchEvent(motionEvent);
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1qKmaX4yzAjzYM6T5uUiRtbMxk2zJlwtd/view?usp=sharing for where it needs to be used.
public static boolean isSwipeControlBrightnessEnabled() {
return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean();
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1TMQxs0ul2_p5_GomE-3J1QWO__M189Da/view?usp=sharing for where it needs to be used.
public static void PlayerTypeChanged(PlayerType playerType) {
SwipeControlAPI.PlayerTypeChanged(playerType);
}

//ToDo: Write Patch for it.
//See https://drive.google.com/file/d/1EoVAyqWOMGUDCovuDb27yeQJBk_CyKsY/view?usp=sharing for where it needs to be used.
public static boolean isSwipeControlEnabled() {
if (ReVancedUtils.getPlayerType() != null && ReVancedUtils.getPlayerType() == PlayerType.WATCH_WHILE_FULLSCREEN && !SwipeHelper.IsControlsShown()) {
return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean() || SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.getBoolean();
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import android.view.View;
import android.widget.TextView;

import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;

import java.util.Locale;
import java.util.Objects;

import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.ryd.requests.RYDRequester;
import app.revanced.integrations.utils.ReVancedUtils;
import app.revanced.integrations.utils.SharedPrefHelper;

public class ReturnYouTubeDislikes {
Expand All @@ -34,7 +33,7 @@ public class ReturnYouTubeDislikes {
private static CompactDecimalFormat compactNumberFormatter;

static {
Context context = YouTubeTikTokRoot_Application.getAppContext();
Context context = ReVancedUtils.getContext();
isEnabled = SharedPrefHelper.getBoolean(Objects.requireNonNull(context), SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_RYD_ENABLED, false);
if (isEnabled) {
registration = new Registration(context);
Expand All @@ -54,10 +53,10 @@ public class ReturnYouTubeDislikes {
public static void onEnabledChange(boolean enabled) {
isEnabled = enabled;
if (registration == null) {
registration = new Registration(YouTubeTikTokRoot_Application.getAppContext());
registration = new Registration(ReVancedUtils.getContext());
}
if (voting == null) {
voting = new Voting(YouTubeTikTokRoot_Application.getAppContext(), registration);
voting = new Voting(ReVancedUtils.getContext(), registration);
}
}

Expand Down Expand Up @@ -176,7 +175,7 @@ public static void trySetDislikes(String dislikeCount) {
}

private static void handleOnClick(View view, boolean previousState) {
Context context = YouTubeTikTokRoot_Application.getAppContext();
Context context = ReVancedUtils.getContext();
if (!isEnabled || SharedPrefHelper.getBoolean(Objects.requireNonNull(context), SharedPrefHelper.SharedPrefNames.YOUTUBE, "user_signed_out", true))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import android.net.Uri;
import android.os.Build;

import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;

import app.revanced.integrations.utils.SharedPrefHelper;
import app.revanced.integrations.utils.ReVancedUtils;

Expand All @@ -28,7 +26,7 @@ public static void showDialogsAtStartup(Activity activity) {
}

private static void rydFirstRun(Activity activity) {
Context context = YouTubeTikTokRoot_Application.getAppContext();
Context context = ReVancedUtils.getContext();
boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_RYD_ENABLED, false);
boolean hintShown = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_RYD_HINT_SHOWN, false);

Expand Down Expand Up @@ -82,7 +80,7 @@ private static void rydFirstRun(Activity activity) {
}

private static void sbFirstRun(Activity activity) {
Context context = YouTubeTikTokRoot_Application.getAppContext();
Context context = ReVancedUtils.getContext();
boolean enabled = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_ENABLED, false);
boolean hintShown = SharedPrefHelper.getBoolean(context, SharedPrefHelper.SharedPrefNames.RYD, PREFERENCES_KEY_SPONSOR_BLOCK_HINT_SHOWN, false);

Expand Down
Loading

0 comments on commit 9b1dce4

Please sign in to comment.