diff --git a/CHANGELOG.md b/CHANGELOG.md index 0645d365b9..b1d5655eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,45 @@ +# [1.6.0-dev.5](https://github.com/crimera/revanced-integrations/compare/v1.6.0-dev.4...v1.6.0-dev.5) (2024-03-22) + + +### Features + +* **Twitter:** Added Ad block hooks ([1d44f8d](https://github.com/crimera/revanced-integrations/commit/1d44f8d443da475e6a925716606d221d945b949c)) + +# [1.6.0-dev.4](https://github.com/crimera/revanced-integrations/compare/v1.6.0-dev.3...v1.6.0-dev.4) (2024-03-18) + + +### Features + +* **Twitter:** Added `Hide Community Notes` to mod settings ([340bb62](https://github.com/crimera/revanced-integrations/commit/340bb62cad351a59922c6182a61476b211e212e0)) +* **Twitter:** Added `Hide Promoted Trends` to Mod Settings ([b613719](https://github.com/crimera/revanced-integrations/commit/b61371941cd8371da9479b7b1f392e5b9a191600)) + +# [1.6.0-dev.3](https://github.com/crimera/revanced-integrations/compare/v1.6.0-dev.2...v1.6.0-dev.3) (2024-03-18) + + +### Features + +* **Twitter:** Add settings for `Remove view count` patch ([0a1469f](https://github.com/crimera/revanced-integrations/commit/0a1469fdea4a8c90dd2f34ee9c40f64f5386ec1b)) + +# [1.6.0-dev.2](https://github.com/crimera/revanced-integrations/compare/v1.6.0-dev.1...v1.6.0-dev.2) (2024-03-18) + + +### Bug Fixes + +* **Twitter:** Use sentence case in settings ([6d05c55](https://github.com/crimera/revanced-integrations/commit/6d05c55d525ce3102ed1c1a9f5d8629a5ea29ca9)) + + +### Features + +* **Twitter:** Add settings for `Hide FAB` patch ([dfa58ce](https://github.com/crimera/revanced-integrations/commit/dfa58ce5a79f71c5bc0e17e39c3c456584fc1e22)) + +# [1.6.0-dev.1](https://github.com/crimera/revanced-integrations/compare/v1.5.0...v1.6.0-dev.1) (2024-03-18) + + +### Features + +* **fix:** Enable `Hide Recommended Users` by default ([0653731](https://github.com/crimera/revanced-integrations/commit/0653731be724ac21d21db712207c5ec31f65decc)) +* **Twitter:** Add Settings for `Hide Recommended Users` patch ([6d518dc](https://github.com/crimera/revanced-integrations/commit/6d518dcf4d016b15ce87831d517bd64a6c29c579)) + # [1.5.0](https://github.com/crimera/revanced-integrations/compare/v1.4.0...v1.5.0) (2024-03-17) diff --git a/app/src/main/java/app/revanced/integrations/twitter/Pref.java b/app/src/main/java/app/revanced/integrations/twitter/Pref.java index 6ac5066274..21d9c37b3d 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/Pref.java +++ b/app/src/main/java/app/revanced/integrations/twitter/Pref.java @@ -1,9 +1,8 @@ package app.revanced.integrations.twitter; -import app.revanced.integrations.twitter.Utils; import app.revanced.integrations.twitter.settings.Settings; + import java.util.ArrayList; -import java.util.Arrays; public class Pref { @@ -15,6 +14,11 @@ public static String getVideoFolder(String filename) { return Utils.getStringPref(Settings.VID_SUBFOLDER)+"/"+filename; } + public static ArrayList hideRecommendedUsers(ArrayList users) { + if (Utils.getBooleanPerf(Settings.MISC_HIDE_RECOMMENDED_USERS)) { return null; } + return users; + } + public static ArrayList liveThread(ArrayList fleets) { if (Utils.getBooleanPerf(Settings.TIMELINE_HIDE_LIVETHREADS)) { return null; } return fleets; @@ -28,5 +32,45 @@ public static int hideForYou() { return Utils.getBooleanPerf(Settings.TIMELINE_HIDE_FORYOU)?34:17; } + public static boolean hideFAB() { + return Utils.getBooleanPerf(Settings.MISC_HIDE_FAB); + } + + public static boolean hideCommNotes() { + return Utils.getBooleanPerf(Settings.MISC_HIDE_COMM_NOTES); + } + + public static boolean hideViewCount() { + return !Utils.getBooleanPerf(Settings.MISC_HIDE_VIEW_COUNT); + } + + public static boolean hidePromotedTrend(Object data) { + if(data!=null && Utils.getBooleanPerf(Settings.ADS_HIDE_PROMOTED_TRENDS)){ + return true; + } + return false; + } + public static boolean hideAds() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_PROMOTED_POSTS); + } + public static boolean hideGoogleAds() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_GOOGLE_ADS); + } + public static boolean hideWTF() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_WHO_TO_FOLLOW); + } + public static boolean hideCTS() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_CREATORS_TO_SUB); + } + public static boolean hideCTJ() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_COMM_TO_JOIN); + } + public static boolean hideRBMK() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_REVISIT_BMK); + } + public static boolean hideDetailedPosts() { + return Utils.getBooleanPerf(Settings.ADS_HIDE_DETAILED_POSTS); + } + //end } \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/TimelineEntry.java b/app/src/main/java/app/revanced/integrations/twitter/patches/TimelineEntry.java new file mode 100644 index 0000000000..1196de791b --- /dev/null +++ b/app/src/main/java/app/revanced/integrations/twitter/patches/TimelineEntry.java @@ -0,0 +1,75 @@ +package app.revanced.integrations.twitter.patches; + +import app.revanced.integrations.twitter.Pref; +import app.revanced.integrations.twitter.Utils; +import app.revanced.integrations.twitter.settings.SettingsStatus; +import android.util.Log; +import java.lang.reflect.Field; + + +public class TimelineEntry { + private static boolean hideAds,hideGAds,hideWTF,hideCTS,hideCTJ,hideDetailedPosts,hideRBMK; + static { + SettingsStatus.load(); + hideAds = (Pref.hideAds() && SettingsStatus.hideAds); + hideGAds = (Pref.hideGoogleAds() && SettingsStatus.hideGAds); + hideWTF = (Pref.hideWTF() && SettingsStatus.hideWTF); + hideCTS = (Pref.hideCTS() && SettingsStatus.hideCTS); + hideCTJ = (Pref.hideCTJ() && SettingsStatus.hideCTJ); + hideDetailedPosts = (Pref.hideDetailedPosts() && SettingsStatus.hideDetailedPosts); + hideRBMK = (Pref.hideRBMK() && SettingsStatus.hideRBMK); + } + + + + private static boolean isEntryIdRemove(String entryId) { + String[] split = entryId.split("-"); + String entryId2 = split[0]; + if (!entryId2.equals("cursor") && !entryId2.equals("Guide") && !entryId2.startsWith("semantic_core")) { + if ((entryId2.equals("promoted") || ((entryId2.equals("conversationthread") && split.length == 3) || entryId2.equals("superhero"))) && hideAds) { + return true; + } + if (entryId2.equals("rtb") && hideGAds) { + return true; + } + + if (entryId2.equals("tweetdetailrelatedtweets") && hideDetailedPosts) { + return true; + } + if (entryId2.equals("bookmarked") && hideRBMK) { + return true; + } + if (entryId.startsWith("community-to-join") && hideCTJ) { + return true; + } + if (entryId.startsWith("who-to-follow") && hideWTF) { + return true; + } + if (entryId.startsWith("who-to-subscribe") && hideCTS) { + return true; + } + } + return false; + } + + public static boolean checkEntry(Object jsonTimelineEntry) { + try { + String className = "com.twitter.model.json.timeline.urt.JsonTimelineEntry"; // Replace with your fully qualified class name + Class clazz = Class.forName(className); + + if (!clazz.isInstance(jsonTimelineEntry)) { + return false; + } + + clazz.cast(jsonTimelineEntry); + Field a = clazz.getDeclaredField("a"); + String entryId = (String) a.get(jsonTimelineEntry); + return isEntryIdRemove(entryId); + } catch (Exception unused) { + + } + return false; + } + +//end +} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt deleted file mode 100644 index 536a43e1f9..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/BaseJsonHook.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.json - -import org.json.JSONObject - -abstract class BaseJsonHook : JsonHook { - abstract fun apply(json: JSONObject) - - override fun transform(json: JSONObject) = json.apply { apply(json) } -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt deleted file mode 100644 index 3edfca4e6a..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHook.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.json - -import app.revanced.integrations.twitter.patches.hook.patch.Hook -import org.json.JSONObject - -interface JsonHook : Hook { - /** - * Transform a JSONObject. - * - * @param json The JSONObject. - */ - fun transform(json: JSONObject): JSONObject - - override fun hook(type: JSONObject) = transform(type) -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt deleted file mode 100644 index 6e4067b923..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/json/JsonHookPatch.kt +++ /dev/null @@ -1,30 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.json - -import app.revanced.integrations.twitter.patches.hook.patch.dummy.DummyHook -import app.revanced.integrations.twitter.utils.json.JsonUtils.parseJson -import app.revanced.integrations.twitter.utils.stream.StreamUtils -import org.json.JSONException -import java.io.IOException -import java.io.InputStream - -object JsonHookPatch { - // Additional hooks added by corresponding patch. - private val hooks = buildList { - add(DummyHook) - } - - @JvmStatic - fun parseJsonHook(jsonInputStream: InputStream): InputStream { - var jsonObject = try { - parseJson(jsonInputStream) - } catch (ignored: IOException) { - return jsonInputStream // Unreachable. - } catch (ignored: JSONException) { - return jsonInputStream - } - - for (hook in hooks) jsonObject = hook.hook(jsonObject) - - return StreamUtils.fromString(jsonObject.toString()) - } -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt deleted file mode 100644 index d6d163ef97..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/Hook.kt +++ /dev/null @@ -1,9 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.patch - -interface Hook { - /** - * Hook the given type. - * @param type The type to hook - */ - fun hook(type: T): T -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt deleted file mode 100644 index 7c33a5b21a..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/ads/AdsHook.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.patch.ads - -import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook -import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker -import org.json.JSONObject - - -object AdsHook : BaseJsonHook() { - /** - * Strips JSONObject from promoted ads. - * - * @param json The JSONObject. - */ - override fun apply(json: JSONObject) = TwiFucker.hidePromotedAds(json) -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/browserchooser/BrowserChooserHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/browserchooser/BrowserChooserHook.kt deleted file mode 100644 index b79d0ef42e..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/browserchooser/BrowserChooserHook.kt +++ /dev/null @@ -1,10 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.patch.browserchooser - -import android.content.Context -import android.content.Intent -import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker - - -object BrowserChooserHook { - fun open(context: Context, intent: Intent) = TwiFucker.openWithChooser(context, intent) -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt deleted file mode 100644 index 1a4f583c7b..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/dummy/DummyHook.kt +++ /dev/null @@ -1,14 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.patch.dummy - -import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook -import app.revanced.integrations.twitter.patches.hook.json.JsonHookPatch -import org.json.JSONObject - -/** - * Dummy hook to reserve a register in [JsonHookPatch.hooks] list. - */ -object DummyHook : BaseJsonHook() { - override fun apply(json: JSONObject) { - // Do nothing. - } -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt deleted file mode 100644 index dfbb1ffb23..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/patch/recommendation/RecommendedUsersHook.kt +++ /dev/null @@ -1,15 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.patch.recommendation - -import app.revanced.integrations.twitter.patches.hook.json.BaseJsonHook -import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFucker -import org.json.JSONObject - - -object RecommendedUsersHook : BaseJsonHook() { - /** - * Strips JSONObject from recommended users. - * - * @param json The JSONObject. - */ - override fun apply(json: JSONObject) = TwiFucker.hideRecommendedUsers(json) -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt deleted file mode 100644 index b21b16ca79..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFucker.kt +++ /dev/null @@ -1,232 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.twifucker - -import android.content.Context -import android.content.Intent -import android.net.Uri -import android.util.Log -import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFuckerUtils.forEach -import app.revanced.integrations.twitter.patches.hook.twifucker.TwiFuckerUtils.forEachIndexed -import org.json.JSONArray -import org.json.JSONObject - -// https://raw.githubusercontent.com/Dr-TSNG/TwiFucker/880cdf1c1622e54ab45561ffcb4f53d94ed97bae/app/src/main/java/icu/nullptr/twifucker/hook/JsonHook.kt -internal object TwiFucker { - // root - private fun JSONObject.jsonGetInstructions(): JSONArray? = optJSONObject("timeline")?.optJSONArray("instructions") - - private fun JSONObject.jsonGetData(): JSONObject? = optJSONObject("data") - - private fun JSONObject.jsonHasRecommendedUsers(): Boolean = has("recommended_users") - - private fun JSONObject.jsonRemoveRecommendedUsers() { - remove("recommended_users") - } - - private fun JSONObject.jsonCheckAndRemoveRecommendedUsers() { - if (jsonHasRecommendedUsers()) { - Log.d("ReVanced", "Handle recommended users: $this") - jsonRemoveRecommendedUsers() - } - } - - private fun JSONObject.jsonHasThreads(): Boolean = has("threads") - - private fun JSONObject.jsonRemoveThreads() { - remove("threads") - } - - private fun JSONObject.jsonCheckAndRemoveThreads() { - if (jsonHasThreads()) { - Log.d("ReVanced", "Handle threads: $this") - jsonRemoveThreads() - } - } - - // data - private fun JSONObject.dataGetInstructions(): JSONArray? { - val timeline = - optJSONObject("user_result")?.optJSONObject("result") - ?.optJSONObject("timeline_response")?.optJSONObject("timeline") - ?: optJSONObject("timeline_response")?.optJSONObject("timeline") - ?: optJSONObject("search")?.optJSONObject("timeline_response")?.optJSONObject("timeline") - ?: optJSONObject("timeline_response") - return timeline?.optJSONArray("instructions") - } - - private fun JSONObject.dataCheckAndRemove() { - dataGetInstructions()?.forEach { instruction -> - instruction.instructionCheckAndRemove { it.entriesRemoveAnnoyance() } - } - } - - private fun JSONObject.dataGetLegacy(): JSONObject? = - optJSONObject("tweet_result")?.optJSONObject("result")?.let { - if (it.has("tweet")) { - it.optJSONObject("tweet") - } else { - it - } - }?.optJSONObject("legacy") - - // entry - private fun JSONObject.entryHasPromotedMetadata(): Boolean = - optJSONObject("content")?.optJSONObject("item")?.optJSONObject("content") - ?.optJSONObject("tweet") - ?.has("promotedMetadata") == true || optJSONObject("content")?.optJSONObject("content") - ?.has("tweetPromotedMetadata") == true || optJSONObject("item")?.optJSONObject("content") - ?.has("tweetPromotedMetadata") == true - - private fun JSONObject.entryGetContentItems(): JSONArray? = - optJSONObject("content")?.optJSONArray("items") - ?: optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") - - private fun JSONObject.entryIsTweetDetailRelatedTweets(): Boolean = optString("entryId").startsWith("tweetdetailrelatedtweets-") - - private fun JSONObject.entryGetTrends(): JSONArray? = optJSONObject("content")?.optJSONObject("timelineModule")?.optJSONArray("items") - - // trend - private fun JSONObject.trendHasPromotedMetadata(): Boolean = - optJSONObject("item")?.optJSONObject("content")?.optJSONObject("trend") - ?.has("promotedMetadata") == true - - private fun JSONArray.trendRemoveAds() { - val trendRemoveIndex = mutableListOf() - forEachIndexed { trendIndex, trend -> - if (trend.trendHasPromotedMetadata()) { - Log.d("ReVanced", "Handle trends ads $trendIndex $trend") - trendRemoveIndex.add(trendIndex) - } - } - for (i in trendRemoveIndex.asReversed()) { - remove(i) - } - } - - // instruction - private fun JSONObject.instructionTimelineAddEntries(): JSONArray? = optJSONArray("entries") - - private fun JSONObject.instructionGetAddEntries(): JSONArray? = optJSONObject("addEntries")?.optJSONArray("entries") - - private fun JSONObject.instructionCheckAndRemove(action: (JSONArray) -> Unit) { - instructionTimelineAddEntries()?.let(action) - instructionGetAddEntries()?.let(action) - } - - // entries - private fun JSONArray.entriesRemoveTimelineAds() { - val removeIndex = mutableListOf() - forEachIndexed { entryIndex, entry -> - entry.entryGetTrends()?.trendRemoveAds() - - if (entry.entryHasPromotedMetadata()) { - Log.d("ReVanced", "Handle timeline ads $entryIndex $entry") - removeIndex.add(entryIndex) - } - - val innerRemoveIndex = mutableListOf() - val contentItems = entry.entryGetContentItems() - contentItems?.forEachIndexed inner@{ itemIndex, item -> - if (item.entryHasPromotedMetadata()) { - Log.d("ReVanced", "Handle timeline replies ads $entryIndex $entry") - if (contentItems.length() == 1) { - removeIndex.add(entryIndex) - } else { - innerRemoveIndex.add(itemIndex) - } - return@inner - } - } - for (i in innerRemoveIndex.asReversed()) { - contentItems?.remove(i) - } - } - for (i in removeIndex.reversed()) { - remove(i) - } - } - - private fun JSONArray.entriesRemoveTweetDetailRelatedTweets() { - val removeIndex = mutableListOf() - forEachIndexed { entryIndex, entry -> - - if (entry.entryIsTweetDetailRelatedTweets()) { - Log.d("ReVanced", "Handle tweet detail related tweets $entryIndex $entry") - removeIndex.add(entryIndex) - } - } - for (i in removeIndex.reversed()) { - remove(i) - } - } - - private fun JSONArray.entriesRemoveAnnoyance() { - entriesRemoveTimelineAds() - entriesRemoveTweetDetailRelatedTweets() - } - - private fun JSONObject.entryIsWhoToFollow(): Boolean = - optString("entryId").let { - it.startsWith("whoToFollow-") || it.startsWith("who-to-follow-") || it.startsWith("connect-module-") - } - - private fun JSONObject.itemContainsPromotedUser(): Boolean = - optJSONObject("item")?.optJSONObject("content") - ?.has("userPromotedMetadata") == true || optJSONObject("item")?.optJSONObject("content") - ?.optJSONObject("user") - ?.has("userPromotedMetadata") == true || optJSONObject("item")?.optJSONObject("content") - ?.optJSONObject("user")?.has("promotedMetadata") == true - - fun JSONArray.entriesRemoveWhoToFollow() { - val entryRemoveIndex = mutableListOf() - forEachIndexed { entryIndex, entry -> - if (!entry.entryIsWhoToFollow()) return@forEachIndexed - - Log.d("ReVanced", "Handle whoToFollow $entryIndex $entry") - entryRemoveIndex.add(entryIndex) - - val items = entry.entryGetContentItems() - val userRemoveIndex = mutableListOf() - items?.forEachIndexed { index, item -> - item.itemContainsPromotedUser().let { - if (it) { - Log.d("ReVanced", "Handle whoToFollow promoted user $index $item") - userRemoveIndex.add(index) - } - } - } - for (i in userRemoveIndex.reversed()) { - items?.remove(i) - } - } - for (i in entryRemoveIndex.reversed()) { - remove(i) - } - } - - fun hideRecommendedUsers(json: JSONObject) { - json.filterInstructions { it.entriesRemoveWhoToFollow() } - json.jsonCheckAndRemoveRecommendedUsers() - } - - fun hidePromotedAds(json: JSONObject) { - json.filterInstructions { it.entriesRemoveAnnoyance() } - json.jsonGetData()?.dataCheckAndRemove() - } - - fun openWithChooser(context: Context, intent: Intent) { - context.startActivity( - Intent.createChooser( - Intent( - "android.intent.action.VIEW", - Uri.parse(intent.dataString) - ), "" - ) - ) - } - - private fun JSONObject.filterInstructions(action: (JSONArray) -> Unit) { - jsonGetInstructions()?.forEach { instruction -> - instruction.instructionCheckAndRemove(action) - } - } -} diff --git a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFuckerUtils.kt b/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFuckerUtils.kt deleted file mode 100644 index f6c05e1fb4..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/patches/hook/twifucker/TwiFuckerUtils.kt +++ /dev/null @@ -1,22 +0,0 @@ -package app.revanced.integrations.twitter.patches.hook.twifucker - -import org.json.JSONArray -import org.json.JSONObject - -internal object TwiFuckerUtils { - inline fun JSONArray.forEach(action: (JSONObject) -> Unit) { - (0 until this.length()).forEach { i -> - if (this[i] is JSONObject) { - action(this[i] as JSONObject) - } - } - } - - inline fun JSONArray.forEachIndexed(action: (index: Int, JSONObject) -> Unit) { - (0 until this.length()).forEach { i -> - if (this[i] is JSONObject) { - action(i, this[i] as JSONObject) - } - } - } -} diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java b/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java index a92ba63fcf..1b49fc49d5 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/Settings.java @@ -9,6 +9,19 @@ public class Settings extends BaseSettings { public static final StringSetting VID_SUBFOLDER = new StringSetting("vid_subfolder", "Twitter"); public static final BooleanSetting MISC_FONT = new BooleanSetting("misc_font", false); + public static final BooleanSetting MISC_HIDE_FAB = new BooleanSetting("misc_hide_fab", true); + public static final BooleanSetting MISC_HIDE_RECOMMENDED_USERS = new BooleanSetting("misc_hide_recommended_users", true); + public static final BooleanSetting MISC_HIDE_COMM_NOTES = new BooleanSetting("misc_hide_comm_notes", false); + public static final BooleanSetting MISC_HIDE_VIEW_COUNT = new BooleanSetting("misc_hide_view_count", true); + + public static final BooleanSetting ADS_HIDE_PROMOTED_TRENDS = new BooleanSetting("ads_hide_promoted_trends", true); + public static final BooleanSetting ADS_HIDE_PROMOTED_POSTS = new BooleanSetting("ads_hide_promoted_posts", true); + public static final BooleanSetting ADS_HIDE_GOOGLE_ADS = new BooleanSetting("ads_hide_google_ads", true); + public static final BooleanSetting ADS_HIDE_WHO_TO_FOLLOW = new BooleanSetting("ads_hide_who_to_follow", true); + public static final BooleanSetting ADS_HIDE_CREATORS_TO_SUB = new BooleanSetting("ads_hide_creators_to_sub", true); + public static final BooleanSetting ADS_HIDE_COMM_TO_JOIN = new BooleanSetting("ads_hide_comm_to_join", true); + public static final BooleanSetting ADS_HIDE_REVISIT_BMK = new BooleanSetting("ads_hide_revisit_bookmark", true); + public static final BooleanSetting ADS_HIDE_DETAILED_POSTS = new BooleanSetting("ads_hide_detailed_posts", true); public static final BooleanSetting TIMELINE_HIDE_LIVETHREADS = new BooleanSetting("timeline_hide_livethreads", true); public static final BooleanSetting TIMELINE_HIDE_BANNER = new BooleanSetting("timeline_hide_banner", true); diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsActivity.java b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsActivity.java index c8fcfc9fe7..1255ee379e 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsActivity.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsActivity.java @@ -37,33 +37,157 @@ public void onCreate(@Nullable Bundle savedInstanceState) { context = getContext(); PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context); - SettingsStatus.load(); + // SettingsStatus.load(); if (SettingsStatus.changeDownloadEnabled) { LegacyTwitterPreferenceCategory downloadPrefs = preferenceCategory("Download", screen); downloadPrefs.addPreference(listPreference( - "Public Folder", + "Public folder", "The public folder to use for video downloads", Settings.VID_PUBLIC_FOLDER )); downloadPrefs.addPreference(editTextPreference( - "Download Subfolder", + "Download subfolder", "The subfolder to download videos to ([PublicFolder]/[Subfolder])", Settings.VID_SUBFOLDER )); } - if (SettingsStatus.enableFontMod) { + if(SettingsStatus.enableAdsSection()){ + LegacyTwitterPreferenceCategory adsPrefs = preferenceCategory("Ads", screen); + + if (SettingsStatus.hideAds) { + adsPrefs.addPreference( + switchPreference( + "Hide promoted posts", + "", + Settings.ADS_HIDE_PROMOTED_POSTS + ) + ); + } + + if (SettingsStatus.hideGAds) { + adsPrefs.addPreference( + switchPreference( + "Hide google ads", + "", + Settings.ADS_HIDE_GOOGLE_ADS + ) + ); + } + if (SettingsStatus.hideWTF) { + adsPrefs.addPreference( + switchPreference( + "Hide \"Who to follow\" section", + "", + Settings.ADS_HIDE_WHO_TO_FOLLOW + ) + ); + } + + if (SettingsStatus.hideCTS) { + adsPrefs.addPreference( + switchPreference( + "Hide \"Creators to subscribe\" section", + "", + Settings.ADS_HIDE_CREATORS_TO_SUB + ) + ); + } + + if (SettingsStatus.hideCTJ) { + adsPrefs.addPreference( + switchPreference( + "Hide \"Community to join\" section", + "", + Settings.ADS_HIDE_COMM_TO_JOIN + ) + ); + } + + if (SettingsStatus.hideRBMK) { + adsPrefs.addPreference( + switchPreference( + "Hide \"Revist your bookmark\" section", + "", + Settings.ADS_HIDE_REVISIT_BMK + ) + ); + } + + if (SettingsStatus.hideDetailedPosts) { + adsPrefs.addPreference( + switchPreference( + "Hide detailed posts (in replies)", + "", + Settings.ADS_HIDE_DETAILED_POSTS + ) + ); + } + + if (SettingsStatus.hidePromotedTrend) { + adsPrefs.addPreference( + switchPreference( + "Hide promoted trends", + "", + Settings.ADS_HIDE_PROMOTED_TRENDS + ) + ); + } + + + + } + + if (SettingsStatus.enableMiscSection()) { LegacyTwitterPreferenceCategory miscPrefs = preferenceCategory("Misc", screen); if (SettingsStatus.enableFontMod) { miscPrefs.addPreference( switchPreference( - "Enable Chirp Font", + "Enable chirp font", "", Settings.MISC_FONT ) ); } + if (SettingsStatus.hideFAB) { + miscPrefs.addPreference( + switchPreference( + "Hide floating action button", + "", + Settings.MISC_HIDE_FAB + ) + ); + } + + if (SettingsStatus.hideRecommendedUsers) { + miscPrefs.addPreference( + switchPreference( + "Hide recommended users", + "", + Settings.MISC_HIDE_RECOMMENDED_USERS + ) + ); + } + + if (SettingsStatus.hideCommunityNote) { + miscPrefs.addPreference( + switchPreference( + "Hide community notes", + "", + Settings.MISC_HIDE_COMM_NOTES + ) + ); + } + if (SettingsStatus.hideViewCount) { + miscPrefs.addPreference( + switchPreference( + "Hide view count", + "", + Settings.MISC_HIDE_VIEW_COUNT + ) + ); + } } if (SettingsStatus.enableTimelineSection()) { @@ -71,27 +195,25 @@ public void onCreate(@Nullable Bundle savedInstanceState) { if (SettingsStatus.hideForyou) { timelinePrefs.addPreference( switchPreference( - "Hide For You", + "Hide for you tab", "", Settings.TIMELINE_HIDE_FORYOU ) ); } - if (SettingsStatus.hideLiveThreads) { timelinePrefs.addPreference( switchPreference( - "Hide Live Threads", + "Hide live threads", "", Settings.TIMELINE_HIDE_LIVETHREADS ) ); } - if (SettingsStatus.hideBanner) { timelinePrefs.addPreference( switchPreference( - "Hide Banner", + "Hide banner", "", Settings.TIMELINE_HIDE_BANNER ) diff --git a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java index a1d01b95a2..4abd1a0079 100644 --- a/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java +++ b/app/src/main/java/app/revanced/integrations/twitter/settings/SettingsStatus.java @@ -3,18 +3,47 @@ public class SettingsStatus { public static boolean changeDownloadEnabled = false; public static boolean enableFontMod = false; + public static boolean hideRecommendedUsers = false; + public static boolean hidePromotedTrend = false; + public static boolean hideCommunityNote = false; + public static boolean hideFAB = false; + public static boolean hideViewCount = false; public static boolean hideLiveThreads = false; public static boolean hideBanner = false; public static boolean hideForyou = false; + public static boolean hideAds = false; + public static boolean hideGAds = false; + public static boolean hideWTF = false; + public static boolean hideCTS = false; + public static boolean hideCTJ = false; + public static boolean hideDetailedPosts = false; + public static boolean hideRBMK = false; + public static void enableDownloadFolder() { changeDownloadEnabled = true; } public static void enableFont() { enableFontMod = true; } + public static void hideRecommendedUsers() { hideRecommendedUsers = true; } + public static void hideCommunityNotes() { hideCommunityNote = true; } + public static void hideFAB() { hideFAB = true; } + public static void hideViewCount() { hideViewCount = true; } public static void hideLiveThreads() { hideLiveThreads = true; } public static void hideBanner() { hideBanner = true; } public static void hideForYou() { hideForyou = true; } - public static boolean enableTimelineSection(){return (hideLiveThreads || hideBanner ||hideForyou);} + public static void hideAds() { hideAds = true; } + public static void hideGAds() { hideGAds = true; } + public static void hideWhoToFollow() { hideWTF = true; } + public static void hideCreatorsToSub() { hideCTS = true; } + public static void hideCommToJoin() { hideCTJ = true; } + public static void hideDetailedPost() { hideDetailedPosts = true; } + public static void hideRevistBookmark() { hideRBMK = true; } + public static void hidePromotedTrends() { hidePromotedTrend = true; } + + public static boolean enableTimelineSection(){ return (hideLiveThreads || hideBanner || hideForyou); } + public static boolean enableMiscSection() { return (enableFontMod || hideRecommendedUsers || hideFAB || hideViewCount || hideCommunityNote); } + public static boolean enableAdsSection() {return (hideAds|| hideGAds || hideWTF || hideCTS || hideCTJ || hideDetailedPosts || hideRBMK ||hidePromotedTrend); } + public static void load() {} } diff --git a/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt b/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt deleted file mode 100644 index 4b7a5002a6..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/utils/json/JsonUtils.kt +++ /dev/null @@ -1,13 +0,0 @@ -package app.revanced.integrations.twitter.utils.json - -import app.revanced.integrations.twitter.utils.stream.StreamUtils -import org.json.JSONException -import org.json.JSONObject -import java.io.IOException -import java.io.InputStream - -object JsonUtils { - @JvmStatic - @Throws(IOException::class, JSONException::class) - fun parseJson(jsonInputStream: InputStream) = JSONObject(StreamUtils.toString(jsonInputStream)) -} \ No newline at end of file diff --git a/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt b/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt deleted file mode 100644 index 7e008eb849..0000000000 --- a/app/src/main/java/app/revanced/integrations/twitter/utils/stream/StreamUtils.kt +++ /dev/null @@ -1,24 +0,0 @@ -package app.revanced.integrations.twitter.utils.stream - -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import java.io.IOException -import java.io.InputStream - -object StreamUtils { - @Throws(IOException::class) - fun toString(inputStream: InputStream): String { - ByteArrayOutputStream().use { result -> - val buffer = ByteArray(1024) - var length: Int - while (inputStream.read(buffer).also { length = it } != -1) { - result.write(buffer, 0, length) - } - return result.toString() - } - } - - fun fromString(string: String): InputStream { - return ByteArrayInputStream(string.toByteArray()) - } -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index a7eb985628..1792043e00 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ org.gradle.parallel = true org.gradle.caching = true android.useAndroidX = true -version = 1.5.0 +version = 1.6.0-dev.5