From b0ad4596cd462a4578e0eb14cbfd96a808438300 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 28 Jan 2025 23:06:36 +0800 Subject: [PATCH 1/5] chore: ColorOS Show Clipboard Toast --- .../java/org/telegram/messenger/AndroidUtilities.java | 7 ++++++- .../kotlin/xyz/nextalone/nagram/helper/ColorOsHelper.kt | 8 ++++++++ bin/scripts/requirements.txt | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ColorOsHelper.kt diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java index b7cc14c724..49ed33d83a 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java @@ -220,6 +220,7 @@ import tw.nekomimi.nekogram.utils.EnvUtil; import tw.nekomimi.nekogram.utils.FileUtil; import tw.nekomimi.nekogram.utils.TelegramUtil; +import xyz.nextalone.nagram.helper.ColorOsHelper; public class AndroidUtilities { public final static int LIGHT_STATUS_BAR_OVERLAY = 0x0f000000, DARK_STATUS_BAR_OVERLAY = 0x33000000; @@ -3442,7 +3443,11 @@ public static void shakeViewSpring(View view, float shiftDp, Runnable endCallbac // } public static boolean shouldShowClipboardToast() { - return (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || !OneUIUtilities.hasBuiltInClipboardToasts()) && (Build.VERSION.SDK_INT < 32 || XiaomiUtilities.isMIUI()); + boolean origin = (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || !OneUIUtilities.hasBuiltInClipboardToasts()) && Build.VERSION.SDK_INT < 32; + if (origin) return true; + boolean isMIUI = XiaomiUtilities.isMIUI(); + boolean isColorOS = ColorOsHelper.INSTANCE.isColorOS(); + return isMIUI || isColorOS; } public static boolean addToClipboard(CharSequence str) { diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ColorOsHelper.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ColorOsHelper.kt new file mode 100644 index 0000000000..debed5297b --- /dev/null +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ColorOsHelper.kt @@ -0,0 +1,8 @@ +package xyz.nextalone.nagram.helper + +import org.telegram.messenger.AndroidUtilities + +object ColorOsHelper { + val isColorOS: Boolean = + AndroidUtilities.getSystemProperty("ro.build.version.oplusrom") != null +} diff --git a/bin/scripts/requirements.txt b/bin/scripts/requirements.txt index 24a0ea49e4..e2c8d6c183 100644 --- a/bin/scripts/requirements.txt +++ b/bin/scripts/requirements.txt @@ -1,2 +1,2 @@ -git+https://github.com/KurimuzonAkuma/pyrogram -PyroTgCrypto==1.2.6a0 +git+https://github.com/TeamPGM/pyrogram +PyroTgCrypto==1.2.7 From 68cf7092078c68322a2c9a637e983ece8d335d8d Mon Sep 17 00:00:00 2001 From: risin42 <5331402+risin42@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:42:16 +0900 Subject: [PATCH 2/5] fix: disable sensitive content filtering (#43) --- .github/workflows/pr.yml | 1 - .../settings/NekoExperimentalSettingsActivity.java | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 6f24c4ca4b..fc831e3c98 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -59,7 +59,6 @@ jobs: boringssl: name: Native Build (BoringSSL) runs-on: ubuntu-latest - needs: check steps: - name: Checkout uses: actions/checkout@v4 diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java index 829a82fe51..91365244c2 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -24,6 +24,7 @@ import org.telegram.messenger.MediaController; import org.telegram.messenger.R; import org.telegram.tgnet.TLRPC; +import org.telegram.tgnet.tl.TL_account; import org.telegram.ui.ActionBar.ActionBar; import org.telegram.ui.ActionBar.AlertDialog; import org.telegram.ui.ActionBar.Theme; @@ -282,7 +283,7 @@ public void onItemClick(int id) { } else if (a instanceof ConfigCellCustom) { // Custom onclick if (position == cellGroup.rows.indexOf(disableFilteringRow)) { sensitiveEnabled = !sensitiveEnabled; - TLRPC.TL_account_setContentSettings req = new TLRPC.TL_account_setContentSettings(); + TL_account.setContentSettings req = new TL_account.setContentSettings(); req.sensitive_enabled = sensitiveEnabled; AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); progressDialog.show(); @@ -502,10 +503,10 @@ public ArrayList getThemeDescriptions() { } private void checkSensitive() { - TLRPC.TL_account_getContentSettings req = new TLRPC.TL_account_getContentSettings(); + TL_account.getContentSettings req = new TL_account.getContentSettings(); getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { if (error == null) { - TLRPC.TL_account_contentSettings settings = (TLRPC.TL_account_contentSettings) response; + TL_account.contentSettings settings = (TL_account.contentSettings) response; sensitiveEnabled = settings.sensitive_enabled; sensitiveCanChange = settings.sensitive_can_change; int count = listView.getChildCount(); From 44c52d29f8a43781a5756c3ceae31c7bcf20bc35 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 29 Jan 2025 18:18:10 +0800 Subject: [PATCH 3/5] chore: update dependencies update nitrite from v3 to v4 --- TMessagesProj/build.gradle | 4 +- .../org/telegram/messenger/SharedConfig.java | 10 +---- .../java/org/telegram/ui/ProfileActivity.java | 2 - .../tw/nekomimi/nekogram/database/DbPref.kt | 34 ++++++++------- .../tw/nekomimi/nekogram/database/Nitrites.kt | 20 +++++---- .../nekogram/transtale/ChatCCTarget.java | 38 ----------------- .../nekogram/transtale/ChatLanguage.java | 37 ----------------- .../nekogram/transtale/TransItem.java | 40 ------------------ .../nekogram/transtale/TranslateDb.kt | 41 +++++++++++++------ .../nekomimi/nekogram/transtale/Translator.kt | 8 ++-- .../transtale/entity/ChatCCTarget.java | 19 +++++++++ .../transtale/entity/ChatLanguage.java | 19 +++++++++ .../nekogram/transtale/entity/TransItem.java | 19 +++++++++ .../mapper/ChatCCTargetConverter.java | 29 +++++++++++++ .../mapper/ChatLanguageConverter.java | 29 +++++++++++++ .../transtale/mapper/TransItemConverter.java | 29 +++++++++++++ .../nekogram/ui/MessageDetailsActivity.java | 27 +++--------- .../nekogram/ui/PinnedStickerHelper.java | 5 ++- 18 files changed, 224 insertions(+), 186 deletions(-) delete mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatCCTarget.java delete mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatLanguage.java delete mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TransItem.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatCCTarget.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatLanguage.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/TransItem.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatCCTargetConverter.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatLanguageConverter.java create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/TransItemConverter.java diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index eaed61362b..6e81ebaad2 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -315,7 +315,9 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.10" implementation 'com.neovisionaries:nv-websocket-client:2.14' implementation 'dnsjava:dnsjava:3.4.1' - implementation "org.dizitart:nitrite:3.4.3" + // db + implementation 'org.dizitart:nitrite:4.3.0' + implementation 'org.dizitart:nitrite-mvstore-adapter:4.3.0' implementation "cn.hutool:hutool-core:5.7.13" implementation "cn.hutool:hutool-crypto:5.7.13" diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java b/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java index 001c5aac16..91fb3be489 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SharedConfig.java @@ -28,12 +28,6 @@ import androidx.annotation.RequiresApi; import androidx.core.content.pm.ShortcutManagerCompat; -import org.apache.commons.lang3.StringUtils; -import org.dizitart.no2.objects.filters.ObjectFilters; -import org.json.JSONArray; -import org.json.JSONException; -import androidx.annotation.IntDef; - import org.json.JSONObject; import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.SerializedData; @@ -556,7 +550,7 @@ public static int getLastLocalId() { public static void saveAccounts() { FileLog.e("Save accounts: " + activeAccounts, new Exception()); ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit() - .putString("active_accounts", StringUtils.join(activeAccounts, ",")) + .putString("active_accounts", StrUtil.join(",", activeAccounts)) .apply(); } @@ -734,7 +728,7 @@ public static void loadConfig() { } if (!SharedConfig.activeAccounts.isEmpty()) { - preferences.edit().putString("active_accounts", StringUtils.join(activeAccounts, ",")).apply(); + preferences.edit().putString("active_accounts", StrUtil.join(",", activeAccounts)).apply(); } preferences.edit().putBoolean("activeAccountsLoaded", true).apply(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 4757300fcc..3e2d740f26 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -127,8 +127,6 @@ import com.jakewharton.processphoenix.ProcessPhoenix; -import org.apache.commons.lang3.StringUtils; - import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.messenger.AccountInstance; import org.telegram.messenger.AndroidUtilities; diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/DbPref.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/DbPref.kt index 84df8aaaba..7b415dd6de 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/DbPref.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/DbPref.kt @@ -1,25 +1,31 @@ package tw.nekomimi.nekogram.database import android.content.SharedPreferences -import org.dizitart.no2.* -import org.dizitart.no2.filters.Filters +import org.dizitart.no2.collection.Document +import org.dizitart.no2.collection.FindOptions +import org.dizitart.no2.collection.NitriteCollection +import org.dizitart.no2.collection.UpdateOptions +import org.dizitart.no2.filters.Filter +import org.dizitart.no2.filters.FluentFilter +import org.dizitart.no2.index.IndexOptions +import org.dizitart.no2.index.IndexType import org.telegram.messenger.FileLog import tw.nekomimi.nekogram.utils.UIUtil -class DbPref(val connection: NitriteCollection) : SharedPreferences { +class DbPref(val collection: NitriteCollection) : SharedPreferences { init { - if (!connection.hasIndex("key")) { - connection.createIndex("key", IndexOptions.indexOptions(IndexType.Unique)) + if (!collection.hasIndex("key")) { + collection.createIndex(IndexOptions.indexOptions(IndexType.UNIQUE), "key") } } val listeners = LinkedHashSet() - val isEmpty get() = connection.find(FindOptions.limit(0, 1)).count() == 0 + val isEmpty get() = collection.find(FindOptions.limitBy(1)).count() == 0 private inline fun getAs(key: String, defValue: T): T { - connection.find(Filters.eq("key", key)).apply { + collection.find(FluentFilter.where("key").eq(key)).apply { runCatching { return first().get("value", T::class.java) } @@ -28,7 +34,7 @@ class DbPref(val connection: NitriteCollection) : SharedPreferences { } override fun contains(key: String): Boolean { - return connection.find(Filters.eq("key", key)).count() > 0 + return collection.find(FluentFilter.where("key").eq(key)).count() > 0 } override fun getBoolean(key: String, defValue: Boolean) = getAs(key, defValue) @@ -37,7 +43,7 @@ class DbPref(val connection: NitriteCollection) : SharedPreferences { override fun getAll(): MutableMap { val allValues = HashMap() - connection.find().forEach { + collection.find().forEach { allValues[it.get("key", String::class.java)] = it["value"] } return allValues @@ -113,17 +119,17 @@ class DbPref(val connection: NitriteCollection) : SharedPreferences { override fun commit(): Boolean { try { if (clear) { - connection.remove(Filters.ALL) + collection.remove(Filter.ALL) } else { toRemove.forEach { - connection.remove(Filters.eq("key", it)) + collection.remove(FluentFilter.where("key").eq(it)) } } toApply.forEach { (key, value) -> if (value == null) { - connection.remove(Filters.eq("key", key)) + collection.remove(FluentFilter.where("key").eq(key)) } else { - connection.update(Filters.eq("key", key), Document().apply { + collection.update(FluentFilter.where("key").eq(key), Document.createDocument().apply { put("key", key) put("value", value) }, UpdateOptions.updateOptions(true)) @@ -142,4 +148,4 @@ class DbPref(val connection: NitriteCollection) : SharedPreferences { } -} \ No newline at end of file +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/Nitrites.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/Nitrites.kt index 7d97607002..d058872436 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/Nitrites.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/database/Nitrites.kt @@ -1,12 +1,14 @@ package tw.nekomimi.nekogram.database import org.dizitart.no2.Nitrite +import org.dizitart.no2.common.module.NitriteModule +import org.dizitart.no2.mvstore.MVStoreModule import org.telegram.messenger.ApplicationLoader import tw.nekomimi.nekogram.utils.FileUtil import java.io.File @JvmOverloads -fun mkDatabase(name: String, delete: Boolean = false): Nitrite { +fun mkDatabase(name: String, delete: Boolean = false, module: NitriteModule? = null): Nitrite { val file = File("${ApplicationLoader.getDataDirFixed()}/databases/$name.db") FileUtil.initDir(file.parentFile!!) @@ -15,12 +17,16 @@ fun mkDatabase(name: String, delete: Boolean = false): Nitrite { } fun create(): Nitrite { - val nitrite = Nitrite.builder() - .filePath(file) - .openOrCreate()!! + val storeModule = MVStoreModule.withConfig() + .filePath(file) + .build() + var nitriteBuilder = Nitrite.builder() + .loadModule(storeModule) + if (module != null) nitriteBuilder = nitriteBuilder.loadModule(module) + val nitrite = nitriteBuilder.openOrCreate() val test = nitrite.openSharedPreference("shared_preferences") - test.connection.close() + test.collection.close() return nitrite } @@ -52,10 +58,10 @@ fun openMainSharedPreference(name: String, delete: Boolean = false): DbPref { mainSharedPreferencesDatabase.openSharedPreference(name) - } catch (e: IllegalStateException) { + } catch (_: IllegalStateException) { openMainSharedPreference(name, true) } -} \ No newline at end of file +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatCCTarget.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatCCTarget.java deleted file mode 100644 index 90f94d9924..0000000000 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatCCTarget.java +++ /dev/null @@ -1,38 +0,0 @@ -package tw.nekomimi.nekogram.transtale; - -import org.dizitart.no2.Document; -import org.dizitart.no2.mapper.Mappable; -import org.dizitart.no2.mapper.NitriteMapper; -import org.dizitart.no2.objects.Id; -import org.dizitart.no2.objects.Index; - -@Index("chatId") -public class ChatCCTarget implements Mappable { - - @Id - public long chatId; - public String ccTarget; - - public ChatCCTarget() { - } - - public ChatCCTarget(long chatId, String ccTarget) { - this.chatId = chatId; - this.ccTarget = ccTarget; - } - - @Override - public Document write(NitriteMapper mapper) { - Document document = new Document(); - document.put("chatId", chatId); - document.put("ccTarget", ccTarget); - return document; - } - - @Override - public void read(NitriteMapper mapper, Document document) { - chatId = ((long) document.get("chatId")); - ccTarget = ((String) document.get("ccTarget")); - } - -} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatLanguage.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatLanguage.java deleted file mode 100644 index 080a9b3ef3..0000000000 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/ChatLanguage.java +++ /dev/null @@ -1,37 +0,0 @@ -package tw.nekomimi.nekogram.transtale; - -import org.dizitart.no2.Document; -import org.dizitart.no2.mapper.Mappable; -import org.dizitart.no2.mapper.NitriteMapper; -import org.dizitart.no2.objects.Id; -import org.dizitart.no2.objects.Index; - -@Index("chatId") -public class ChatLanguage implements Mappable { - - @Id - public long chatId; - - public String language; - - public ChatLanguage() { - } - - public ChatLanguage(long chatId, String language) { - this.chatId = chatId; - this.language = language; - } - - @Override public Document write(NitriteMapper mapper) { - Document document = new Document(); - document.put("chatId",chatId); - document.put("language",language); - return document; - } - - @Override public void read(NitriteMapper mapper, Document document) { - chatId = ((long) document.get("chatId")); - language = ((String) document.get("language")); - } - -} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TransItem.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TransItem.java deleted file mode 100644 index 228bf4b141..0000000000 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TransItem.java +++ /dev/null @@ -1,40 +0,0 @@ -package tw.nekomimi.nekogram.transtale; - -import org.dizitart.no2.Document; -import org.dizitart.no2.IndexType; -import org.dizitart.no2.mapper.Mappable; -import org.dizitart.no2.mapper.NitriteMapper; -import org.dizitart.no2.objects.Id; -import org.dizitart.no2.objects.Index; -import org.dizitart.no2.objects.Indices; - -@Index(value = "text") -public class TransItem implements Mappable { - - @Id - public String text; - public String trans; - - public TransItem() { - } - - public TransItem(String text, String trans) { - this.text = text; - this.trans = trans; - } - - @Override - public Document write(NitriteMapper mapper) { - Document document = new Document(); - document.put("text",text); - document.put("trans", trans); - return document; - } - - @Override - public void read(NitriteMapper mapper, Document document) { - text = (String) document.get("text"); - trans = (String) document.get("trans"); - } - -} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TranslateDb.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TranslateDb.kt index 788f888369..8fecc635e8 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TranslateDb.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/TranslateDb.kt @@ -1,29 +1,44 @@ package tw.nekomimi.nekogram.transtale -import org.dizitart.no2.objects.ObjectRepository -import org.dizitart.no2.objects.filters.ObjectFilters +import org.dizitart.no2.common.mapper.SimpleNitriteMapper +import org.dizitart.no2.common.module.NitriteModule +import org.dizitart.no2.filters.FluentFilter +import org.dizitart.no2.repository.ObjectRepository import org.telegram.messenger.LocaleController import tw.nekomimi.nekogram.NekoConfig import tw.nekomimi.nekogram.database.mkDatabase +import tw.nekomimi.nekogram.transtale.entity.ChatCCTarget +import tw.nekomimi.nekogram.transtale.entity.ChatLanguage +import tw.nekomimi.nekogram.transtale.entity.TransItem +import tw.nekomimi.nekogram.transtale.mapper.ChatCCTargetConverter +import tw.nekomimi.nekogram.transtale.mapper.ChatLanguageConverter +import tw.nekomimi.nekogram.transtale.mapper.TransItemConverter import tw.nekomimi.nekogram.utils.UIUtil -import java.util.* -import kotlin.collections.HashMap +import java.util.Locale class TranslateDb(val code: String) { - var conn: ObjectRepository = db.getRepository(code, TransItem::class.java) + var conn: ObjectRepository = db.getRepository(TransItem::class.java, code) companion object { - val db = mkDatabase("translate_caches") + val db = mkDatabase("translate_caches", module = NitriteModule.module(getNitriteMapper())) val repo = HashMap() - val chat = db.getRepository("chat", ChatLanguage::class.java) - val ccTarget = db.getRepository("opencc", ChatCCTarget::class.java) + val chat: ObjectRepository = db.getRepository(ChatLanguage::class.java, "chat") + val ccTarget: ObjectRepository = db.getRepository(ChatCCTarget::class.java, "opencc") + + @JvmStatic fun getNitriteMapper(): SimpleNitriteMapper { + val nitriteMapper = SimpleNitriteMapper() + nitriteMapper.registerEntityConverter(ChatCCTargetConverter()) + nitriteMapper.registerEntityConverter(ChatLanguageConverter()) + nitriteMapper.registerEntityConverter(TransItemConverter()) + return nitriteMapper + } @JvmStatic fun getChatLanguage(chatId: Long, default: Locale): Locale { - return chat.find(ObjectFilters.eq("chatId", chatId)).firstOrDefault()?.language?.code2Locale + return chat.find(FluentFilter.where("chatId").eq(chatId)).firstOrNull()?.language?.code2Locale ?: default } @@ -38,7 +53,7 @@ class TranslateDb(val code: String) { @JvmStatic fun getChatCCTarget(chatId: Long, default: String?): String? { - return ccTarget.find(ObjectFilters.eq("chatId", chatId)).firstOrDefault()?.ccTarget + return ccTarget.find(FluentFilter.where("chatId").eq(chatId)).firstOrNull()?.ccTarget ?: default } @@ -80,7 +95,7 @@ class TranslateDb(val code: String) { } - fun contains(text: String) = synchronized(this) { conn.find(ObjectFilters.eq("text", text)).count() > 0 } + fun contains(text: String) = synchronized(this) { conn.find(FluentFilter.where("text").eq(text)).count() > 0 } fun save(text: String, trans: String) = synchronized(this) { @@ -90,8 +105,8 @@ class TranslateDb(val code: String) { fun query(text: String) = synchronized(this) { - conn.find(ObjectFilters.eq("text", text)).firstOrDefault()?.trans + conn.find(FluentFilter.where("text").eq(text)).firstOrNull()?.trans } -} \ No newline at end of file +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt index cfe4fd70ba..010410ff0a 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/Translator.kt @@ -4,10 +4,8 @@ import android.view.View import cn.hutool.core.util.ArrayUtil import cn.hutool.core.util.StrUtil import cn.hutool.http.HttpRequest -import org.apache.commons.lang3.LocaleUtils import org.telegram.messenger.LocaleController import org.telegram.messenger.R -import org.telegram.messenger.SharedConfig import tw.nekomimi.nekogram.NekoConfig import tw.nekomimi.nekogram.ui.PopupBuilder import tw.nekomimi.nekogram.cc.CCConverter @@ -145,13 +143,17 @@ interface Translator { } + val availableLocaleList: Array = Locale.getAvailableLocales().also { + Arrays.sort(it, Comparator.comparing(Locale::toString)) + } + @JvmStatic @JvmOverloads fun showTargetLangSelect(anchor: View, input: Boolean = false, full: Boolean = false, callback: (Locale) -> Unit) { val builder = PopupBuilder(anchor) - var locales = (if (full) LocaleUtils.availableLocaleList() + var locales = (if (full) availableLocaleList .filter { it.variant.isBlank() } else LocaleController.getInstance() .languages .map { it.pluralLangCode } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatCCTarget.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatCCTarget.java new file mode 100644 index 0000000000..e5dbcfd166 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatCCTarget.java @@ -0,0 +1,19 @@ +package tw.nekomimi.nekogram.transtale.entity; + +import org.dizitart.no2.repository.annotations.Id; +import org.dizitart.no2.repository.annotations.Index; + +@Index(fields = "chatId") +public class ChatCCTarget { + @Id + public Long chatId; + public String ccTarget; + + public ChatCCTarget() { + } + + public ChatCCTarget(Long chatId, String ccTarget) { + this.chatId = chatId; + this.ccTarget = ccTarget; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatLanguage.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatLanguage.java new file mode 100644 index 0000000000..0b5fe90514 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/ChatLanguage.java @@ -0,0 +1,19 @@ +package tw.nekomimi.nekogram.transtale.entity; + +import org.dizitart.no2.repository.annotations.Id; +import org.dizitart.no2.repository.annotations.Index; + +@Index(fields = "chatId") +public class ChatLanguage { + @Id + public Long chatId; + public String language; + + public ChatLanguage() { + } + + public ChatLanguage(Long chatId, String language) { + this.chatId = chatId; + this.language = language; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/TransItem.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/TransItem.java new file mode 100644 index 0000000000..d11f6a46a5 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/entity/TransItem.java @@ -0,0 +1,19 @@ +package tw.nekomimi.nekogram.transtale.entity; + +import org.dizitart.no2.repository.annotations.Id; +import org.dizitart.no2.repository.annotations.Index; + +@Index(fields = "text") +public class TransItem { + @Id + public String text; + public String trans; + + public TransItem() { + } + + public TransItem(String text, String trans) { + this.text = text; + this.trans = trans; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatCCTargetConverter.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatCCTargetConverter.java new file mode 100644 index 0000000000..ce4b77673c --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatCCTargetConverter.java @@ -0,0 +1,29 @@ +package tw.nekomimi.nekogram.transtale.mapper; + +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.common.mapper.EntityConverter; +import org.dizitart.no2.common.mapper.NitriteMapper; + +import tw.nekomimi.nekogram.transtale.entity.ChatCCTarget; + +public class ChatCCTargetConverter implements EntityConverter { + @Override + public Class getEntityType() { + return ChatCCTarget.class; + } + + @Override + public Document toDocument(ChatCCTarget entity, NitriteMapper nitriteMapper) { + return Document.createDocument() + .put("chatId", entity.chatId) + .put("ccTarget", entity.ccTarget); + } + + @Override + public ChatCCTarget fromDocument(Document document, NitriteMapper nitriteMapper) { + ChatCCTarget entity = new ChatCCTarget(); + entity.chatId = document.get("chatId", Long.class); + entity.ccTarget = document.get("ccTarget", String.class); + return entity; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatLanguageConverter.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatLanguageConverter.java new file mode 100644 index 0000000000..c5a189adc7 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/ChatLanguageConverter.java @@ -0,0 +1,29 @@ +package tw.nekomimi.nekogram.transtale.mapper; + +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.common.mapper.EntityConverter; +import org.dizitart.no2.common.mapper.NitriteMapper; + +import tw.nekomimi.nekogram.transtale.entity.ChatLanguage; + +public class ChatLanguageConverter implements EntityConverter { + @Override + public Class getEntityType() { + return ChatLanguage.class; + } + + @Override + public Document toDocument(ChatLanguage entity, NitriteMapper nitriteMapper) { + return Document.createDocument() + .put("chatId", entity.chatId) + .put("language", entity.language); + } + + @Override + public ChatLanguage fromDocument(Document document, NitriteMapper nitriteMapper) { + ChatLanguage entity = new ChatLanguage(); + entity.chatId = document.get("chatId", Long.class); + entity.language = document.get("language", String.class); + return entity; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/TransItemConverter.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/TransItemConverter.java new file mode 100644 index 0000000000..cdbfa5c341 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/transtale/mapper/TransItemConverter.java @@ -0,0 +1,29 @@ +package tw.nekomimi.nekogram.transtale.mapper; + +import org.dizitart.no2.collection.Document; +import org.dizitart.no2.common.mapper.EntityConverter; +import org.dizitart.no2.common.mapper.NitriteMapper; + +import tw.nekomimi.nekogram.transtale.entity.TransItem; + +public class TransItemConverter implements EntityConverter { + @Override + public Class getEntityType() { + return TransItem.class; + } + + @Override + public Document toDocument(TransItem entity, NitriteMapper nitriteMapper) { + return Document.createDocument() + .put("text", entity.text) + .put("trans", entity.trans); + } + + @Override + public TransItem fromDocument(Document document, NitriteMapper nitriteMapper) { + TransItem entity = new TransItem(); + entity.text = document.get("text", String.class); + entity.trans = document.get("trans", String.class); + return entity; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageDetailsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageDetailsActivity.java index 74add9a3a9..a3709ee6e7 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageDetailsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/MessageDetailsActivity.java @@ -19,16 +19,13 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.google.gson.ExclusionStrategy; -import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; @@ -62,7 +59,6 @@ import org.telegram.ui.ProfileActivity; import java.io.File; -import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Date; @@ -104,8 +100,8 @@ public class MessageDetailsActivity extends BaseFragment implements Notification private UndoView copyTooltip; public static final Gson gson = new GsonBuilder() - .setExclusionStrategies(new Exclusion()) .registerTypeHierarchyAdapter(byte[].class, new ByteArrayToBase64TypeAdapter()).create(); + public static final Gson prettyGson = new GsonBuilder().setPrettyPrinting().create(); private static class ByteArrayToBase64TypeAdapter implements JsonSerializer, JsonDeserializer { public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { @@ -117,16 +113,6 @@ public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContex } } - public static class Exclusion implements ExclusionStrategy { - public boolean shouldSkipClass(Class arg0) { - return false; - } - - public boolean shouldSkipField(FieldAttributes f) { - return f.getName().equals("disableFree") || f.getName().equals("networkType"); - } - } - public MessageDetailsActivity(MessageObject messageObject) { this.messageObject = messageObject; if (messageObject.messageOwner.peer_id != null && messageObject.messageOwner.peer_id.channel_id != 0) { @@ -490,10 +476,9 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { textCell.setTextAndValue("Buttons", gson.toJson(messageObject.messageOwner.reply_markup), divider); } else if (position == jsonTextRow) { try { - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationFeature.INDENT_OUTPUT); - String jsonString = mapper.writeValueAsString(messageObject.messageOwner); - + String jsonTempString = gson.toJson(messageObject.messageOwner); + JsonElement jsonElement = JsonParser.parseString(jsonTempString); + String jsonString = prettyGson.toJson(jsonElement); final SpannableString[] sb = new SpannableString[1]; new CountDownTimer(300, 100) { @Override @@ -506,7 +491,7 @@ public void onFinish() { textCell.setTextAndValue("JSON", sb[0], divider); } }.start(); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); } } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/PinnedStickerHelper.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/PinnedStickerHelper.java index b8f847f5f4..55b268d504 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/PinnedStickerHelper.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/ui/PinnedStickerHelper.java @@ -1,6 +1,5 @@ package tw.nekomimi.nekogram.ui; -import org.apache.commons.lang3.StringUtils; import org.telegram.messenger.MessagesController; import org.telegram.tgnet.ConnectionsManager; import org.telegram.tgnet.TLRPC; @@ -11,6 +10,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; +import cn.hutool.core.util.StrUtil; + /** * @author luvletter2333 */ @@ -54,7 +55,7 @@ private PinnedStickerHelper(int accountNum) { private void updateConfig() { MessagesController.getMainSettings(accountNum) .edit() - .putString("pinnedStickers", StringUtils.join(this.pinnedList, ",")) + .putString("pinnedStickers", StrUtil.join(",", this.pinnedList)) .apply(); } From 1c060dff5ebbad69ba4a497e63f08189ca36b2f4 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 31 Jan 2025 19:35:11 +0800 Subject: [PATCH 4/5] refa: config cell select box create sub menu dialog --- .../nekomimi/nekogram/config/ConfigItem.java | 1 + .../nekogram/config/ConfigItemKeyLinked.java | 70 +++ .../config/cell/ConfigCellTextCheck.java | 4 + .../settings/NekoChatSettingsActivity.java | 419 +++--------------- .../settings/NekoGeneralSettingsActivity.java | 87 +--- .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 52 +++ 6 files changed, 198 insertions(+), 435 deletions(-) create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItemKeyLinked.java diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItem.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItem.java index 164f678283..79f36041ab 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItem.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItem.java @@ -21,6 +21,7 @@ public class ConfigItem { public static final int configTypeMapIntInt = 4; public static final int configTypeLong = 5; public static final int configTypeFloat = 6; + public static final int configTypeBoolLinkInt = 7; public final String key; public final int type; diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItemKeyLinked.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItemKeyLinked.java new file mode 100644 index 0000000000..3612acc167 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/ConfigItemKeyLinked.java @@ -0,0 +1,70 @@ +package tw.nekomimi.nekogram.config; + +import android.content.SharedPreferences; + +import org.telegram.messenger.FileLog; + +import tw.nekomimi.nekogram.NekoConfig; + +public class ConfigItemKeyLinked extends ConfigItem { + public final ConfigItem keyLinked; + public final int flag; + + public ConfigItemKeyLinked(String key, ConfigItem keyLinked, int flag, Object defaultValue) { + super(key, ConfigItem.configTypeBoolLinkInt, defaultValue); + this.keyLinked = keyLinked; + this.flag = (int) Math.pow(2, flag); + } + + public ConfigItem getKeyLinked() { + return keyLinked; + } + + public void changedFromKeyLinked(int currentConfig) { + changed((currentConfig & flag) != 0); + } + + public boolean toggleConfigBool() { + value = !this.Bool(); + saveConfig(); + return this.Bool();//返回toggle之后的 + } + + public void setConfigBool(boolean v) { + value = v; + saveConfig(); + } + + public void saveConfig() { + synchronized (NekoConfig.sync) { + try { + SharedPreferences.Editor editor = NekoConfig.preferences.edit(); + + if (this.type == configTypeBoolLinkInt) { + int currentConfig = this.keyLinked.Int(); + int newConfig; + if ((boolean) this.value) { + newConfig = currentConfig | flag; // 开启对应位 + } else { + newConfig = currentConfig & ~flag; // 关闭对应位 + } + this.keyLinked.changed(newConfig); + editor.putInt(this.keyLinked.getKey(), newConfig); + } + editor.apply(); + } catch (Exception e) { + FileLog.e(e); + } + } + } + + public Object checkConfigFromString(String value) { + try { + if (type == configTypeBoolLinkInt) { + return Boolean.parseBoolean(value); + } + return null; + } catch (Exception ignored) {} + return null; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextCheck.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextCheck.java index 4df7453855..66bb3823f0 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextCheck.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextCheck.java @@ -41,6 +41,10 @@ public ConfigItem getBindConfig() { return bindConfig; } + public String getTitle() { + return title; + } + public String getKey() { return bindConfig == null ? null : bindConfig.getKey(); } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index e2b061afda..2c000000f6 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -52,6 +52,7 @@ import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.NekoXConfig; import tw.nekomimi.nekogram.config.CellGroup; +import tw.nekomimi.nekogram.config.ConfigItem; import tw.nekomimi.nekogram.config.cell.AbstractConfigCell; import tw.nekomimi.nekogram.config.cell.ConfigCellCustom; import tw.nekomimi.nekogram.config.cell.ConfigCellDivider; @@ -89,8 +90,38 @@ public class NekoChatSettingsActivity extends BaseNekoXSettingsActivity implemen private final AbstractConfigCell labelChannelUserRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.labelChannelUser)); private final AbstractConfigCell hideSendAsChannelRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.hideSendAsChannel)); private final AbstractConfigCell showSpoilersDirectlyRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.showSpoilersDirectly)); - private final AbstractConfigCell messageMenuRow = cellGroup.appendCell(new ConfigCellSelectBox("MessageMenu", null, null, this::showMessageMenuAlert)); - private final AbstractConfigCell defaultDeleteMenuRow = cellGroup.appendCell(new ConfigCellSelectBox("DefaultDeleteMenu", null, null, this::showDeleteMenuAlert)); + private final AbstractConfigCell messageMenuRow = cellGroup.appendCell(new ConfigCellSelectBox("MessageMenu", null, null, () -> { + if (getParentActivity() == null) return; + showDialog(showConfigMenuAlert(getParentActivity(), "MessageMenu", new ArrayList<>() {{ + add(new ConfigCellTextCheck(NekoConfig.showDeleteDownloadedFile, null, LocaleController.getString(R.string.DeleteDownloadedFile))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowCopyPhoto())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowNoQuoteForward())); + add(new ConfigCellTextCheck(NekoConfig.showAddToSavedMessages, null, LocaleController.getString(R.string.AddToSavedMessages))); + add(new ConfigCellTextCheck(NekoConfig.showRepeat, null, LocaleController.getString(R.string.Repeat))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowRepeatAsCopy())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowInvertReply())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowGreatOrPoor(), null, NaConfig.INSTANCE.getCustomGreat().String())); + add(new ConfigCellTextCheck(NekoConfig.showViewHistory, null, LocaleController.getString(R.string.ViewHistory))); + add(new ConfigCellTextCheck(NekoConfig.showTranslate, null, LocaleController.getString(R.string.Translate))); + add(new ConfigCellTextCheck(NekoConfig.showReport, null, LocaleController.getString(R.string.ReportChat))); + add(new ConfigCellTextCheck(NekoConfig.showAdminActions, null, LocaleController.getString(R.string.EditAdminRights))); + add(new ConfigCellTextCheck(NekoConfig.showChangePermissions, null, LocaleController.getString(R.string.ChangePermissions))); + add(new ConfigCellTextCheck(NekoConfig.showMessageHide, null, LocaleController.getString(R.string.Hide))); + add(new ConfigCellTextCheck(NekoConfig.showShareMessages, null, LocaleController.getString(R.string.ShareMessages))); + add(new ConfigCellTextCheck(NekoConfig.showMessageDetails, null, LocaleController.getString(R.string.MessageDetails))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowSetReminder())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowReactions())); + }})); + })); + private final AbstractConfigCell defaultDeleteMenuRow = cellGroup.appendCell(new ConfigCellSelectBox("DefaultDeleteMenu", null, null, () -> { + if (getParentActivity() == null) return; + showDialog(showConfigMenuAlert(getParentActivity(), NaConfig.INSTANCE.getDefaultDeleteMenu().getKey(), new ArrayList<>() {{ + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDefaultDeleteMenuBanUsers())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDefaultDeleteMenReportSpam())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDefaultDeleteMenuDeleteAll())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDefaultDeleteMenuDoActionsInCommonGroups())); + }})); + })); private final AbstractConfigCell customGreatRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getCustomGreat(), LocaleController.getString(R.string.CustomGreatHint), null,(input) -> input.isEmpty() ? (String) NaConfig.INSTANCE.getCustomGreat().defaultValue : input)); private final AbstractConfigCell customPoorRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getCustomPoor(), LocaleController.getString(R.string.CustomPoorHint), null,(input) -> input.isEmpty() ? (String) NaConfig.INSTANCE.getCustomPoor().defaultValue : input)); private final AbstractConfigCell customEditedMessageRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getCustomEditedMessage(), "", null)); @@ -118,7 +149,22 @@ public class NekoChatSettingsActivity extends BaseNekoXSettingsActivity implemen // }, null)); private final AbstractConfigCell doubleTapActionRow = cellGroup.appendCell(new ConfigCellCustom("DoubleTapAction", CellGroup.ITEM_TYPE_TEXT_SETTINGS_CELL, true)); private final AbstractConfigCell autoReplaceRepeatRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getAutoReplaceRepeat())); - private final AbstractConfigCell textStyleRow = cellGroup.appendCell(new ConfigCellSelectBox("TextStyle", null, null, this::showTextStyleAlert)); + private final AbstractConfigCell textStyleRow = cellGroup.appendCell(new ConfigCellSelectBox("TextStyle", null, null, () -> { + if (getParentActivity() == null) return; + showDialog(showConfigMenuAlert(getParentActivity(), "TextStyle", new ArrayList<>() {{ + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextBold(), null, LocaleController.getString(R.string.Bold))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextItalic(), null, LocaleController.getString(R.string.Italic))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextMono(), null, LocaleController.getString(R.string.Mono))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextStrikethrough(), null, LocaleController.getString(R.string.Strike))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextUnderline(), null, LocaleController.getString(R.string.Underline))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextSpoiler(), null, LocaleController.getString(R.string.Spoiler))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextCreateLink(), null, LocaleController.getString(R.string.CreateLink))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextCreateMention(), null, LocaleController.getString(R.string.CreateMention))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextRegular(), null, LocaleController.getString(R.string.Regular))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextUndoRedo(), null, LocaleController.getString(R.string.TextUndoRedo))); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowTextQuote(), null, LocaleController.getString(R.string.Quote))); + }})); + })); private final AbstractConfigCell disableZalgoSymbolsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getZalgoFilter(), LocaleController.getString("ZalgoFilterNotice", R.string.ZalgoFilterNotice))); private final AbstractConfigCell quickToggleAnonymousRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getQuickToggleAnonymous(), LocaleController.getString("QuickToggleAnonymousNotice", R.string.QuickToggleAnonymousNotice))); private final AbstractConfigCell showOnlineStatusRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getShowOnlineStatus(), LocaleController.getString("ShowOnlineStatusNotice", R.string.ShowOnlineStatusNotice))); @@ -435,13 +481,9 @@ public ArrayList getThemeDescriptions() { return themeDescriptions; } - private void showMessageMenuAlert() { - if (getParentActivity() == null) { - return; - } - Context context = getParentActivity(); + public static AlertDialog showConfigMenuAlert(Context context, String titleKey, ArrayList configItems) { AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(LocaleController.getString("MessageMenu", R.string.MessageMenu)); + builder.setTitle(LocaleController.getString(titleKey)); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); @@ -450,367 +492,34 @@ private void showMessageMenuAlert() { linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - int count = 11 + 7; + int count = configItems.size(); for (int a = 0; a < count; a++) { + ConfigCellTextCheck configItem = configItems.get(a); TextCheckCell textCell = new TextCheckCell(context); - switch (a) { - case 0: { - textCell.setTextAndCheck(LocaleController.getString("DeleteDownloadedFile", R.string.DeleteDownloadedFile), NekoConfig.showDeleteDownloadedFile.Bool(), false); - break; - } - case 1: { - textCell.setTextAndCheck(LocaleController.getString("CopyPhoto", R.string.CopyPhoto), NaConfig.INSTANCE.getShowCopyPhoto().Bool(), false); - break; - } - case 2 : { - textCell.setTextAndCheck(LocaleController.getString("NoQuoteForward", R.string.NoQuoteForward), NaConfig.INSTANCE.getShowNoQuoteForward().Bool(), false); - break; - } - case 1 + 2: { - textCell.setTextAndCheck(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages), NekoConfig.showAddToSavedMessages.Bool(), false); - break; - } - case 2 + 2: { - textCell.setTextAndCheck(LocaleController.getString("Repeat", R.string.Repeat), NekoConfig.showRepeat.Bool(), false); - break; - } - case 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("RepeatAsCopy", R.string.RepeatAsCopy), NaConfig.INSTANCE.getShowRepeatAsCopy().Bool(), false); - break; - } - case 4 + 2: { - textCell.setTextAndCheck(LocaleController.getString("InvertReply", R.string.InvertReply), NaConfig.INSTANCE.getShowInvertReply().Bool(), false); - break; - } - case 5 + 2: { - textCell.setTextAndCheck(NaConfig.INSTANCE.getCustomGreat().String(), NaConfig.INSTANCE.getShowGreatOrPoor().Bool(), false); - break; - } - case 3 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("ViewHistory", R.string.ViewHistory), NekoConfig.showViewHistory.Bool(), false); - break; - } - case 4 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("Translate", R.string.Translate), NekoConfig.showTranslate.Bool(), false); - break; - } - case 5 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("ReportChat", R.string.ReportChat), NekoConfig.showReport.Bool(), false); - break; - } - case 6 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("EditAdminRights", R.string.EditAdminRights), NekoConfig.showAdminActions.Bool(), false); - break; - } - case 7 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("ChangePermissions", R.string.ChangePermissions), NekoConfig.showChangePermissions.Bool(), false); - break; - } - case 8 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("Hide", R.string.Hide), NekoConfig.showMessageHide.Bool(), false); - break; - } - case 9 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("ShareMessages", R.string.ShareMessages), NekoConfig.showShareMessages.Bool(), false); - break; - } - case 10 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("MessageDetails", R.string.MessageDetails), NekoConfig.showMessageDetails.Bool(), false); - break; - } - case 11 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("SetReminder", R.string.SetReminder), NaConfig.INSTANCE.getShowSetReminder().Bool(), true); - break; - } - case 12 + 3 + 2: { - textCell.setTextAndCheck(LocaleController.getString("Reactions", R.string.Reactions), NaConfig.INSTANCE.getShowReactions().Bool(), true); - break; - } - } + textCell.setTextAndCheck(configItem.getTitle(), configItem.getBindConfig().Bool(), false); textCell.setTag(a); textCell.setBackground(Theme.getSelectorDrawable(false)); linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); + int finalA = a; textCell.setOnClickListener(v2 -> { Integer tag = (Integer) v2.getTag(); - switch (tag) { - case 0: { - textCell.setChecked(NekoConfig.showDeleteDownloadedFile.toggleConfigBool()); - break; - } - case 1: { - textCell.setChecked(NaConfig.INSTANCE.getShowCopyPhoto().toggleConfigBool()); - break; - } - case 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowNoQuoteForward().toggleConfigBool()); - break; - } - case 1 + 2: { - textCell.setChecked(NekoConfig.showAddToSavedMessages.toggleConfigBool()); - break; - } - case 2 + 2: { - textCell.setChecked(NekoConfig.showRepeat.toggleConfigBool()); - break; - } - case 3 + 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowRepeatAsCopy().toggleConfigBool()); - break; - } - case 4 + 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowInvertReply().toggleConfigBool()); - break; - } - case 5 + 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowGreatOrPoor().toggleConfigBool()); - break; - } - case 3 + 3 + 2: { - textCell.setChecked(NekoConfig.showViewHistory.toggleConfigBool()); - break; - } - case 4 + 3 + 2: { - textCell.setChecked(NekoConfig.showTranslate.toggleConfigBool()); - break; - } - case 5 + 3 + 2: { - textCell.setChecked(NekoConfig.showReport.toggleConfigBool()); - break; - } - case 6 + 3 + 2: { - textCell.setChecked(NekoConfig.showAdminActions.toggleConfigBool()); - break; - } - case 7 + 3 + 2: { - textCell.setChecked(NekoConfig.showChangePermissions.toggleConfigBool()); - break; - } - case 8 + 3 + 2: { - textCell.setChecked(NekoConfig.showMessageHide.toggleConfigBool()); - break; - } - case 9 + 3 + 2: { - textCell.setChecked(NekoConfig.showShareMessages.toggleConfigBool()); - break; - } - case 10 + 3 + 2: { - textCell.setChecked(NekoConfig.showMessageDetails.toggleConfigBool()); - break; - } - case 11 + 3 + 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowSetReminder().toggleConfigBool()); - break; - } - case 12 + 3 + 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowReactions().toggleConfigBool()); - break; - } + if (tag == finalA) { + textCell.setChecked(configItem.getBindConfig().toggleConfigBool()); } }); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setView(linearLayout); - showDialog(builder.create()); - } - - public void showTextStyleAlert() { - if (getParentActivity() == null) { - return; - } - - Context context = getParentActivity(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(LocaleController.getString("TextStyle", R.string.TextStyle)); - - LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - - LinearLayout linearLayoutInviteContainer = new LinearLayout(context); - linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); - linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - for (int a = 0; a < 11; a++) { - TextCheckCell textCell = new TextCheckCell(getParentActivity()); - textCell.setTag(a); - switch (a) { - case 0: { - textCell.setTextAndCheck(LocaleController.getString("Bold", R.string.Bold), NaConfig.INSTANCE.getShowTextBold().Bool(), false); - break; - } - case 1: { - textCell.setTextAndCheck(LocaleController.getString("Italic", R.string.Italic), NaConfig.INSTANCE.getShowTextItalic().Bool(), false); - break; - } - case 2: { - textCell.setTextAndCheck(LocaleController.getString("Mono", R.string.Mono), NaConfig.INSTANCE.getShowTextMono().Bool(), false); - break; - } - case 3: { - textCell.setTextAndCheck(LocaleController.getString("Strike", R.string.Strike), NaConfig.INSTANCE.getShowTextStrikethrough().Bool(), false); - break; - } - case 4: { - textCell.setTextAndCheck(LocaleController.getString("Underline", R.string.Underline), NaConfig.INSTANCE.getShowTextUnderline().Bool(), false); - break; - } - case 5: { - textCell.setTextAndCheck(LocaleController.getString("Spoiler", R.string.Spoiler), NaConfig.INSTANCE.getShowTextSpoiler().Bool(), false); - break; - } - case 6: { - textCell.setTextAndCheck(LocaleController.getString("CreateLink", R.string.CreateLink), NaConfig.INSTANCE.getShowTextCreateLink().Bool(), false); - break; - } - case 7: { - textCell.setTextAndCheck(LocaleController.getString("CreateMention", R.string.CreateMention), NaConfig.INSTANCE.getShowTextCreateMention().Bool(), false); - break; - } - case 8: { - textCell.setTextAndCheck(LocaleController.getString("Regular", R.string.Regular), NaConfig.INSTANCE.getShowTextRegular().Bool(), false); - break; - } - case 9: { - textCell.setTextAndCheck(LocaleController.getString("TextUndoRedo", R.string.TextUndoRedo), NaConfig.INSTANCE.getShowTextUndoRedo().Bool(), false); - break; - } - case 10: { - textCell.setTextAndCheck(LocaleController.getString("Quote", R.string.Quote), NaConfig.INSTANCE.getShowTextQuote().Bool(), false); - break; - } - } - textCell.setTag(a); - textCell.setBackground(Theme.getSelectorDrawable(false)); - linearLayout.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - textCell.setOnClickListener(v2 -> { - Integer tag = (Integer) v2.getTag(); - switch (tag) { - case 0: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextBold().toggleConfigBool()); - break; - } - case 1: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextItalic().toggleConfigBool()); - break; - } - case 2: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextMono().toggleConfigBool()); - break; - } - case 3: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextStrikethrough().toggleConfigBool()); - break; - } - case 4: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextUnderline().toggleConfigBool()); - break; - } - case 5: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextSpoiler().toggleConfigBool()); - break; - } - case 6: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextCreateLink().toggleConfigBool()); - break; - } - case 7: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextCreateMention().toggleConfigBool()); - break; - } - case 8: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextRegular().toggleConfigBool()); - break; - } - case 9: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextUndoRedo().toggleConfigBool()); - break; - } - case 10: { - textCell.setChecked(NaConfig.INSTANCE.getShowTextQuote().toggleConfigBool()); - break; - } - } - }); - - } - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); - builder.setView(linearLayout); - showDialog(builder.create()); + return builder.create(); } public static boolean[] getDeleteMenuChecks() { - final boolean[] checks = new boolean[4]; - final Integer[] values = {8, 4, 2, 1}; - int data = NaConfig.INSTANCE.getDefaultDeleteMenu().Int(); - for (int i = 0; i < values.length; i++) { - if (data >= values[i]) { - checks[i] = true; - data -= values[i]; - } else { - checks[i] = false; - } - } - return checks; - } - - private void saveDeleteMenuChecks(boolean[] checks) { - final Integer[] values = {8, 4, 2, 1}; - int data = 0; - for (int i = 0; i < values.length; i++) { - if (checks[i]) { - data += values[i]; - } - } - NaConfig.INSTANCE.getDefaultDeleteMenu().setConfigInt(data); - } - - private void showDeleteMenuAlert() { - if (getParentActivity() == null) { - return; - } - Context context = getParentActivity(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(LocaleController.getString("DefaultDeleteMenu", R.string.DefaultDeleteMenu)); - - LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - - LinearLayout linearLayoutInviteContainer = new LinearLayout(context); - linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); - linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - - final boolean[] checks = getDeleteMenuChecks(); - - for (int a = 0; a < 4; a++) { - TextCheckCell textCell = new TextCheckCell(context); - switch (a) { - case 0: { - textCell.setTextAndCheck(LocaleController.getString("DeleteBanUsers", R.string.DeleteBanUsers), checks[a], false); - break; - } - case 1: { - textCell.setTextAndCheck(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), checks[a], false); - break; - } - case 2 : { - textCell.setTextAndCheck(LocaleController.getString("DeleteAll", R.string.DeleteAll), checks[a], false); - break; - } - case 3: { - textCell.setTextAndCheck(LocaleController.getString("DoActionsInCommonGroups", R.string.DoActionsInCommonGroups), checks[a], false); - break; - } - } - textCell.setTag(a); - textCell.setBackground(Theme.getSelectorDrawable(false)); - linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - textCell.setOnClickListener(v2 -> { - Integer tag = (Integer) v2.getTag(); - checks[tag] = !checks[tag]; - textCell.setChecked(checks[tag]); - }); - } - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> saveDeleteMenuChecks(checks)); - builder.setView(linearLayout); - showDialog(builder.create()); + return new boolean[]{ + NaConfig.INSTANCE.getDefaultDeleteMenuBanUsers().Bool(), + NaConfig.INSTANCE.getDefaultDeleteMenReportSpam().Bool(), + NaConfig.INSTANCE.getDefaultDeleteMenuDeleteAll().Bool(), + NaConfig.INSTANCE.getDefaultDeleteMenuDoActionsInCommonGroups().Bool(), + }; } @Override diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index 23eaf3023c..4f2eb55b5e 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -171,7 +171,13 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity { private final AbstractConfigCell header4 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("DialogsSettings"))); private final AbstractConfigCell sortMenuRow = cellGroup.appendCell(new ConfigCellSelectBox("SortMenu", null, null, () -> { - showSortMenuAlert(); + if (getParentActivity() == null) return; + showDialog(NekoChatSettingsActivity.showConfigMenuAlert(getParentActivity(), "SortMenu", new ArrayList<>() {{ + add(new ConfigCellTextCheck(NekoConfig.sortByUnread, null, LocaleController.getString(R.string.SortByUnread))); + add(new ConfigCellTextCheck(NekoConfig.sortByUnmuted, null, LocaleController.getString(R.string.SortByUnmuted))); + add(new ConfigCellTextCheck(NekoConfig.sortByUser, null, LocaleController.getString(R.string.SortByUser))); + add(new ConfigCellTextCheck(NekoConfig.sortByContacts, null, LocaleController.getString(R.string.SortByContacts))); + }})); })); private final AbstractConfigCell divider4 = cellGroup.appendCell(new ConfigCellDivider()); @@ -605,85 +611,6 @@ public String toString() { } } - - private void showSortMenuAlert() { - if (getParentActivity() == null) { - return; - } - Context context = getParentActivity(); - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(LocaleController.getString("SortMenu", R.string.SortMenu)); - - LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - - LinearLayout linearLayoutInviteContainer = new LinearLayout(context); - linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL); - linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - - int count = 4; - for (int a = 0; a < count; a++) { - TextCheckCell textCell = new TextCheckCell(context); - switch (a) { - case 0: { - textCell.setTextAndCheck(LocaleController.getString("SortByUnread", R.string.SortByUnread), NekoConfig.sortByUnread.Bool(), false); - break; - } - case 1: { - textCell.setTextAndCheck(LocaleController.getString("SortByUnmuted", R.string.SortByUnmuted), NekoConfig.sortByUnmuted.Bool(), false); - break; - } - case 2: { - textCell.setTextAndCheck(LocaleController.getString("SortByUser", R.string.SortByUser), NekoConfig.sortByUser.Bool(), false); - break; - } - case 3: { - textCell.setTextAndCheck(LocaleController.getString("SortByContacts", R.string.SortByContacts), NekoConfig.sortByContacts.Bool(), false); - break; - } - } - textCell.setTag(a); - textCell.setBackgroundDrawable(Theme.getSelectorDrawable(false)); - linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); - textCell.setOnClickListener(view -> { - Integer tag = (Integer) view.getTag(); - switch (tag) { - case 0: { - NekoConfig.sortByUnread.toggleConfigBool(); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.sortByUnread.Bool()); - } - break; - } - case 1: { - NekoConfig.sortByUnmuted.toggleConfigBool(); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.sortByUnmuted.Bool()); - } - break; - } - case 2: { - NekoConfig.sortByUser.toggleConfigBool(); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.sortByUser.Bool()); - } - break; - } - case 3: { - NekoConfig.sortByContacts.toggleConfigBool(); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.sortByContacts.Bool()); - } - break; - } - } - }); - } - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); - builder.setView(linearLayout); - showDialog(builder.create()); - } - @Override public void onResume() { super.onResume(); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index 87a81b0f00..f62c830a9e 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -8,6 +8,7 @@ import org.telegram.messenger.ApplicationLoader import org.telegram.messenger.LocaleController import org.telegram.messenger.R import tw.nekomimi.nekogram.config.ConfigItem +import tw.nekomimi.nekogram.config.ConfigItemKeyLinked import java.io.ByteArrayInputStream import java.io.ObjectInputStream @@ -415,6 +416,34 @@ object NaConfig { ConfigItem.configTypeInt, 0 ) + val defaultDeleteMenuBanUsers = + addConfig( + "DeleteBanUsers", + defaultDeleteMenu, + 3, + false + ) + val defaultDeleteMenReportSpam = + addConfig( + "DeleteReportSpam", + defaultDeleteMenu, + 2, + false + ) + val defaultDeleteMenuDeleteAll = + addConfig( + "DeleteAll", + defaultDeleteMenu, + 1, + false + ) + val defaultDeleteMenuDoActionsInCommonGroups = + addConfig( + "DoActionsInCommonGroups", + defaultDeleteMenu, + 0, + false + ) val disableSuggestionView = addConfig( "DisableSuggestionView", @@ -694,6 +723,25 @@ object NaConfig { return a } + private fun addConfig( + k: String, + t: ConfigItem, + d: Int, + e: Any? + ): ConfigItem { + val a = + ConfigItemKeyLinked( + k, + t, + d, + e, + ) + configs.add( + a + ) + return a + } + fun loadConfig( force: Boolean ) { @@ -793,6 +841,10 @@ object NaConfig { } } } + if (o.type == ConfigItem.configTypeBoolLinkInt) { + o as ConfigItemKeyLinked + o.changedFromKeyLinked(preferences.getInt(o.keyLinked.key, 0)) + } } configLoaded = true From 55b99573f63a0ee4fb0f9aac9e47e0a9eebe5d7d Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 31 Jan 2025 18:16:27 +0800 Subject: [PATCH 5/5] feat: Trend Recommendations Optional Disable Related Features (#44) Co-authored-by: CinitDev --- .../messenger/MediaDataController.java | 3 +- .../java/org/telegram/ui/ChatActivity.java | 6 +- .../ui/Components/EmojiTabsStrip.java | 3 +- .../org/telegram/ui/Components/EmojiView.java | 10 +-- .../java/org/telegram/ui/DialogsActivity.java | 12 +-- .../java/tw/nekomimi/nekogram/NekoConfig.java | 6 +- .../settings/NekoChatSettingsActivity.java | 18 +++- .../kotlin/xyz/nextalone/nagram/NaConfig.kt | 90 +++++++++++++++++++ .../src/main/res/values-zh-rCN/strings_na.xml | 12 +++ .../src/main/res/values/strings_na.xml | 12 +++ 10 files changed, 152 insertions(+), 20 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java index 95ef5c7080..40cfa1eb87 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java @@ -107,6 +107,7 @@ import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.ui.PinnedStickerHelper; +import xyz.nextalone.nagram.NaConfig; import xyz.nextalone.nagram.helper.ExternalStickerCacheHelper; @SuppressWarnings("unchecked") @@ -2237,7 +2238,7 @@ public void addNewStickerSet(TLRPC.TL_messages_stickerSet set) { } public void loadFeaturedStickers(boolean emoji, boolean cache) { - if (loadingFeaturedStickers[emoji ? 1 : 0] || NekoConfig.disableTrending.Bool()) { + if (loadingFeaturedStickers[emoji ? 1 : 0] || NaConfig.INSTANCE.getDisableFeaturedStickers().Bool()) { return; } loadingFeaturedStickers[emoji ? 1 : 0] = true; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 6e7b5d6825..48acb19a3b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -8963,7 +8963,7 @@ public void onAllEffectsEnd() { } } - if (getDialogId() == getUserConfig().getClientUserId() && (getUserConfig().isPremium() && NekoConfig.disableTrending.Bool())) { + if (getDialogId() == getUserConfig().getClientUserId() && (getUserConfig().isPremium() && !NaConfig.INSTANCE.getDisableFavoriteSearchEmojiTags().Bool())) { actionBarSearchTags = new SearchTagsList(context, ChatActivity.this, contentView, currentAccount, getSavedDialogId(), themeDelegate, true) { @Override protected boolean setFilter(ReactionsLayoutInBubble.VisibleReaction reaction) { @@ -24002,7 +24002,7 @@ private void loadSendAsPeers(boolean animatedUpdate) { } sendAsPeersObj = getMessagesController().getSendAsPeers(dialog_id); if (sendAsPeersObj != null) { - if (NekoConfig.disableTrending.Bool()) { + if (NaConfig.INSTANCE.getDisableNonPremiumChannelChatShow().Bool()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { sendAsPeersObj.peers.removeIf(peer -> peer.premium_required); } @@ -31675,7 +31675,7 @@ public boolean onTouch(View v, MotionEvent event) { sheet.show(); })); } - if (isReactionsAvailable && (!tags || (!getMessagesController().premiumFeaturesBlocked() && (getUserConfig().isPremium() && NekoConfig.disableTrending.Bool())))) { + if (isReactionsAvailable && (!tags || (!getMessagesController().premiumFeaturesBlocked() && (getUserConfig().isPremium() && !NaConfig.INSTANCE.getDisablePremiumFavoriteEmojiTags().Bool())))) { int pad = 22; int sPad = 24; reactionsLayout.setPadding(AndroidUtilities.dp(4) + (LocaleController.isRTL ? 0 : sPad), AndroidUtilities.dp(4), AndroidUtilities.dp(4) + (LocaleController.isRTL ? sPad : 0), AndroidUtilities.dp(pad)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiTabsStrip.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiTabsStrip.java index ae83a8dc2c..fd645dc525 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiTabsStrip.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiTabsStrip.java @@ -47,6 +47,7 @@ import java.util.Map; import tw.nekomimi.nekogram.NekoConfig; +import xyz.nextalone.nagram.NaConfig; public class EmojiTabsStrip extends ScrollableHorizontalScrollView { @@ -493,7 +494,7 @@ public void updateEmojiPacks(ArrayList emojiPacks) { return; } final boolean isPremium = UserConfig.getInstance(UserConfig.selectedAccount).isPremium() || allowEmojisForNonPremium(); - if (NekoConfig.disableTrending.Bool() && !isPremium) { + if (NaConfig.INSTANCE.getDisableFeatuerdEmojis().Bool() && !isPremium) { return; } int childCount = contentView.getChildCount() - packsIndexStart - (settingsTab != null ? 1 : 0); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java index 7edb5eb822..3f91e61b38 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java @@ -147,6 +147,7 @@ import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.ui.PinnedStickerHelper; +import xyz.nextalone.nagram.NaConfig; public class EmojiView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate { @@ -5212,7 +5213,7 @@ private void updateStickerTabs(boolean updateStickerSets) { if (trendingAdapter != null) { trendingAdapter.notifyDataSetChanged(); } - if (!NekoConfig.disableTrending.Bool() && !featured.isEmpty() && (!BuildVars.DEBUG_PRIVATE_VERSION || featuredStickerSets.isEmpty() || preferences.getLong("featured_hidden", 0) == featured.get(0).set.id)) { + if (!NaConfig.INSTANCE.getDisableFeaturedStickers().Bool() && !featured.isEmpty() && (!BuildVars.DEBUG_PRIVATE_VERSION || featuredStickerSets.isEmpty() || preferences.getLong("featured_hidden", 0) == featured.get(0).set.id)) { final int id = mediaDataController.getUnreadStickerSets().isEmpty() ? 2 : 3; final StickerTabView trendingStickersTabView = stickersTab.addStickerIconTab(id, stickerIcons[id]); trendingStickersTabView.textView.setText(LocaleController.getString(R.string.FeaturedStickersShort)); @@ -5396,10 +5397,8 @@ private void updateGifTabs() { gifTabs.addIconTab(0, gifIcons[0]).setContentDescription(LocaleController.getString(R.string.RecentStickers)); } - if (!NekoConfig.disableTrending.Bool()) { - gifTrendingTabNum = gifTabsCount++; - gifTabs.addIconTab(1, gifIcons[1]).setContentDescription(LocaleController.getString(R.string.FeaturedGifs)); - } + gifTrendingTabNum = gifTabsCount++; + gifTabs.addIconTab(1, gifIcons[1]).setContentDescription(LocaleController.getString(R.string.FeaturedGifs)); gifFirstEmojiTabNum = gifTabsCount; final int hPadding = AndroidUtilities.dp(13); @@ -8122,6 +8121,7 @@ private void updateRecentItemsCount() { } public void loadTrendingGifs() { + if (NaConfig.INSTANCE.getDisableFeaturedGifs().Bool()) return; search("", "", true, true, true); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index 9e432a16f0..8668c9d992 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -5979,7 +5979,7 @@ private void updateDialogsHint() { } authHintCell.set(DialogsActivity.this, currentAccount); updateAuthHintCellVisibility(true); - } else if (folderId == 0 && MessagesController.getInstance(currentAccount).pendingSuggestions.contains("PREMIUM_GRACE") && !NekoConfig.disableTrending.Bool()) { + } else if (folderId == 0 && MessagesController.getInstance(currentAccount).pendingSuggestions.contains("PREMIUM_GRACE") && !NaConfig.INSTANCE.getDisablePremiumExpiring().Bool()) { dialogsHintCellVisible = true; dialogsHintCell.setVisibility(View.VISIBLE); dialogsHintCell.setCompact(true); @@ -5995,7 +5995,7 @@ private void updateDialogsHint() { updateDialogsHint(); }); updateAuthHintCellVisibility(false); - } else if (isStarsSubscriptionHintVisible() && !NekoConfig.disableTrending.Bool()) { + } else if (isStarsSubscriptionHintVisible() && !NaConfig.INSTANCE.getDisableStarsSubscription().Bool()) { StarsController c = StarsController.getInstance(currentAccount); dialogsHintCellVisible = true; dialogsHintCell.setVisibility(View.VISIBLE); @@ -6036,7 +6036,7 @@ private void updateDialogsHint() { updateDialogsHint(); }); updateAuthHintCellVisibility(false); - } else if (folderId == 0 && !getMessagesController().premiumPurchaseBlocked() && BirthdayController.getInstance(currentAccount).contains() && !getMessagesController().dismissedSuggestions.contains("BIRTHDAY_CONTACTS_TODAY") && !NekoConfig.disableTrending.Bool()) { + } else if (folderId == 0 && !getMessagesController().premiumPurchaseBlocked() && BirthdayController.getInstance(currentAccount).contains() && !getMessagesController().dismissedSuggestions.contains("BIRTHDAY_CONTACTS_TODAY") && !NaConfig.INSTANCE.getDisableBirthdayContact().Bool()) { BirthdayController.BirthdayState state = BirthdayController.getInstance(currentAccount).getState(); ArrayList users = state.today; dialogsHintCellVisible = true; @@ -6155,7 +6155,7 @@ private void updateDialogsHint() { .show(); }); updateAuthHintCellVisibility(false); - } else if (isPremiumChristmasHintVisible()) { + } else if (isPremiumChristmasHintVisible() && !NaConfig.INSTANCE.getDisablePremiumChristmas().Bool()) { dialogsHintCellVisible = true; dialogsHintCell.setVisibility(View.VISIBLE); dialogsHintCell.setCompact(false); @@ -6178,7 +6178,7 @@ private void updateDialogsHint() { .show(); }); updateAuthHintCellVisibility(false); - } else if (isPremiumRestoreHintVisible()) { + } else if (isPremiumRestoreHintVisible() && !NaConfig.INSTANCE.getDisablePremiumRestore().Bool()) { dialogsHintCellVisible = true; dialogsHintCell.setVisibility(View.VISIBLE); dialogsHintCell.setCompact(false); @@ -6199,7 +6199,7 @@ private void updateDialogsHint() { LocaleController.getString(R.string.RestorePremiumHintMessage) ); updateAuthHintCellVisibility(false); - } else if (isPremiumHintVisible()) { + } else if (isPremiumHintVisible() && !NaConfig.INSTANCE.getDisablePremiumUpgrade().Bool()) { dialogsHintCellVisible = true; dialogsHintCell.setVisibility(View.VISIBLE); dialogsHintCell.setCompact(false); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index acc6d4d4a5..06451777f0 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -161,7 +161,7 @@ public class NekoConfig { public static ConfigItem disableLinkPreviewByDefault = addConfig("DisableLinkPreviewByDefault", configTypeBool, false); public static ConfigItem sendCommentAfterForward = addConfig("SendCommentAfterForward", configTypeBool, true); // public static ConfigItem increaseVoiceMessageQuality = addConfig("IncreaseVoiceMessageQuality", configTypeBool, true); - public static ConfigItem disableTrending = addConfig("DisableTrending", configTypeBool, true); +// public static ConfigItem disableTrending = addConfig("DisableTrending", configTypeBool, true); public static ConfigItem dontSendGreetingSticker = addConfig("DontSendGreetingSticker", configTypeBool, false); public static ConfigItem hideTimeForSticker = addConfig("HideTimeForSticker", configTypeBool, false); public static ConfigItem takeGIFasVideo = addConfig("TakeGIFasVideo", configTypeBool, false); @@ -452,8 +452,8 @@ public static void checkMigrate(boolean force) { sendCommentAfterForward.setConfigBool(preferences.getBoolean("sendCommentAfterForward", true)); // if (preferences.contains("increaseVoiceMessageQuality")) // increaseVoiceMessageQuality.setConfigBool(preferences.getBoolean("increaseVoiceMessageQuality", true)); - if (preferences.contains("disableTrending")) - disableTrending.setConfigBool(preferences.getBoolean("disableTrending", true)); +// if (preferences.contains("disableTrending")) +// disableTrending.setConfigBool(preferences.getBoolean("disableTrending", true)); if (preferences.contains("dontSendGreetingSticker")) dontSendGreetingSticker.setConfigBool(preferences.getBoolean("dontSendGreetingSticker", false)); if (preferences.contains("hideTimeForSticker")) diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index 2c000000f6..d3c024e38a 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -180,7 +180,23 @@ public class NekoChatSettingsActivity extends BaseNekoXSettingsActivity implemen private final AbstractConfigCell disableInstantCameraRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableInstantCamera)); private final AbstractConfigCell disableVibrationRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableVibration)); private final AbstractConfigCell disableProximityEventsRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableProximityEvents)); - private final AbstractConfigCell disableTrendingRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableTrending)); + private final AbstractConfigCell disableTrendingRow = cellGroup.appendCell(new ConfigCellSelectBox("DisableTrending", null, null, () -> { + if (getParentActivity() == null) return; + showDialog(showConfigMenuAlert(getParentActivity(), "DisableTrending", new ArrayList<>() {{ + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisablePremiumUpgrade())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisablePremiumExpiring())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisablePremiumChristmas())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableBirthdayContact())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisablePremiumRestore())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableStarsSubscription())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableFavoriteSearchEmojiTags())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableFeatuerdEmojis())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableFeaturedStickers())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableFeaturedGifs())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisablePremiumFavoriteEmojiTags())); + add(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableNonPremiumChannelChatShow())); + }})); + })); private final AbstractConfigCell disableSwipeToNextRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableSwipeToNext)); private final AbstractConfigCell disableChannelMuteButtonRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableChannelMuteButton())); private final AbstractConfigCell disablePhotoSideActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disablePhotoSideAction)); diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt index f62c830a9e..b0ddbc8888 100644 --- a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/NaConfig.kt @@ -705,6 +705,96 @@ object NaConfig { ConfigItem.configTypeBool, false ) + val disableTrendingFlags = + addConfig( + "DisableTrendingFlags", + ConfigItem.configTypeInt, + 0 + ) + val disableStarsSubscription = + addConfig( + "DisableStarsSubscription", + disableTrendingFlags, + 0, + false + ) + val disablePremiumExpiring = + addConfig( + "DisablePremiumExpiring", + disableTrendingFlags, + 1, + false + ) + val disablePremiumUpgrade = + addConfig( + "DisablePremiumUpgrade", + disableTrendingFlags, + 2, + false + ) + val disablePremiumChristmas = + addConfig( + "DisablePremiumChristmas", + disableTrendingFlags, + 3, + false + ) + val disableBirthdayContact = + addConfig( + "DisableBirthdayContact", + disableTrendingFlags, + 4, + false + ) + val disablePremiumRestore = + addConfig( + "DisablePremiumRestore", + disableTrendingFlags, + 5, + false + ) + val disableFeatuerdEmojis = + addConfig( + "DisableFeatuerdEmojis", + disableTrendingFlags, + 6, + false + ) + val disableFeaturedStickers = + addConfig( + "DisableFeaturedStickers", + disableTrendingFlags, + 7, + false + ) + val disableFeaturedGifs = + addConfig( + "DisableFeaturedGifs", + disableTrendingFlags, + 8, + false + ) + val disablePremiumFavoriteEmojiTags = + addConfig( + "DisablePremiumFavoriteEmojiTags", + disableTrendingFlags, + 9, + false + ) + val disableFavoriteSearchEmojiTags = + addConfig( + "DisableFavoriteSearchEmojiTags", + disableTrendingFlags, + 10, + false + ) + val disableNonPremiumChannelChatShow = + addConfig( + "DisableNonPremiumChannelChatShow", + disableTrendingFlags, + 11, + false + ) private fun addConfig( k: String, diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml index 284e2ce351..7aef1eac51 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml @@ -169,4 +169,16 @@ 禁用 Bot 的打开小程序按钮 使用用户昵称作为标题 改善上传视频画质 + 禁用Stars余额不足通知 + 禁用Premium到期通知 + 禁用Premium升级通知 + 禁用Premium圣诞通知 + 禁用Premium过期恢复通知 + 禁用联系人生日通知 + 禁用收藏夹标签搜索栏Emoji列表 + 禁用热门Premium Emoji + 禁用热门Premium Stickers + 禁用热门GIF图 + 禁用Premium收藏夹Emoji标签 + 禁用非Premium频道马甲显示 diff --git a/TMessagesProj/src/main/res/values/strings_na.xml b/TMessagesProj/src/main/res/values/strings_na.xml index 343f2f3acf..93f62946b2 100644 --- a/TMessagesProj/src/main/res/values/strings_na.xml +++ b/TMessagesProj/src/main/res/values/strings_na.xml @@ -170,4 +170,16 @@ Disable Bot Open Button Use user nickname as Title Enhanced shared video bitrate + Disable Stars low balance notification + Disable Premium expiration notification + Disable Premium upgrade notification + Disable Premium Christmas notification + Disable Premium expiration recovery notification + Disable contact birthday notification + Disable emoji list in favorites tag search bar + Disable popular Premium Emojis + Disable popular Premium Stickers + Disable popular GIFs + Disable Premium favorite emoji tags + Disable non-Premium channel alias display