mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-12-07 01:51:27 +01:00
feat(YouTube - Hide layout components): Add "Hide view count" and "Hide upload time" settings (#5983)
This commit is contained in:
@@ -3,6 +3,9 @@ package app.revanced.extension.youtube.patches.components;
|
||||
import static app.revanced.extension.youtube.shared.NavigationBar.NavigationButton;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -500,4 +503,62 @@ public final class LayoutComponentsFilter extends Filter {
|
||||
// This check is important as the shelf layout is used for the library tab playlists.
|
||||
return NavigationButton.getSelectedNavigationButton() != NavigationButton.LIBRARY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static SpannableString modifyFeedSubtitleSpan(SpannableString original, float truncationDimension) {
|
||||
try {
|
||||
final boolean hideViewCount = Settings.HIDE_VIEW_COUNT.get();
|
||||
final boolean hideUploadTime = Settings.HIDE_UPLOAD_TIME.get();
|
||||
if (!hideViewCount && !hideUploadTime) {
|
||||
return original;
|
||||
}
|
||||
|
||||
// Applies only for these specific dimensions.
|
||||
if (truncationDimension == 16f || truncationDimension == 42f) {
|
||||
String delimiter = " · ";
|
||||
final int delimiterLength = delimiter.length();
|
||||
|
||||
// Index includes the starting delimiter.
|
||||
final int viewCountStartIndex = TextUtils.indexOf(original, delimiter);
|
||||
if (viewCountStartIndex < 0) {
|
||||
return original;
|
||||
}
|
||||
|
||||
final int uploadTimeStartIndex = TextUtils.indexOf(original, delimiter,
|
||||
viewCountStartIndex + delimiterLength);
|
||||
if (uploadTimeStartIndex < 0) {
|
||||
return original;
|
||||
}
|
||||
|
||||
// Ensure there is exactly 2 delimiters.
|
||||
if (TextUtils.indexOf(original, delimiter,
|
||||
uploadTimeStartIndex + delimiterLength) >= 0) {
|
||||
return original;
|
||||
}
|
||||
|
||||
// Make a mutable copy that keeps existing span styling.
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(original);
|
||||
|
||||
// Remove the sections.
|
||||
if (hideUploadTime) {
|
||||
builder.delete(uploadTimeStartIndex, original.length());
|
||||
}
|
||||
|
||||
if (hideViewCount) {
|
||||
builder.delete(viewCountStartIndex, uploadTimeStartIndex);
|
||||
}
|
||||
|
||||
SpannableString replacement = new SpannableString(builder);
|
||||
Logger.printDebug(() -> "Replacing feed subtitle span: " + original + " with: " + replacement);
|
||||
|
||||
return replacement;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "modifyFeedSubtitleSpan failure", ex);
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,9 @@ public class Settings extends BaseSettings {
|
||||
public static final BooleanSetting HIDE_SHOW_MORE_BUTTON = new BooleanSetting("revanced_hide_show_more_button", TRUE, true);
|
||||
public static final BooleanSetting HIDE_SURVEYS = new BooleanSetting("revanced_hide_surveys", TRUE);
|
||||
public static final BooleanSetting HIDE_TICKET_SHELF = new BooleanSetting("revanced_hide_ticket_shelf", FALSE);
|
||||
public static final BooleanSetting HIDE_UPLOAD_TIME = new BooleanSetting("revanced_hide_upload_time", FALSE, "revanced_hide_upload_time_user_dialog_message");
|
||||
public static final BooleanSetting HIDE_VIDEO_RECOMMENDATION_LABELS = new BooleanSetting("revanced_hide_video_recommendation_labels", TRUE);
|
||||
public static final BooleanSetting HIDE_VIEW_COUNT = new BooleanSetting("revanced_hide_view_count", FALSE, "revanced_hide_view_count_user_dialog_message");
|
||||
|
||||
// Alternative thumbnails
|
||||
public static final EnumSetting<ThumbnailOption> ALT_THUMBNAIL_HOME = new EnumSetting<>("revanced_alt_thumbnail_home", ThumbnailOption.ORIGINAL);
|
||||
|
||||
Reference in New Issue
Block a user