diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index a9a568a8a..15f7c1ba6 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -30,6 +30,12 @@ buildscript { } +repositories { + + maven { url "https://oss.sonatype.org/content/repositories/snapshots" } + +} + dependencies { implementation 'androidx.core:core:1.5.0-alpha01' @@ -73,6 +79,11 @@ dependencies { compileOnly "com.google.firebase:firebase-crashlytics:$crashlyticsVersion" compileOnly "com.google.android.play:core:$playCoreVersion" + compileOnly 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT' + compileOnly 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT' + compileOnly 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT' + compileOnly 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT' + releaseImplementation "com.google.firebase:firebase-messaging:$fcmVersion" releaseImplementation "com.google.firebase:firebase-crashlytics:$crashlyticsVersion" releaseImplementation "com.google.android.play:core:$playCoreVersion" @@ -112,8 +123,6 @@ android { versionName verName versionCode verCode - vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] - def appId = null def appHash = null @@ -295,14 +304,67 @@ android { mini { versionNameSuffix '-mini' } + miniNoEmoji { + versionNameSuffix '-mini-no-emoji' + } + miniAppleEmoji { + versionNameSuffix '-mini-apple-emoji' + } + miniNotoEmoji { + versionNameSuffix '-mini-noto-emoji' + } + miniTwitterEmoji { + versionNameSuffix '-mini-twitter-emoji' + } + miniFacebookEmoji { + versionNameSuffix '-mini-facebook-emoji' + } full {} + fullNoEmoji { + versionNameSuffix '-full-no-emoji' + } + fullAppleEmoji { + versionNameSuffix '-full-apple-emoji' + } + fullNotoEmoji { + versionNameSuffix '-full-noto-emoji' + } + fullTwitterEmoji { + versionNameSuffix '-full-twitter-emoji' + } + fullFacebookEmoji { + versionNameSuffix '-full-facebook-emoji' + } } - sourceSets.full { - dependencies { - implementation files('libs/libv2ray.aar') - implementation files('libs/ss-rust-release.aar') - implementation files('libs/ssr-libev-release.aar') + sourceSets.all { set -> + if (set.name.startsWith("full")) { + set.dependencies { + implementation files('libs/libv2ray.aar') + implementation files('libs/ss-rust-release.aar') + implementation files('libs/ssr-libev-release.aar') + } + } + if (set.name.matches("(mini|full).*")) { + if (set.name.contains("Apple")) { + set.dependencies { + implementation 'com.vanniktech:emoji-ios:0.7.0-SNAPSHOT' + } + } else if (set.name.contains("Noto")) { + set.dependencies { + implementation 'com.vanniktech:emoji-google:0.7.0-SNAPSHOT' + } + } else if (set.name.contains("Twitter")) { + set.dependencies { + implementation 'com.vanniktech:emoji-twitter:0.7.0-SNAPSHOT' + } + } else if (set.name.contains("Facebook")) { + set.dependencies { + implementation 'com.vanniktech:emoji-facebook:0.7.0-SNAPSHOT' + } + } else { + set.assets.srcDirs = ["src/main/assets", "src/emojis/blob"] + } } } @@ -317,7 +379,7 @@ android { applicationVariants.all { variant -> variant.outputs.all { output -> - outputFileName = outputFileName.replace("TMessagesProj","NekoX") + outputFileName = outputFileName.replace("TMessagesProj", "NekoX") } def assembleTgVoipDexTaskName = "assemble${variant.name.capitalize()}TgVoipDex" diff --git a/TMessagesProj/src/main/assets/fonts/blob_compat.ttf b/TMessagesProj/src/emojis/blob/fonts/blob_compat.ttf similarity index 100% rename from TMessagesProj/src/main/assets/fonts/blob_compat.ttf rename to TMessagesProj/src/emojis/blob/fonts/blob_compat.ttf diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java index 0d562d0f0..58b5b4b13 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java @@ -35,6 +35,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import tw.nekomimi.nekogram.EmojiProvider; import tw.nekomimi.nekogram.NekoConfig; public class Emoji { @@ -264,8 +265,6 @@ public class Emoji { return rect; } - private static Typeface blobCompat; - @Override public void draw(Canvas canvas) { Rect b; @@ -275,33 +274,23 @@ public class Emoji { b = getBounds(); } - if (!NekoConfig.useSystemEmoji) { + String emoji = fixEmoji(EmojiData.data[info.page][info.emojiIndex]); - if (blobCompat == null) { - - blobCompat = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), "fonts/blob_compat.ttf"); + if (NekoConfig.useSystemEmoji || EmojiProvider.noEmoji || EmojiProvider.isFont || !EmojiProvider.contains(emoji)) { + if (!NekoConfig.useSystemEmoji && EmojiProvider.isFont) { + textPaint.setTypeface(EmojiProvider.getFont()); } - textPaint.setTypeface(blobCompat); + textPaint.setTextSize(b.height() * 0.8f); + canvas.drawText(emoji, 0, emoji.length(), b.left, b.bottom - b.height() * 0.225f, textPaint); + + } else { + + canvas.drawBitmap(EmojiProvider.readDrawable(emoji).getBitmap(), null, b, paint); } - String emoji = fixEmoji(EmojiData.data[info.page][info.emojiIndex]); - textPaint.setTextSize(b.height() * 0.8f); - canvas.drawText(emoji, 0, emoji.length(), b.left, b.bottom - b.height() * 0.225f, textPaint); - -// -// if (emojiBmp[info.page][info.page2] == null) { -// loadEmoji(info.page, info.page2); -// canvas.drawRect(getBounds(), placeholderPaint); -// return; -// } -// -// -// //if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) { -// canvas.drawBitmap(emojiBmp[info.page][info.page2], null, b, paint); -// //} } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java index a4d97f6f8..61a0d7097 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java @@ -98,7 +98,7 @@ public class BottomSheet extends Dialog { protected String behindKeyboardColorKey = Theme.key_dialogBackground; protected int behindKeyboardColor; - private boolean canDismissWithSwipe = true; + private boolean canDismissWithSwipe = false; private boolean allowCustomAnimation = true; private boolean showWithoutAnimation; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 67005bcfd..aac881925 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -549,11 +549,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter return Unit.INSTANCE; }); } - builder.addItem(LocaleController.getString("SwitchVersion", R.string.SwitchVersion), R.drawable.baseline_replay_24, (it) -> { - builder.dismiss(); - UpdateChecksKt.switchVersion(getParentActivity()); - return Unit.INSTANCE; - }); + if (BuildConfig.BUILD_TYPE.startsWith("release")) { + builder.addItem(LocaleController.getString("SwitchVersion", R.string.SwitchVersion), R.drawable.baseline_replay_24, (it) -> { + builder.dismiss(); + UpdateChecksKt.switchVersion(getParentActivity()); + return Unit.INSTANCE; + }); + } if (NekoXConfig.developerModeEntrance || NekoXConfig.developerMode) { builder.addItem(LocaleController.getString("DeveloperSettings", R.string.DeveloperSettings), R.drawable.baseline_developer_mode_24, (it) -> { builder.dismiss(); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/EmojiProvider.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/EmojiProvider.kt new file mode 100644 index 000000000..cc848276f --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/EmojiProvider.kt @@ -0,0 +1,84 @@ +package tw.nekomimi.nekogram + +import android.graphics.Typeface +import android.graphics.drawable.BitmapDrawable +import com.vanniktech.emoji.emoji.Emoji +import com.vanniktech.emoji.facebook.FacebookEmojiProvider +import com.vanniktech.emoji.google.GoogleEmojiProvider +import com.vanniktech.emoji.ios.IosEmojiProvider +import com.vanniktech.emoji.twitter.TwitterEmojiProvider +import org.telegram.messenger.ApplicationLoader +import org.telegram.messenger.BuildConfig +import java.util.* + + +object EmojiProvider { + + val type = BuildConfig.FLAVOR + + @JvmField + val noEmoji = type.contains("NoEmoji") + + // default use blob + @JvmField + val isFont = !type.contains("Emoji") + + @JvmStatic + val font by lazy { + if (!isFont) throw IllegalStateException() + val resName = when { + !type.contains("emoji") -> "blob_compat.ttf" + else -> throw IllegalStateException() + } + Typeface.createFromAsset(ApplicationLoader.applicationContext.assets, "fonts/$resName"); + } + + private val isApple = type.contains("Apple") + private val isNoto = type.contains("Noto") + private val isTwitter = type.contains("Twitter") + private val isFacebook = type.contains("Facebook") + + private val emojiMap = LinkedHashMap() + + init { + + if (!isFont && !noEmoji) { + + val provider = when { + isApple -> IosEmojiProvider() + isNoto -> GoogleEmojiProvider() + isTwitter -> TwitterEmojiProvider() + isFacebook -> FacebookEmojiProvider() + else -> throw IllegalStateException() + } + + val categoriesSize = provider.categories.size + //noinspection ForLoopReplaceableByForEach + for (i in 0 until categoriesSize) { + val emojis = provider.categories[i].emojis + val emojisSize = emojis.size + for (j in 0 until emojisSize) { + val emoji = emojis[j] + val unicode = emoji.unicode + val variants = emoji.variants + emojiMap[unicode] = emoji + for (k in variants.indices) { + val variant = variants[k] + val variantUnicode = variant.unicode + emojiMap[variantUnicode] = variant + } + } + + } + + } + + } + + @JvmStatic + fun contains(emoji: String) = emojiMap.contains(emoji) + + @JvmStatic + fun readDrawable(emoji: String) = emojiMap[emoji]!!.getDrawable(ApplicationLoader.applicationContext) as BitmapDrawable + +} \ No newline at end of file diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/parts/UpdateChecks.kt b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/parts/UpdateChecks.kt index f24db72b8..b714aa6b6 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/parts/UpdateChecks.kt +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/parts/UpdateChecks.kt @@ -2,6 +2,7 @@ package tw.nekomimi.nekogram.parts import android.app.Activity import android.content.IntentSender +import cn.hutool.core.util.StrUtil import com.google.android.play.core.appupdate.AppUpdateManagerFactory import com.google.android.play.core.install.InstallStateUpdatedListener import com.google.android.play.core.install.model.AppUpdateType @@ -11,7 +12,6 @@ import org.json.JSONObject import org.telegram.messenger.BuildConfig import org.telegram.messenger.LocaleController import org.telegram.messenger.R -import org.telegram.ui.Cells.TextCell import tw.nekomimi.nekogram.BottomBuilder import tw.nekomimi.nekogram.ExternalGcm import tw.nekomimi.nekogram.NekoXConfig @@ -22,71 +22,82 @@ fun Activity.switchVersion() { val builder = BottomBuilder(this) - builder.addItems(arrayOf( - "Mini Release", - "Mini Release NoGcm", - "Full Release", - "Full Release NoGcm" - ).filterIndexed { index, text -> + fun addVersion(fPrefix: String, fSuffix: String, noGcm: Boolean) { - !(BuildConfig.BUILD_TYPE == when { - text.endsWith("NoGcm") -> "releaseNoGcm" - else -> "release" - } && BuildConfig.FLAVOR == text.substringBefore(" ").toLowerCase()) + var buildType = "Release" - }.toTypedArray()) { index: Int, text: String, _: TextCell -> + if (noGcm) buildType += "NoGcm" - builder.dismiss() + builder.addItem("$fPrefix $buildType $fSuffix".trim()) { - val buildType = when { - text.endsWith("NoGcm") -> "releaseNoGcm" - else -> "release" - } + val flavor = (fPrefix.toLowerCase() + fSuffix).trim() - val flavor = text.substringBefore(" ").toLowerCase() + buildType = StrUtil.lowerFirst(buildType) - val progress = AlertUtil.showProgress(this) + val progress = AlertUtil.showProgress(this) - progress.show() + progress.show() - UIUtil.runOnIoDispatcher { + UIUtil.runOnIoDispatcher { - val ex = mutableListOf() + val ex = mutableListOf() - UpdateUtil.updateUrls.forEach { url -> + UpdateUtil.updateUrls.forEach { url -> - runCatching { + runCatching { - val updateInfo = JSONObject(HttpUtil.get("$url/update.json")) + val updateInfo = JSONObject(HttpUtil.get("$url/update.json")) - val code = updateInfo.getInt("versionCode") + val code = updateInfo.getInt("versionCode") - UIUtil.runOnUIThread { + UIUtil.runOnUIThread { - progress.dismiss() + progress.dismiss() - UpdateUtil.doUpdate(this, code, updateInfo.getString("defaultFlavor"), buildType, flavor) + UpdateUtil.doUpdate(this, code, updateInfo.getString("defaultFlavor"), buildType, flavor) + + } + + return@runOnIoDispatcher + + }.onFailure { + + ex.add(it) } - return@runOnIoDispatcher - - }.onFailure { - - ex.add(it) - } + progress.dismiss() + + AlertUtil.showToast(ex.joinToString("\n") { it.message ?: it.javaClass.simpleName }) + } - progress.dismiss() - - AlertUtil.showToast(ex.joinToString("\n") { it.message ?: it.javaClass.simpleName }) - } } + fun addVersion(fPrefix: String, fSuffix: String) { + + addVersion(fPrefix, fSuffix, false) + addVersion(fPrefix, fSuffix, true) + + } + + fun addVersion(fPrefix: String) { + + arrayOf("", "NoEmoji", "Apple", "Noto", "Twitter", "Facebook").forEach { + + addVersion(fPrefix, "${it}Emoji") + + } + + } + + addVersion("Full") + addVersion("Mini") + builder.show() } 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 53a60d285..c419ba79a 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -47,6 +47,7 @@ import java.util.concurrent.atomic.AtomicReference; import cn.hutool.core.util.StrUtil; import kotlin.Unit; import tw.nekomimi.nekogram.BottomBuilder; +import tw.nekomimi.nekogram.EmojiProvider; import tw.nekomimi.nekogram.NekoConfig; import tw.nekomimi.nekogram.transtale.Translator; import tw.nekomimi.nekogram.transtale.TranslatorKt; @@ -573,7 +574,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { appearanceRow = rowCount++; typefaceRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? rowCount++ : -1; useDefaultThemeRow = rowCount++; - useSystemEmojiRow = rowCount++; + useSystemEmojiRow = EmojiProvider.noEmoji ? -1 : rowCount++; transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; forceTabletRow = rowCount++; avatarAsDrawerBackgroundRow = rowCount++;