mirror of https://github.com/NekoX-Dev/NekoX.git
Add channel description translate
This commit is contained in:
parent
886ceeb49f
commit
dad76e025d
|
@ -5,8 +5,8 @@ apply plugin: 'com.android.application'
|
|||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
def verName = "7.1.3-rc05"
|
||||
def verCode = 82
|
||||
def verName = "7.1.3-rc06"
|
||||
def verCode = 84
|
||||
|
||||
def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")
|
||||
|
||||
|
@ -345,6 +345,7 @@ android {
|
|||
}
|
||||
fullPlay {
|
||||
versionNameSuffix '-play'
|
||||
versionCode verCode - 1
|
||||
}
|
||||
fullNoEmoji {
|
||||
versionNameSuffix '-full-no-emoji'
|
||||
|
|
|
@ -645,8 +645,10 @@ public class FileLoader extends BaseController {
|
|||
operation = new FileLoadOperation(document, parentObject);
|
||||
if (MessageObject.isVoiceDocument(document)) {
|
||||
type = MEDIA_DIR_AUDIO;
|
||||
} else if (MessageObject.isVideoDocument(document)) {
|
||||
} else if (MessageObject.isVideoDocument(document) || MessageObject.isGifDocument(document)) {
|
||||
type = MEDIA_DIR_VIDEO;
|
||||
} else if (MessageObject.isStickerDocument(document)) {
|
||||
type = MEDIA_DIR_CACHE;
|
||||
} else {
|
||||
type = MEDIA_DIR_DOCUMENT;
|
||||
}
|
||||
|
|
|
@ -167,6 +167,7 @@ import tw.nekomimi.nekogram.ExternalGcm;
|
|||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
import tw.nekomimi.nekogram.NekoXConfig;
|
||||
import tw.nekomimi.nekogram.NekoXSettingActivity;
|
||||
import tw.nekomimi.nekogram.parts.DialogTransKt;
|
||||
import tw.nekomimi.nekogram.parts.UpdateChecksKt;
|
||||
import tw.nekomimi.nekogram.settings.NekoSettingsActivity;
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil;
|
||||
|
@ -2503,6 +2504,26 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
|||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
builder.addItem(LocaleController.getString("Translate", R.string.Translate),R.drawable.ic_translate, __ -> {
|
||||
try {
|
||||
String about;
|
||||
if (position == locationRow) {
|
||||
about = chatInfo != null && chatInfo.location instanceof TLRPC.TL_channelLocation ? ((TLRPC.TL_channelLocation) chatInfo.location).address : null;
|
||||
} else if (position == channelInfoRow) {
|
||||
about = chatInfo != null ? chatInfo.about : null;
|
||||
} else {
|
||||
about = userInfo != null ? userInfo.about : null;
|
||||
}
|
||||
if (!TextUtils.isEmpty(about)) {
|
||||
DialogTransKt.startTrans(getParentActivity(), about);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
builder.show();
|
||||
|
||||
} else if (position == numberRow) {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package tw.nekomimi.nekogram.parts
|
||||
|
||||
import android.content.Context
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import tw.nekomimi.nekogram.transtale.TranslateDb
|
||||
import tw.nekomimi.nekogram.transtale.Translator
|
||||
import tw.nekomimi.nekogram.transtale.code2Locale
|
||||
import tw.nekomimi.nekogram.utils.AlertUtil
|
||||
import tw.nekomimi.nekogram.utils.UIUtil
|
||||
import tw.nekomimi.nekogram.utils.uDismiss
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
fun startTrans(ctx: Context, text: String) {
|
||||
|
||||
val dialog = AlertUtil.showProgress(ctx)
|
||||
|
||||
val canceled = AtomicBoolean(false)
|
||||
|
||||
dialog.setOnCancelListener {
|
||||
|
||||
canceled.set(true)
|
||||
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
|
||||
fun update(message: String) {
|
||||
|
||||
UIUtil.runOnUIThread(Runnable { dialog.setMessage(message) })
|
||||
|
||||
}
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
|
||||
val target = TranslateDb.currentTarget()
|
||||
|
||||
if (target.contains(text)) {
|
||||
|
||||
dialog.uDismiss()
|
||||
|
||||
AlertUtil.showCopyAlert(ctx, target.query(text) ?: "")
|
||||
|
||||
return@launch
|
||||
|
||||
}
|
||||
|
||||
runCatching {
|
||||
|
||||
val result = Translator.translate(target.code.code2Locale, text)
|
||||
|
||||
if (!canceled.get()) {
|
||||
|
||||
dialog.uDismiss()
|
||||
|
||||
AlertUtil.showCopyAlert(ctx, result)
|
||||
|
||||
}
|
||||
|
||||
}.onFailure {
|
||||
|
||||
dialog.uDismiss()
|
||||
|
||||
if (!canceled.get()) {
|
||||
|
||||
AlertUtil.showTransFailedDialog(ctx, it is UnsupportedOperationException, it.message
|
||||
?: it.javaClass.simpleName) {
|
||||
|
||||
startTrans(ctx, text)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@ class TranslateDb(val code: String) {
|
|||
val db = mkDatabase("translate_caches")
|
||||
|
||||
val repo = HashMap<Locale, TranslateDb>()
|
||||
val chat = db.getRepository(ChatLanguage::class.java)
|
||||
val chat = db.getRepository("chat", ChatLanguage::class.java)
|
||||
|
||||
@JvmStatic fun getChatLanguage(chatId: Int, default: Locale): Locale {
|
||||
|
||||
|
@ -40,7 +40,10 @@ class TranslateDb(val code: String) {
|
|||
|
||||
@JvmStatic fun clearAll() {
|
||||
|
||||
db.listRepositories().map { it.transDbByCode }.forEach { it.clear() }
|
||||
db.listRepositories()
|
||||
.filter { it != "chat" }
|
||||
.map { db.getCollection(it) }
|
||||
.forEach { it.drop() }
|
||||
|
||||
repo.clear()
|
||||
|
||||
|
@ -51,7 +54,6 @@ class TranslateDb(val code: String) {
|
|||
fun clear() = synchronized(this) {
|
||||
|
||||
conn.drop()
|
||||
conn = db.getRepository(code, TransItem::class.java)
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue