commit 45f4c65ab336ccb78f55bdc9b5856e722f7d4e10
parent a879419fc5418e3407293ce1ad6928941ea62f6f
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 29 Oct 2023 13:17:09 +0100

fix(core): old bitmoji selfie

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 10+++++++---
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/OldBitmojiSelfie.kt | 25++++++++++++++++++-------
3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -274,9 +274,9 @@ "name": "Hide UI Components", "description": "Select which UI components to hide" }, - "2d_bitmoji_selfie": { - "name": "2D Bitmoji Selfie", - "description": "Brings back the 2D Bitmoji selfies from older Snapchat versions\nYou may need to clean the Snapchat cache for this to take effect" + "old_bitmoji_selfie": { + "name": "Old Bitmoji Selfie", + "description": "Brings back the Bitmoji selfies from older Snapchat versions" }, "disable_spotlight": { "name": "Disable Spotlight", @@ -693,6 +693,10 @@ "bypass_video_length_restriction": { "single": "Single media", "split": "Split media" + }, + "old_bitmoji_selfie": { + "2d": "2D Bitmoji", + "3d": "3D Bitmoji" } } }, diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt @@ -41,7 +41,7 @@ class UserInterfaceTweaks : ConfigContainer() { "hide_chat_call_buttons", "hide_profile_call_buttons" ) { requireRestart() } - val ddBitmojiSelfie = boolean("2d_bitmoji_selfie") { requireCleanCache() } + val oldBitmojiSelfie = unique("old_bitmoji_selfie", "2d", "3d") { requireCleanCache() } val disableSpotlight = boolean("disable_spotlight") { requireRestart() } val storyViewerOverride = unique("story_viewer_override", "DISCOVER_PLAYBACK_SEEKBAR", "VERTICAL_STORY_VIEWER") { requireRestart() } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/OldBitmojiSelfie.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/OldBitmojiSelfie.kt @@ -1,5 +1,6 @@ package me.rhunk.snapenhance.core.features.impl.ui +import android.net.Uri import me.rhunk.snapenhance.common.util.snap.BitmojiSelfie import me.rhunk.snapenhance.core.event.events.impl.NetworkApiRequestEvent import me.rhunk.snapenhance.core.features.Feature @@ -8,15 +9,25 @@ import me.rhunk.snapenhance.core.features.FeatureLoadParams class OldBitmojiSelfie : Feature("OldBitmojiSelfie", loadParams = FeatureLoadParams.INIT_SYNC) { override fun init() { val urlPrefixes = arrayOf("https://images.bitmoji.com/3d/render/", "https://cf-st.sc-cdn.net/3d/render/") - val state by context.config.userInterface.ddBitmojiSelfie + val oldBitmojiSelfie = context.config.userInterface.oldBitmojiSelfie.getNullable() ?: return - context.event.subscribe(NetworkApiRequestEvent::class, { state }) { event -> + context.event.subscribe(NetworkApiRequestEvent::class) { event -> if (urlPrefixes.firstOrNull { event.url.startsWith(it) } == null) return@subscribe - val bitmojiURI = event.url.substringAfterLast("/") - event.url = - BitmojiSelfie.BitmojiSelfieType.STANDARD.prefixUrl + - bitmojiURI + - (bitmojiURI.takeIf { !it.contains("?") }?.let { "?" } ?: "&") + "transparent=1" + event.url = event.url.replace("ua=1", "") // replace ua=1 with nothing for old 3d selfies/background + + // replace with old 2d selfies + if (oldBitmojiSelfie == "2d" && event.url.contains("trim=circle")) { + val bitmojiPath = event.url.substringAfterLast("/").substringBeforeLast("?") + event.url = Uri.parse(BitmojiSelfie.BitmojiSelfieType.STANDARD.prefixUrl) + .buildUpon() + .appendPath(bitmojiPath) + .appendQueryParameter("transparent", "1") + .appendQueryParameter("trim", "circle") + .build() + .toString() + } + + if (arrayOf("?", "&").any { event.url.endsWith(it) }) event.url = event.url.dropLast(1) } } } \ No newline at end of file