From 79e21298105fed28f06928c3eb92b0109341e849 Mon Sep 17 00:00:00 2001 From: Temm Date: Sat, 23 Sep 2023 21:19:27 +0200 Subject: [PATCH 1/5] feat(Tumblr): Add feat filter integration --- .../tumblr/patches/TimelineFilterPatch.java | 28 +++++++++++++++++++ .../tumblr/rumblr/model/TimelineObject.java | 8 ++++++ .../rumblr/model/TimelineObjectType.java | 4 +++ .../com/tumblr/rumblr/model/Timelineable.java | 5 ++++ 4 files changed, 45 insertions(+) create mode 100644 app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java create mode 100644 dummy/src/main/java/com/tumblr/rumblr/model/TimelineObject.java create mode 100644 dummy/src/main/java/com/tumblr/rumblr/model/TimelineObjectType.java create mode 100644 dummy/src/main/java/com/tumblr/rumblr/model/Timelineable.java diff --git a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java new file mode 100644 index 0000000000..bb1d24f653 --- /dev/null +++ b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java @@ -0,0 +1,28 @@ +package app.revanced.tumblr.patches; + +import android.util.Log; + +import com.tumblr.rumblr.model.TimelineObject; +import com.tumblr.rumblr.model.TimelineObjectType; +import com.tumblr.rumblr.model.Timelineable; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; + +public class TimelineFilterPatch { + public static void filterTimeline(List> timelineObjects) { + Iterator> iterator = timelineObjects.iterator(); + while (iterator.hasNext()) { + TimelineObject timelineElement = iterator.next(); + if (timelineElement == null) continue; + String elementType = timelineElement.getData().getTimelineObjectType().toString(); + + // This dummy gets removed by the TimelineFilterPatch and in its place, + // equivalent instructions with a different constant string + // will be inserted for each Timeline object type filter. + if ("BLOCKED_OBJECT_DUMMY".equals(elementType)) iterator.remove(); + } + } +} diff --git a/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObject.java b/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObject.java new file mode 100644 index 0000000000..8bb2c885d4 --- /dev/null +++ b/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObject.java @@ -0,0 +1,8 @@ +package com.tumblr.rumblr.model; + +public class TimelineObject { + public final T getData() { + throw new UnsupportedOperationException("Stub"); + } + +} diff --git a/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObjectType.java b/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObjectType.java new file mode 100644 index 0000000000..f9b7d7abca --- /dev/null +++ b/dummy/src/main/java/com/tumblr/rumblr/model/TimelineObjectType.java @@ -0,0 +1,4 @@ +package com.tumblr.rumblr.model; + +public enum TimelineObjectType { +} diff --git a/dummy/src/main/java/com/tumblr/rumblr/model/Timelineable.java b/dummy/src/main/java/com/tumblr/rumblr/model/Timelineable.java new file mode 100644 index 0000000000..bf84887def --- /dev/null +++ b/dummy/src/main/java/com/tumblr/rumblr/model/Timelineable.java @@ -0,0 +1,5 @@ +package com.tumblr.rumblr.model; + +public interface Timelineable { + TimelineObjectType getTimelineObjectType(); +} From 2f313bb60105d756e3d73dc0d0895ef343986f4f Mon Sep 17 00:00:00 2001 From: leumasme Date: Sun, 24 Sep 2023 00:22:18 +0200 Subject: [PATCH 2/5] refactor(Tumblr): add refactor warning comment --- .../java/app/revanced/tumblr/patches/TimelineFilterPatch.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java index bb1d24f653..87c3bf923b 100644 --- a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java +++ b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java @@ -12,6 +12,8 @@ import java.util.Objects; public class TimelineFilterPatch { + // !! This method gets modified by the TimelineFilterPatch. + // If you refactor this method, you will need to update the patch. public static void filterTimeline(List> timelineObjects) { Iterator> iterator = timelineObjects.iterator(); while (iterator.hasNext()) { From 7e4879ed4caa9e561edcd83571a0c35842fc4ad5 Mon Sep 17 00:00:00 2001 From: leumasme Date: Fri, 29 Sep 2023 06:22:48 +0200 Subject: [PATCH 3/5] refactor: update tumblr patch injection method --- .../tumblr/patches/TimelineFilterPatch.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java index 87c3bf923b..0695a8a9d3 100644 --- a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java +++ b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java @@ -1,19 +1,25 @@ package app.revanced.tumblr.patches; -import android.util.Log; - import com.tumblr.rumblr.model.TimelineObject; -import com.tumblr.rumblr.model.TimelineObjectType; import com.tumblr.rumblr.model.Timelineable; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Objects; public class TimelineFilterPatch { - // !! This method gets modified by the TimelineFilterPatch. - // If you refactor this method, you will need to update the patch. + static List blockedObjectTypes = new ArrayList<>(); + + static { + // This dummy gets removed by the TimelineFilterPatch and in its place, + // equivalent instructions with a different constant string + // will be inserted for each Timeline object type filter. + // Modifying this line may break the patch. + blockedObjectTypes.add("BLOCKED_OBJECT_DUMMY"); + } + + // Calls to this method are injected where the list of Timeline objects is first received. + // We modify the list filter out elements that we want to hide. public static void filterTimeline(List> timelineObjects) { Iterator> iterator = timelineObjects.iterator(); while (iterator.hasNext()) { @@ -21,10 +27,7 @@ public static void filterTimeline(List> t if (timelineElement == null) continue; String elementType = timelineElement.getData().getTimelineObjectType().toString(); - // This dummy gets removed by the TimelineFilterPatch and in its place, - // equivalent instructions with a different constant string - // will be inserted for each Timeline object type filter. - if ("BLOCKED_OBJECT_DUMMY".equals(elementType)) iterator.remove(); + if (blockedObjectTypes.contains(elementType)) iterator.remove(); } } } From 633ea4dc5d176c1a09bae8a73ff4c72f668d55dd Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 1 Oct 2023 04:50:36 +0200 Subject: [PATCH 4/5] refactor --- .../tumblr/patches/TimelineFilterPatch.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java index 0695a8a9d3..b954502baf 100644 --- a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java +++ b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java @@ -4,11 +4,10 @@ import com.tumblr.rumblr.model.Timelineable; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -public class TimelineFilterPatch { - static List blockedObjectTypes = new ArrayList<>(); +public final class TimelineFilterPatch { + private static final List blockedObjectTypes = new ArrayList<>(); static { // This dummy gets removed by the TimelineFilterPatch and in its place, @@ -20,13 +19,13 @@ public class TimelineFilterPatch { // Calls to this method are injected where the list of Timeline objects is first received. // We modify the list filter out elements that we want to hide. - public static void filterTimeline(List> timelineObjects) { - Iterator> iterator = timelineObjects.iterator(); + public static void filterTimeline(final List> timelineObjects) { + final var iterator = timelineObjects.iterator(); while (iterator.hasNext()) { - TimelineObject timelineElement = iterator.next(); + var timelineElement = iterator.next(); if (timelineElement == null) continue; - String elementType = timelineElement.getData().getTimelineObjectType().toString(); + String elementType = timelineElement.getData().getTimelineObjectType().toString(); if (blockedObjectTypes.contains(elementType)) iterator.remove(); } } From 479c92b92873873936aa92d49c668c8b77326053 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 1 Oct 2023 04:57:25 +0200 Subject: [PATCH 5/5] perf: Use HashSet --- .../java/app/revanced/tumblr/patches/TimelineFilterPatch.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java index b954502baf..1a4d50eff3 100644 --- a/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java +++ b/app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java @@ -3,11 +3,11 @@ import com.tumblr.rumblr.model.TimelineObject; import com.tumblr.rumblr.model.Timelineable; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; public final class TimelineFilterPatch { - private static final List blockedObjectTypes = new ArrayList<>(); + private static final HashSet blockedObjectTypes = new HashSet<>(); static { // This dummy gets removed by the TimelineFilterPatch and in its place,