DeepLApi test
This commit is contained in:
@@ -9,5 +9,6 @@ public enum MsgAction{
|
||||
DELETE,
|
||||
SPAM,
|
||||
PIN,
|
||||
UNPIN
|
||||
UNPIN,
|
||||
TRANSLATE
|
||||
}
|
||||
@@ -5,10 +5,12 @@ import com.vk.im.engine.ImConfig;
|
||||
import com.vk.im.engine.ImEngine;
|
||||
import com.vk.im.engine.models.dialogs.Dialog;
|
||||
import com.vk.im.engine.models.messages.Msg;
|
||||
import com.vk.im.engine.models.messages.MsgFromUser;
|
||||
import com.vk.im.engine.utils.MsgPermissionHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public final class MsgActionHelper{
|
||||
@@ -32,6 +34,7 @@ public final class MsgActionHelper{
|
||||
CollectionExt.a(arrayList, MsgAction.SPAM, MsgPermissionHelper.b.h(aVar));
|
||||
CollectionExt.a(arrayList, MsgAction.PIN, MsgPermissionHelper.b.e(aVar));
|
||||
CollectionExt.a(arrayList, MsgAction.UNPIN, MsgPermissionHelper.b.i(aVar));
|
||||
CollectionExt.a(arrayList, MsgAction.TRANSLATE, true);
|
||||
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package ru.vtosters.lite.net.translate;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import ru.vtosters.lite.net.NetCall;
|
||||
import ru.vtosters.lite.net.NetCallback;
|
||||
import ru.vtosters.lite.net.NetClient;
|
||||
import ru.vtosters.lite.net.NetRequest;
|
||||
import ru.vtosters.lite.net.NetResponse;
|
||||
|
||||
public class DeepLApi{
|
||||
private static final NetClient client = new NetClient.Builder().build();
|
||||
private static JSONObject resp;
|
||||
|
||||
public static void getTranslation(String text, String to){ // Get translation from DeepL private API using Input text and Language code which you want to translate to
|
||||
String uri = "https://www2.deepl.com/jsonrpc";
|
||||
String key = "9";
|
||||
|
||||
try {
|
||||
var xinst = "d1c8bfe3-639d-4af2-af66-2da461ce4b8c";
|
||||
var android = "12";
|
||||
var phone = "GM1917";
|
||||
|
||||
TreeMap<String, String> treeMap = new TreeMap<>(); // create map for request
|
||||
treeMap.put("Host", "www2.deepl.com");
|
||||
treeMap.put("referer", "https://www.deepl.com/");
|
||||
treeMap.put("x-instance", xinst);
|
||||
treeMap.put("user-agent", "DeepL/1.3.1(34) Android " + android + " (" + phone + ";armv8l)");
|
||||
treeMap.put("x-app-os-name", "Android");
|
||||
treeMap.put("x-app-os-version", android);
|
||||
treeMap.put("x-app-version", "1.3.1");
|
||||
treeMap.put("x-app-build", "34");
|
||||
treeMap.put("x-app-device", phone);
|
||||
treeMap.put("x-app-instance-id", xinst);
|
||||
treeMap.put("content-type", "application/json; charset=utf-8");
|
||||
treeMap.put("content-length", uri.length() + "");
|
||||
treeMap.put("accept-encoding", "gzip");
|
||||
|
||||
client.newCall(new NetRequest.Builder().url(uri).post().params(treeMap).build()).enqueue(new NetCallback() {
|
||||
@Override
|
||||
public void onResponse(NetCall call, NetResponse response){
|
||||
Log.d("DeepLApi", "Response: " + response.getDataString());
|
||||
try {
|
||||
resp = new JSONObject(response.getDataString()).optJSONObject("result");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(NetCall call, IOException e) {
|
||||
Log.d("DeepLApi", "Failure: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
if (resp == null) {
|
||||
Log.d("DeepLApi", "Response is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var lang = resp.optString("lang"); // get language code from response
|
||||
var texts = resp.optJSONArray("texts").getJSONObject(0);
|
||||
var result = texts.optString("text"); // get translation result as text
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("DeepLApi", "Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package ru.vtosters.lite.net.translate;
|
||||
public class DeepLJson{
|
||||
public static void main(String text) {
|
||||
|
||||
}
|
||||
}
|
||||
+9
-1
@@ -583,7 +583,15 @@
|
||||
.method public a(Lcom/vk/im/ui/components/common/MsgAction;Lcom/vk/im/engine/models/messages/Msg;)V
|
||||
.locals 1
|
||||
|
||||
.line 20
|
||||
invoke-static {p1, p2}, Lru/vtosters/lite/dnr/DNRInjector;->onClickMsg(Lcom/vk/im/ui/components/common/MsgAction;Lcom/vk/im/engine/models/messages/Msg;)Z
|
||||
|
||||
move-result v0
|
||||
|
||||
if-nez v0, :cond_228
|
||||
|
||||
goto :goto_0
|
||||
|
||||
:cond_228
|
||||
sget-object v0, Lcom/vk/im/ui/components/msg_list/g;->$EnumSwitchMapping$0:[I
|
||||
|
||||
invoke-virtual {p1}, Ljava/lang/Enum;->ordinal()I
|
||||
|
||||
+20
-1
@@ -51,7 +51,7 @@
|
||||
|
||||
invoke-direct {v0, v1}, Lcom/vk/im/ui/components/viewcontrollers/popup/DelegateMsg$a;-><init>(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
|
||||
const/16 v0, 0x9
|
||||
const/16 v0, 0xa
|
||||
|
||||
new-array v0, v0, [Lkotlin/Pair;
|
||||
|
||||
@@ -208,6 +208,25 @@
|
||||
|
||||
aput-object v1, v0, v2
|
||||
|
||||
|
||||
.line 9
|
||||
sget-object v1, Lcom/vk/im/ui/components/common/MsgAction;->TRANSLATE:Lcom/vk/im/ui/components/common/MsgAction;
|
||||
|
||||
new-instance v2, Lcom/vk/im/ui/components/viewcontrollers/popup/DelegateMsg$a$a;
|
||||
|
||||
sget v3, Lcom/vk/im/ui/m;->vkim_msg_action_spam:I
|
||||
|
||||
invoke-direct {v2, v3}, Lcom/vk/im/ui/components/viewcontrollers/popup/DelegateMsg$a$a;-><init>(I)V
|
||||
|
||||
invoke-static {v1, v2}, Lkotlin/Tuples;->a(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
|
||||
|
||||
move-result-object v1
|
||||
|
||||
const/16 v2, 0x9
|
||||
|
||||
aput-object v1, v0, v2
|
||||
|
||||
|
||||
.line 10
|
||||
invoke-static {v0}, Lkotlin/collections/c0;->b([Lkotlin/Pair;)Ljava/util/LinkedHashMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user