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

Commit

Permalink
feat(YouTube - Shorts components): Add Enable timestamps, `Timestam…
Browse files Browse the repository at this point in the history
…p long press action`, `Meta panel bottom margin` settings
  • Loading branch information
inotia00 authored and Francesco146 committed Jul 5, 2024
1 parent 766925d commit be36036
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
package app.revanced.integrations.youtube.patches.shorts;

import static app.revanced.integrations.shared.utils.Utils.hideViewUnderCondition;
import static app.revanced.integrations.youtube.utils.ExtendedUtils.validateValue;

import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.lang.ref.WeakReference;

import app.revanced.integrations.shared.utils.ResourceUtils;
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.utils.VideoUtils;

@SuppressWarnings("unused")
public class ShortsPatch {
private static final boolean ENABLE_TIME_STAMP = Settings.ENABLE_TIME_STAMP.get();
private static final int META_PANEL_BOTTOM_MARGIN;

static {
final int bottomMargin = validateValue(
Settings.META_PANEL_BOTTOM_MARGIN,
0,
64,
"revanced_shorts_meta_panel_bottom_margin_invalid_toast"
);

META_PANEL_BOTTOM_MARGIN = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) bottomMargin, Utils.getResources().getDisplayMetrics());
}

public static Enum<?> repeat;
public static Enum<?> singlePlay;
public static Enum<?> endScreen;
Expand All @@ -31,6 +50,40 @@ public static boolean disableResumingStartupShortsPlayer() {
return Settings.DISABLE_RESUMING_SHORTS_PLAYER.get();
}

public static boolean enableShortsTimeStamp(boolean original) {
return ENABLE_TIME_STAMP || original;
}

public static int enableShortsTimeStamp(int original) {
return ENABLE_TIME_STAMP ? 10010 : original;
}

public static void setShortsMetaPanelBottomMargin(View view) {
if (!ENABLE_TIME_STAMP)
return;

if (!(view.getLayoutParams() instanceof RelativeLayout.LayoutParams lp))
return;

lp.setMargins(0, 0, 0, META_PANEL_BOTTOM_MARGIN);
lp.setMarginEnd(ResourceUtils.getDimension("reel_player_right_dyn_bar_width"));
}

public static void setShortsTimeStampChangeRepeatState(View view) {
if (!ENABLE_TIME_STAMP)
return;
if (!Settings.TIME_STAMP_CHANGE_REPEAT_STATE.get())
return;
if (view == null)
return;

view.setLongClickable(true);
view.setOnLongClickListener(view1 -> {
VideoUtils.showShortsRepeatDialog(view1.getContext());
return true;
});
}

public static void hideShortsCommentsButton(View view) {
hideViewUnderCondition(Settings.HIDE_SHORTS_COMMENTS_BUTTON.get(), view);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ public class Settings extends BaseSettings {


// Experimental Flags
public static final BooleanSetting ENABLE_TIME_STAMP = new BooleanSetting("revanced_enable_shorts_time_stamp", FALSE, true);
public static final BooleanSetting TIME_STAMP_CHANGE_REPEAT_STATE = new BooleanSetting("revanced_shorts_time_stamp_change_repeat_state", TRUE, true, parent(ENABLE_TIME_STAMP));
public static final IntegerSetting META_PANEL_BOTTOM_MARGIN = new IntegerSetting("revanced_shorts_meta_panel_bottom_margin", 32, true, parent(ENABLE_TIME_STAMP));
public static final BooleanSetting HIDE_SHORTS_TOOLBAR = new BooleanSetting("revanced_hide_shorts_toolbar", FALSE, true);
public static final BooleanSetting HIDE_SHORTS_NAVIGATION_BAR = new BooleanSetting("revanced_hide_shorts_navigation_bar", FALSE, true);
public static final BooleanSetting REPLACE_CHANNEL_HANDLE = new BooleanSetting("revanced_replace_channel_handle", FALSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.shared.settings.IntegerSetting;
import app.revanced.integrations.shared.settings.StringSetting;
import app.revanced.integrations.shared.utils.IntentUtils;
import app.revanced.integrations.shared.utils.Logger;
Expand All @@ -21,6 +22,7 @@
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

import static app.revanced.integrations.shared.utils.ResourceUtils.getStringArray;
import static app.revanced.integrations.shared.utils.StringRef.str;
import static app.revanced.integrations.youtube.patches.video.PlaybackSpeedPatch.userSelectedPlaybackSpeed;
import static app.revanced.integrations.youtube.settings.preference.ExternalDownloaderPreference.checkPackageIsEnabled;
Expand Down Expand Up @@ -159,6 +161,31 @@ public static void showPlaybackSpeedDialog(@NonNull Context context) {
.show();
}

private static int mClickedDialogEntryIndex;

public static void showShortsRepeatDialog(@NonNull Context context) {
final IntegerSetting setting = Settings.CHANGE_SHORTS_REPEAT_STATE;
final String settingsKey = setting.key;

final String entryKey = settingsKey + "_entries";
final String entryValueKey = settingsKey + "_entry_values";
final String[] mEntries = getStringArray(entryKey);
final String[] mEntryValues = getStringArray(entryValueKey);

final int findIndex = Arrays.binarySearch(mEntryValues, String.valueOf(setting.get()));
mClickedDialogEntryIndex = findIndex >= 0 ? findIndex : setting.defaultValue;

new AlertDialog.Builder(context)
.setTitle(str(settingsKey + "_title"))
.setSingleChoiceItems(mEntries, mClickedDialogEntryIndex, (dialog, id) -> {
mClickedDialogEntryIndex = id;
setting.save(id);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}

public static void showFlyoutMenu() {
if (Settings.APPEND_TIME_STAMP_INFORMATION_TYPE.get()) {
showVideoQualityFlyoutMenu();
Expand Down

0 comments on commit be36036

Please sign in to comment.