From 7eb209d8533f68cd344c331482b38bfcf4baca06 Mon Sep 17 00:00:00 2001 From: LagradOst <46196380+Blatzar@users.noreply.github.com> Date: Sun, 11 Jun 2023 23:18:56 +0000 Subject: [PATCH] feat(reddit): add `hide-promoted` patch (#419) Co-authored-by: oSumAtrIX --- .../patches/FilterPromotedLinksPatch.java | 26 +++++++++++++++++++ .../java/com/reddit/domain/model/ILink.java | 7 +++++ 2 files changed, 33 insertions(+) create mode 100644 app/src/main/java/app/revanced/reddit/patches/FilterPromotedLinksPatch.java create mode 100644 dummy/src/main/java/com/reddit/domain/model/ILink.java diff --git a/app/src/main/java/app/revanced/reddit/patches/FilterPromotedLinksPatch.java b/app/src/main/java/app/revanced/reddit/patches/FilterPromotedLinksPatch.java new file mode 100644 index 00000000..5c9d3207 --- /dev/null +++ b/app/src/main/java/app/revanced/reddit/patches/FilterPromotedLinksPatch.java @@ -0,0 +1,26 @@ +package app.revanced.reddit.patches; + +import com.reddit.domain.model.ILink; + +import java.util.ArrayList; +import java.util.List; + +public final class FilterPromotedLinksPatch { + /** + * Filters list from promoted links. + **/ + public static List filterChildren(final Iterable links) { + final List filteredList = new ArrayList<>(); + + for (Object item : links) { + if (!(item instanceof ILink)) continue; + + final var link = (ILink) item; + final var isPromotedAd = link.getPromoted(); + + if (!isPromotedAd) filteredList.add(item); + } + + return filteredList; + } +} diff --git a/dummy/src/main/java/com/reddit/domain/model/ILink.java b/dummy/src/main/java/com/reddit/domain/model/ILink.java new file mode 100644 index 00000000..f9cbb955 --- /dev/null +++ b/dummy/src/main/java/com/reddit/domain/model/ILink.java @@ -0,0 +1,7 @@ +package com.reddit.domain.model; + +public class ILink { + public boolean getPromoted() { + throw new UnsupportedOperationException("Stub"); + } +}