Skip to content

Commit

Permalink
feat(core): edit text override
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Dec 4, 2023
1 parent ce2fe64 commit 35016b5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/src/main/assets/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@
"fidelius_indicator": {
"name": "Fidelius Indicator",
"description": "Adds a green circle next to messages that have been sent only to you"
},
"edit_text_override": {
"name": "Edit Text Override",
"description": "Overrides text field behavior"
}
}
},
Expand Down Expand Up @@ -795,6 +799,10 @@
"auto_reload": {
"snapchat_only": "Snapchat Only",
"all": "All (Snapchat + SnapEnhance)"
},
"edit_text_override": {
"multi_line_chat_input": "Multi Line Chat Input",
"bypass_text_input_limit": "Bypass Text Input Limit"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ class UserInterfaceTweaks : ConfigContainer() {
val hideSettingsGear = boolean("hide_settings_gear") { requireRestart() }
val verticalStoryViewer = boolean("vertical_story_viewer") { requireRestart() }
val fideliusIndicator = boolean("fidelius_indicator") { requireRestart() }
val editTextOverride = multiple("edit_text_override", "multi_line_chat_input", "bypass_text_input_limit") {
requireRestart(); addNotices(FeatureNotice.BAN_RISK, FeatureNotice.INTERNAL_BEHAVIOR)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.rhunk.snapenhance.core.features.impl.ui

import android.text.InputFilter
import android.text.InputType
import android.widget.EditText
import android.widget.TextView
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.hook
import me.rhunk.snapenhance.core.util.hook.hookConstructor

class EditTextOverride : Feature("Edit Text Override", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
override fun onActivityCreate() {
val editTextOverride by context.config.userInterface.editTextOverride
if (editTextOverride.isEmpty()) return

if (editTextOverride.contains("bypass_text_input_limit")) {
TextView::class.java.getMethod("setFilters", Array<InputFilter>::class.java)
.hook(HookStage.BEFORE) { param ->
param.setArg(0, param.arg<Array<InputFilter>>(0).filter {
it !is InputFilter.LengthFilter
}.toTypedArray())
}
}

if (editTextOverride.contains("multi_line_chat_input")) {
findClass("com.snap.messaging.chat.features.input.InputBarEditText").apply {
hookConstructor(HookStage.AFTER) { param ->
val editText = param.thisObject<EditText>()
editText.inputType = editText.inputType or InputType.TYPE_TEXT_FLAG_MULTI_LINE
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class FeatureManager(
Stories::class,
DisableComposerModules::class,
FideliusIndicator::class,
EditTextOverride::class,
)

initializeFeatures()
Expand Down

0 comments on commit 35016b5

Please sign in to comment.