mirror of https://github.com/NekoX-Dev/NekoX.git
Fixes
This commit is contained in:
parent
ca9e3928a3
commit
9a2a1837b3
|
@ -133,9 +133,7 @@ public class DrawerProfileCell extends FrameLayout {
|
|||
}
|
||||
|
||||
private boolean useAdb() {
|
||||
|
||||
return NekoConfig.avatarAsDrawerBackground && ImageLocation.isUserHasPhoto(user);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,7 +198,11 @@ public class DrawerProfileCell extends FrameLayout {
|
|||
}
|
||||
|
||||
public boolean isInAvatar(float x, float y) {
|
||||
return x >= avatarImageView.getLeft() && x <= avatarImageView.getRight() && y >= avatarImageView.getTop() && y <= avatarImageView.getBottom();
|
||||
if (useAdb()) {
|
||||
return y <= arrowView.getTop();
|
||||
} else {
|
||||
return x >= avatarImageView.getLeft() && x <= avatarImageView.getRight() && y >= avatarImageView.getTop() && y <= avatarImageView.getBottom();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAvatar() {
|
||||
|
@ -238,7 +240,7 @@ public class DrawerProfileCell extends FrameLayout {
|
|||
avatarDrawable.setColor(Theme.getColor(Theme.key_avatar_backgroundInProfileBlue));
|
||||
avatarImageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, user);
|
||||
if (useAdb()) {
|
||||
avatarBackgroundView.setImage(ImageLocation.getForUser(user, true), "512_512", avatarDrawable, user);
|
||||
avatarBackgroundView.setImage(ImageLocation.getForUser(user, true), "512_512", new ColorDrawable(0x00000000), user);
|
||||
avatarBackgroundView.setVisibility(VISIBLE);
|
||||
avatarImageView.setVisibility(INVISIBLE);
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package tw.nekomimi.nekogram;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.BaseController;
|
||||
import org.telegram.messenger.MessageObject;
|
||||
|
@ -29,10 +27,8 @@ public class MessageHelper extends BaseController {
|
|||
|
||||
public void resetMessageContent(long dialog_id, MessageObject messageObject) {
|
||||
TLRPC.Message message = messageObject.messageOwner;
|
||||
final SparseArray<TLRPC.User> usersDict = new SparseArray<>();
|
||||
final SparseArray<TLRPC.Chat> chatsDict = new SparseArray<>();
|
||||
|
||||
MessageObject obj = new MessageObject(currentAccount, message, usersDict, chatsDict, true, true);
|
||||
MessageObject obj = new MessageObject(currentAccount, message, true, true);
|
||||
|
||||
ArrayList<MessageObject> arrayList = new ArrayList<>();
|
||||
arrayList.add(obj);
|
||||
|
|
|
@ -201,6 +201,8 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
if (view instanceof TextCheckCell) {
|
||||
((TextCheckCell) view).setChecked(NekoConfig.hidePhone);
|
||||
}
|
||||
parentLayout.rebuildAllFragmentViews(false, false);
|
||||
getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged);
|
||||
} else if (position == disableUndoRow) {
|
||||
NekoConfig.toggleDisableUndo();
|
||||
if (view instanceof TextCheckCell) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.telegram.messenger.LocaleController
|
|||
import org.telegram.messenger.R
|
||||
import tw.nekomimi.nekogram.NekoConfig
|
||||
import tw.nekomimi.nekogram.PopupBuilder
|
||||
import tw.nekomimi.nekogram.transtale.source.GoogleWebTranslator
|
||||
import tw.nekomimi.nekogram.transtale.source.GoogleAppTranslator
|
||||
import tw.nekomimi.nekogram.transtale.source.LingoTranslator
|
||||
import tw.nekomimi.nekogram.transtale.source.YandexTranslator
|
||||
import tw.nekomimi.nekogram.utils.UIUtil
|
||||
|
@ -82,7 +82,7 @@ interface Translator {
|
|||
}
|
||||
|
||||
val translator = when (NekoConfig.translationProvider) {
|
||||
in 1..2 -> GoogleWebTranslator
|
||||
in 1..2 -> GoogleAppTranslator
|
||||
3 -> LingoTranslator
|
||||
4 -> YandexTranslator
|
||||
else -> throw IllegalArgumentException()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package tw.nekomimi.nekogram.transtale.source
|
||||
|
||||
import cn.hutool.core.util.StrUtil
|
||||
import kotlinx.coroutines.delay
|
||||
import okhttp3.Request
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.telegram.messenger.LocaleController
|
||||
import org.telegram.messenger.R
|
||||
import tw.nekomimi.nekogram.NekoConfig
|
||||
|
@ -11,11 +10,8 @@ import tw.nekomimi.nekogram.transtale.TransUtils
|
|||
import tw.nekomimi.nekogram.transtale.Translator
|
||||
import tw.nekomimi.nekogram.utils.HttpUtil
|
||||
import tw.nekomimi.nekogram.utils.applyUserAgent
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object GoogleWebTranslator : Translator {
|
||||
|
||||
lateinit var tkk: LongArray
|
||||
object GoogleAppTranslator : Translator {
|
||||
|
||||
override suspend fun doTranslate(from: String, to: String, query: String): String {
|
||||
|
||||
|
@ -27,59 +23,15 @@ object GoogleWebTranslator : Translator {
|
|||
|
||||
}
|
||||
|
||||
for (index in 0 until 4) {
|
||||
|
||||
if (!GoogleWebTranslator::tkk.isInitialized) {
|
||||
|
||||
val url = "https://translate.google." + if (NekoConfig.translationProvider == 2) "cn" else "com"
|
||||
|
||||
val response = runCatching {
|
||||
(if (NekoConfig.translationProvider == 2) HttpUtil.okHttpClientNoDoh else HttpUtil.okHttpClient).newCall(Request.Builder().url(url).applyUserAgent().build()).execute()
|
||||
}.recoverCatching {
|
||||
HttpUtil.okHttpClientWithCurrProxy.newCall(Request.Builder().url(url).applyUserAgent().build()).execute()
|
||||
}.getOrThrow()
|
||||
|
||||
if (response.code != 200) {
|
||||
|
||||
error("HTTP ${response.code} : ${response.body?.string()}")
|
||||
|
||||
}
|
||||
|
||||
val html = response.body?.string()
|
||||
|
||||
if (html.isNullOrBlank()) {
|
||||
|
||||
error("Tkk init failed")
|
||||
|
||||
}
|
||||
|
||||
val matcher = Pattern.compile("tkk\\s*[:=]\\s*['\"]([0-9]+)\\.([0-9]+)['\"]", Pattern.CASE_INSENSITIVE or Pattern.UNICODE_CASE).matcher(html)
|
||||
|
||||
tkk = if (matcher.find() && matcher.group(1) != null && matcher.group(2) != null) {
|
||||
longArrayOf(matcher.group(1).toLong(), matcher.group(2).toLong())
|
||||
} else {
|
||||
delay(1000L)
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!GoogleWebTranslator::tkk.isInitialized) error("Tkk match failed")
|
||||
|
||||
|
||||
val tk = TransUtils.signWeb(query, tkk[0], tkk[1])
|
||||
|
||||
val url = "https://translate.google." + (if (NekoConfig.translationProvider == 2) "cn" else "com") + "/translate_a/single?client=webapp&dt=t&sl=auto" +
|
||||
val url = "https://translate.google." + (if (NekoConfig.translationProvider == 2) "cn" else "com") + "/translate_a/single?dj=1" +
|
||||
"&q=" + TransUtils.encodeURIComponent(query) +
|
||||
"&sl=auto" +
|
||||
"&tl=" + to +
|
||||
"&tk=" + tk +
|
||||
"&q=" + TransUtils.encodeURIComponent(query) // 不能用URLEncoder
|
||||
"&ie=UTF-8&oe=UTF-8&client=at&dt=t&otf=2"
|
||||
|
||||
val response = runCatching {
|
||||
(if (NekoConfig.translationProvider == 2) HttpUtil.okHttpClientNoDoh else HttpUtil.okHttpClient).newCall(Request.Builder().url(url).applyUserAgent().build()).execute()
|
||||
(if (NekoConfig.translationProvider == 2) HttpUtil.okHttpClientNoDoh else HttpUtil.okHttpClient).newCall(Request.Builder().url(url)
|
||||
.header("User-Agent", "GoogleTranslate/6.14.0.04.343003216 (Linux; U; Android 10; Redmi K20 Pro)").build()).execute()
|
||||
}.recoverCatching {
|
||||
HttpUtil.okHttpClientWithCurrProxy.newCall(Request.Builder().url(url).applyUserAgent().build()).execute()
|
||||
}.getOrThrow()
|
||||
|
@ -92,9 +44,9 @@ object GoogleWebTranslator : Translator {
|
|||
|
||||
val result = StringBuilder()
|
||||
|
||||
val array = JSONArray(response.body!!.string()).getJSONArray(0)
|
||||
val array = JSONObject(response.body!!.string()).getJSONArray("sentences")
|
||||
for (index in 0 until array.length()) {
|
||||
result.append(array.getJSONArray(index).getString(0))
|
||||
result.append(array.getJSONObject(index).getString("trans"))
|
||||
}
|
||||
|
||||
return result.toString()
|
Loading…
Reference in New Issue