This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Tumblr): Use a common filter patch (#479)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/src/main/java/app/revanced/tumblr/patches/TimelineFilterPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package app.revanced.tumblr.patches; | ||
|
||
import com.tumblr.rumblr.model.TimelineObject; | ||
import com.tumblr.rumblr.model.Timelineable; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
public final class TimelineFilterPatch { | ||
private static final HashSet<String> blockedObjectTypes = new HashSet<>(); | ||
|
||
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(final List<TimelineObject<? extends Timelineable>> timelineObjects) { | ||
final var iterator = timelineObjects.iterator(); | ||
while (iterator.hasNext()) { | ||
var timelineElement = iterator.next(); | ||
if (timelineElement == null) continue; | ||
|
||
String elementType = timelineElement.getData().getTimelineObjectType().toString(); | ||
if (blockedObjectTypes.contains(elementType)) iterator.remove(); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dummy/src/main/java/com/tumblr/rumblr/model/TimelineObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.tumblr.rumblr.model; | ||
|
||
public class TimelineObject<T extends Timelineable> { | ||
public final T getData() { | ||
throw new UnsupportedOperationException("Stub"); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
dummy/src/main/java/com/tumblr/rumblr/model/TimelineObjectType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.tumblr.rumblr.model; | ||
|
||
public enum TimelineObjectType { | ||
} |
5 changes: 5 additions & 0 deletions
5
dummy/src/main/java/com/tumblr/rumblr/model/Timelineable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tumblr.rumblr.model; | ||
|
||
public interface Timelineable { | ||
TimelineObjectType getTimelineObjectType(); | ||
} |