feat: anti auto save
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
"tweaks": "Tweaks",
|
||||
"experimental": "Experimental"
|
||||
},
|
||||
|
||||
"action": {
|
||||
"clean_cache": "Clean Cache"
|
||||
},
|
||||
|
||||
"property": {
|
||||
"save_folder": "Save Folder",
|
||||
@@ -32,6 +36,7 @@
|
||||
"message_preview_length": "Message Preview Length",
|
||||
"external_media_as_snap": "External Media As Snap",
|
||||
"auto_save": "Auto Save",
|
||||
"anti_auto_save": "Anti Auto Save Button",
|
||||
"snapchat_plus": "Snapchat Plus",
|
||||
"remove_voice_record_button": "Remove Voice Record Button",
|
||||
"remove_stickers_button": "Remove Stickers Button",
|
||||
@@ -48,7 +53,8 @@
|
||||
"friend_menu_option": {
|
||||
"preview": "Preview",
|
||||
"stealth_mode": "Stealth Mode",
|
||||
"anti_auto_download": "Anti Auto Download"
|
||||
"anti_auto_download": "Anti Auto Download",
|
||||
"anti_auto_save": "Anti Auto Save"
|
||||
},
|
||||
|
||||
"message_context_menu_option": {
|
||||
|
||||
@@ -121,6 +121,7 @@ enum class ConfigProperty(
|
||||
false
|
||||
),
|
||||
AUTO_SAVE("property.auto_save", "description.auto_save", ConfigCategory.EXTRAS, false),
|
||||
ANTI_AUTO_SAVE("property.anti_auto_save", "description.anti_auto_save", ConfigCategory.EXTRAS, false),
|
||||
SNAPCHAT_PLUS("property.snapchat_plus", "description.snapchat_plus", ConfigCategory.EXTRAS, false),
|
||||
|
||||
REMOVE_VOICE_RECORD_BUTTON(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.rhunk.snapenhance.features.impl.extras
|
||||
|
||||
import me.rhunk.snapenhance.bridge.common.impl.file.BridgeFileType
|
||||
import me.rhunk.snapenhance.features.BridgeFileFeature
|
||||
import me.rhunk.snapenhance.features.FeatureLoadParams
|
||||
|
||||
class AntiAutoSave : BridgeFileFeature("AntiAutoSave", BridgeFileType.ANTI_AUTO_SAVE, loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
|
||||
override fun onActivityCreate() {
|
||||
readFile()
|
||||
}
|
||||
|
||||
fun setConversationIgnored(userId: String, state: Boolean) {
|
||||
setState(userId.hashCode().toLong().toString(16), state)
|
||||
}
|
||||
|
||||
fun isConversationIgnored(userId: String): Boolean {
|
||||
return exists(userId.hashCode().toLong().toString(16))
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,10 @@ class AutoSave : Feature("Auto Save", loadParams = FeatureLoadParams.ACTIVITY_CR
|
||||
|
||||
private fun canSave(): Boolean {
|
||||
with(context.feature(Messaging::class)) {
|
||||
if (lastOpenedConversationUUID == null || context.feature(StealthMode::class).isStealth(lastOpenedConversationUUID.toString())) return@canSave false
|
||||
if (lastOpenedConversationUUID == null) return@canSave false
|
||||
val conversation = lastOpenedConversationUUID.toString()
|
||||
if (context.feature(StealthMode::class).isStealth(conversation)) return@canSave false
|
||||
if (context.feature(AntiAutoSave::class).isConversationIgnored(conversation)) return@canSave false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import me.rhunk.snapenhance.database.objects.FriendInfo
|
||||
import me.rhunk.snapenhance.database.objects.UserConversationLink
|
||||
import me.rhunk.snapenhance.features.impl.Messaging
|
||||
import me.rhunk.snapenhance.features.impl.downloader.AntiAutoDownload
|
||||
import me.rhunk.snapenhance.features.impl.extras.AntiAutoSave
|
||||
import me.rhunk.snapenhance.features.impl.spy.StealthMode
|
||||
import me.rhunk.snapenhance.features.impl.ui.menus.AbstractMenu
|
||||
import me.rhunk.snapenhance.features.impl.ui.menus.ViewAppearanceHelper.applyTheme
|
||||
@@ -163,6 +164,17 @@ class FriendFeedInfoMenu : AbstractMenu() {
|
||||
builder.show()
|
||||
}
|
||||
|
||||
private fun createToggleFeature(viewModel: View, viewConsumer: ((View) -> Unit), text: String, isChecked: () -> Boolean, toggle: (Boolean) -> Unit) {
|
||||
val switch = Switch(viewModel.context)
|
||||
switch.text = context.translation.get(text)
|
||||
switch.isChecked = isChecked()
|
||||
applyTheme(viewModel, switch)
|
||||
switch.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
|
||||
toggle(isChecked)
|
||||
}
|
||||
viewConsumer(switch)
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n", "UseSwitchCompatOrMaterialCode", "DefaultLocale")
|
||||
fun inject(viewModel: View, viewConsumer: ((View) -> Unit)) {
|
||||
val messaging = context.feature(Messaging::class)
|
||||
@@ -201,21 +213,27 @@ class FriendFeedInfoMenu : AbstractMenu() {
|
||||
)
|
||||
}
|
||||
|
||||
if (context.config.bool(ConfigProperty.ANTI_DOWNLOAD_BUTTON)) {
|
||||
val userId = context.database.getFriendFeedInfoByConversationId(conversationId)?.friendUserId ?: return
|
||||
run {
|
||||
val userId = context.database.getFriendFeedInfoByConversationId(conversationId)?.friendUserId ?: return@run
|
||||
if (context.config.bool(ConfigProperty.ANTI_DOWNLOAD_BUTTON)) {
|
||||
createToggleFeature(viewModel,
|
||||
viewConsumer,
|
||||
"friend_menu_option.anti_auto_download",
|
||||
{ context.feature(AntiAutoDownload::class).isUserIgnored(userId) },
|
||||
{ context.feature(AntiAutoDownload::class).setUserIgnored(userId, it) }
|
||||
)
|
||||
}
|
||||
|
||||
val antiAutoDownload = Switch(viewModel.context)
|
||||
antiAutoDownload.text = context.translation.get("friend_menu_option.anti_auto_download")
|
||||
antiAutoDownload.isChecked = context.feature(AntiAutoDownload::class).isUserIgnored(userId)
|
||||
applyTheme(viewModel, antiAutoDownload)
|
||||
antiAutoDownload.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
|
||||
context.feature(AntiAutoDownload::class).setUserIgnored(
|
||||
userId,
|
||||
isChecked
|
||||
if (context.config.bool(ConfigProperty.ANTI_AUTO_SAVE)) {
|
||||
createToggleFeature(viewModel,
|
||||
viewConsumer,
|
||||
"friend_menu_option.anti_auto_save",
|
||||
{ context.feature(AntiAutoSave::class).isConversationIgnored(conversationId) },
|
||||
{ context.feature(AntiAutoSave::class).setConversationIgnored(conversationId, it) }
|
||||
)
|
||||
}
|
||||
viewConsumer(antiAutoDownload)
|
||||
}
|
||||
|
||||
viewConsumer(stealthSwitch)
|
||||
viewConsumer(previewButton)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import me.rhunk.snapenhance.features.impl.ConfigEnumKeys
|
||||
import me.rhunk.snapenhance.features.impl.Messaging
|
||||
import me.rhunk.snapenhance.features.impl.downloader.AntiAutoDownload
|
||||
import me.rhunk.snapenhance.features.impl.downloader.MediaDownloader
|
||||
import me.rhunk.snapenhance.features.impl.extras.AntiAutoSave
|
||||
import me.rhunk.snapenhance.features.impl.extras.AutoSave
|
||||
import me.rhunk.snapenhance.features.impl.extras.ExternalMediaAsSnap
|
||||
import me.rhunk.snapenhance.features.impl.extras.Notifications
|
||||
@@ -62,6 +63,7 @@ class FeatureManager(private val context: ModContext) : Manager {
|
||||
register(ConfigEnumKeys::class)
|
||||
register(AntiAutoDownload::class)
|
||||
register(ExternalMediaAsSnap::class)
|
||||
register(AntiAutoSave::class)
|
||||
|
||||
initializeFeatures()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user