fixed errors
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
package ru.vtosters.lite.translators;
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
public class Translate{
|
||||
public static void dialog(String text) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
String translated;
|
||||
|
||||
Log.d("Translate", text + " will be translated");
|
||||
|
||||
try {
|
||||
translated = YandexTranslator.translate(text); // for future
|
||||
} catch (Exception e) {
|
||||
translated = "Error";
|
||||
Log.e("Translate", e.getMessage());
|
||||
}
|
||||
|
||||
Context ctx = getGlobalContext();
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
|
||||
alertDialog.setTitle("Переводчик");
|
||||
alertDialog.setMessage(translated);
|
||||
alertDialog.setPositiveButton("Закрыть", (dialog, which) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
var alert = alertDialog.create();
|
||||
alert.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package ru.vtosters.lite.ui.dialogs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import ru.vtosters.lite.translators.YandexTranslator;
|
||||
|
||||
public class Translate {
|
||||
public static void showTranslatedText(Context context, String text) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
var translation = YandexTranslator.translate(text);
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
showDialog(context, translation);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("Translate", e + "");
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static void showDialog(Context context, String text) {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
|
||||
alertDialog.setTitle("Переводчик");
|
||||
alertDialog.setMessage(text);
|
||||
alertDialog.setPositiveButton("Закрыть", (dialog, which) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
var alert = alertDialog.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user