commit 4b52f95c54373307ee8a57910fabe2a92e53361a
parent 007c2a60935224d717c2a2026af7431a8dbdc2f5
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Fri, 19 May 2023 00:58:08 +0200

refacto: suppress warnings & clean code

Diffstat:
Mapp/src/main/kotlin/me/rhunk/snapenhance/bridge/service/BridgeService.kt | 6++++--
Mapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/extras/Notifications.kt | 1+
Mapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/UITweaks.kt | 23+++++++++++++----------
Mapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/FriendFeedInfoMenu.kt | 2+-
Mapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt | 6++----
Mapp/src/main/kotlin/me/rhunk/snapenhance/manager/impl/MappingManager.kt | 4++--
6 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/bridge/service/BridgeService.kt b/app/src/main/kotlin/me/rhunk/snapenhance/bridge/service/BridgeService.kt @@ -1,5 +1,6 @@ package me.rhunk.snapenhance.bridge.service +import android.annotation.SuppressLint import android.app.DownloadManager import android.app.Service import android.content.* @@ -62,7 +63,7 @@ class BridgeService : Service() { BridgeMessageType.LOCALE_REQUEST -> { with(LocaleRequest()) { read(msg.data) - handleLocaleRequest(this) { message -> + handleLocaleRequest { message -> replyMessenger.send(message) } } @@ -119,7 +120,7 @@ class BridgeService : Service() { reply(MessageLoggerResult(true).toMessage(BridgeMessageType.MESSAGE_LOGGER_RESULT.value)) } - private fun handleLocaleRequest(msg: LocaleRequest, reply: (Message) -> Unit) { + private fun handleLocaleRequest(reply: (Message) -> Unit) { val deviceLocale = Locale.getDefault().toString() val compatibleLocale = resources.assets.list("lang")?.find { it.startsWith(deviceLocale) }?.substring(0, 5) ?: "en_US" @@ -129,6 +130,7 @@ class BridgeService : Service() { } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") private fun handleDownloadContent(msg: DownloadContentRequest, reply: (Message) -> Unit) { if (!msg.url!!.startsWith("http://127.0.0.1:")) return diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/extras/Notifications.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/extras/Notifications.kt @@ -142,6 +142,7 @@ class Notifications : Feature("Notifications", loadParams = FeatureLoadParams.IN return@onEach }.onFailure { Logger.xposedLog("Failed to send preview notification", it) + Logger.debug("urlKey: $urlKey") } } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/UITweaks.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/UITweaks.kt @@ -1,5 +1,6 @@ package me.rhunk.snapenhance.features.impl.ui +import android.annotation.SuppressLint import android.view.View import android.view.ViewGroup import me.rhunk.snapenhance.Constants @@ -10,6 +11,7 @@ import me.rhunk.snapenhance.hook.HookStage import me.rhunk.snapenhance.hook.Hooker class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) { + @SuppressLint("DiscouragedApi") override fun onActivityCreate() { val resources = context.resources @@ -26,6 +28,10 @@ class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CRE if (viewId == chatNoteRecordButton && context.config.bool(ConfigProperty.REMOVE_VOICE_RECORD_BUTTON)) { methodParam.setArg(0, View.GONE) } + if (viewId == callButton1 || viewId == callButton2) { + if (!context.config.bool(ConfigProperty.REMOVE_CALL_BUTTONS)) return@hook + methodParam.setArg(0, View.GONE) + } } //TODO: use the event bus to dispatch a addView event @@ -45,16 +51,13 @@ class UITweaks : Feature("UITweaks", loadParams = FeatureLoadParams.ACTIVITY_CRE if (chatInputBarSticker == viewId && context.config.bool(ConfigProperty.REMOVE_STICKERS_BUTTON)) { view.visibility = View.GONE } - if (context.config.bool(ConfigProperty.REMOVE_CALL_BUTTONS)) { - if (viewId == callButton1 || viewId == callButton2) { - if (view.visibility == View.GONE) return@hook - Hooker.ephemeralHookObjectMethod(View::class.java, view, "setVisibility", HookStage.BEFORE) { param -> - param.setArg(0, View.GONE) - } - } - if (viewId == callButtonsStub) { - param.setResult(null) - } + if (viewId == callButton1 || viewId == callButton2) { + if (!context.config.bool(ConfigProperty.REMOVE_CALL_BUTTONS)) return@hook + if (view.visibility == View.GONE) return@hook + } + if (viewId == callButtonsStub) { + if (!context.config.bool(ConfigProperty.REMOVE_CALL_BUTTONS)) return@hook + param.setResult(null) } } } diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/FriendFeedInfoMenu.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/FriendFeedInfoMenu.kt @@ -179,7 +179,7 @@ class FriendFeedInfoMenu : AbstractMenu() { previewButton.text = context.translation.get("friend_menu_option.preview") applyTheme(viewModel, previewButton) val finalFocusedConversationTargetUser = focusedConversationTargetUser - previewButton.setOnClickListener { v: View? -> + previewButton.setOnClickListener { showPreview( finalFocusedConversationTargetUser, conversationId, diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/impl/SettingsMenu.kt @@ -101,11 +101,9 @@ class SettingsMenu : AbstractMenu() { } @SuppressLint("SetTextI18n") + @Suppress("deprecation") fun inject(viewModel: View, addView: (View) -> Unit) { - val packageInfo = viewModel.context.packageManager.getPackageInfo( - Constants.SNAPCHAT_PACKAGE_NAME, - 0 - ) + val packageInfo = viewModel.context.packageManager.getPackageInfo(Constants.SNAPCHAT_PACKAGE_NAME, 0) val versionTextBuilder = StringBuilder() versionTextBuilder.append("SnapEnhance ").append(BuildConfig.VERSION_NAME) .append(" by rhunk") diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/MappingManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/MappingManager.kt @@ -3,7 +3,6 @@ package me.rhunk.snapenhance.manager.impl import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonParser -import dalvik.system.DexFile import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -33,6 +32,7 @@ class MappingManager(private val context: ModContext) : Manager { private val mappings = ConcurrentHashMap<String, Any>() private var snapBuildNumber = 0 + @Suppress("deprecation") override fun init() { val currentBuildNumber = context.androidContext.packageManager.getPackageInfo( Constants.SNAPCHAT_PACKAGE_NAME, @@ -113,7 +113,7 @@ class MappingManager(private val context: ModContext) : Manager { val dexElements = dexPathList.getObjectField("dexElements") as Array<Any> dexElements.forEach { dexElement: Any -> - (dexElement.getObjectField("dexFile") as DexFile?)?.apply { + (dexElement.getObjectField("dexFile") as dalvik.system.DexFile?)?.apply { entries().toList().forEach fileList@{ className -> //ignore classes without a dot in them if (className.contains(".") && !className.startsWith("com.snap")) return@fileList