commit b232dbc0563d01c2d93fd5e37eb9a75d27c0687b
parent 3b0b44fcd44fa67e7a7eacc5c61a003975230191
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Mon, 27 Nov 2023 21:19:34 +0100

feat: fidelius indicator

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/UserInterfaceTweaks.kt | 1+
Acore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/FideliusIndicator.kt | 43+++++++++++++++++++++++++++++++++++++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt | 1+
4 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -314,6 +314,10 @@ "enable_friend_feed_menu_bar": { "name": "Friend Feed Menu Bar", "description": "Enables the new Friend Feed Menu Bar" + }, + "fidelius_indicator": { + "name": "Fidelius Indicator", + "description": "Adds a green circle next to messages that have been sent only to you" } } }, 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 @@ -47,4 +47,5 @@ class UserInterfaceTweaks : ConfigContainer() { val disableSpotlight = boolean("disable_spotlight") { requireRestart() } val hideSettingsGear = boolean("hide_settings_gear") { requireRestart() } val verticalStoryViewer = boolean("vertical_story_viewer") { requireRestart() } + val fideliusIndicator = boolean("fidelius_indicator") { requireRestart() } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/FideliusIndicator.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/ui/FideliusIndicator.kt @@ -0,0 +1,42 @@ +package me.rhunk.snapenhance.core.features.impl.ui + +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.drawable.ShapeDrawable +import android.graphics.drawable.shapes.Shape +import me.rhunk.snapenhance.common.data.ContentType +import me.rhunk.snapenhance.common.util.protobuf.ProtoReader +import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent +import me.rhunk.snapenhance.core.features.Feature +import me.rhunk.snapenhance.core.features.FeatureLoadParams +import me.rhunk.snapenhance.core.ui.addForegroundDrawable +import me.rhunk.snapenhance.core.ui.removeForegroundDrawable + +class FideliusIndicator : Feature("Fidelius Indicator", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { + override fun onActivityCreate() { + if (!context.config.userInterface.fideliusIndicator.get()) return + + context.event.subscribe(BindViewEvent::class) { event -> + event.chatMessage { _, messageId -> + event.view.removeForegroundDrawable("fideliusIndicator") + + val message = context.database.getConversationMessageFromId(messageId.toLong()) ?: return@chatMessage + if (message.senderId == context.database.myUserId) return@chatMessage + if (message.contentType != ContentType.SNAP.id && message.contentType != ContentType.EXTERNAL_MEDIA.id) return@chatMessage + + if (!ProtoReader(message.messageContent ?: return@chatMessage).containsPath(4, 3, 3, 6)) return@chatMessage + + event.view.addForegroundDrawable("fideliusIndicator", ShapeDrawable(object: Shape() { + override fun draw(canvas: Canvas, paint: Paint) { + val margin = 25f + val radius = 15f + + canvas.drawCircle(margin + radius, canvas.height - margin - radius, radius, paint.apply { + color = 0xFF00FF00.toInt() + }) + } + })) + } + } + } +}+ \ No newline at end of file diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/manager/impl/FeatureManager.kt @@ -110,6 +110,7 @@ class FeatureManager( DisableConfirmationDialogs::class, Stories::class, DisableComposerModules::class, + FideliusIndicator::class, ) initializeFeatures()