translate

This commit is contained in:
Thomas 2022-10-29 19:03:31 +02:00
parent ec77f4b7b6
commit b0bde6e66d
8 changed files with 91 additions and 76 deletions

View file

@ -34,14 +34,12 @@
tools:replace="android:allowBackup">
<activity
android:name="app.fedilab.android.activities.MainActivity"
android:name=".activities.MainActivity"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
@ -66,14 +64,11 @@
<activity-alias
android:name=".activities.MainActivity.Bubbles"
android:enabled="false"
android:enabled="true"
android:exported="true"
android:icon="@mipmap/ic_launcher_bubbles"
android:roundIcon="@mipmap/ic_launcher_bubbles_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="bubbles" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -87,9 +82,6 @@
android:icon="@mipmap/ic_launcher_fediverse"
android:roundIcon="@mipmap/ic_launcher_fediverse_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="Fediverse" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -103,9 +95,6 @@
android:icon="@mipmap/ic_launcher_hero"
android:roundIcon="@mipmap/ic_launcher_hero_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="hero" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -119,9 +108,6 @@
android:icon="@mipmap/ic_launcher_atom"
android:roundIcon="@mipmap/ic_launcher_atom_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="atom" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -135,9 +121,6 @@
android:icon="@mipmap/ic_launcher_crash"
android:roundIcon="@mipmap/ic_launcher_crash_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="braincrash" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -151,9 +134,6 @@
android:icon="@mipmap/ic_launcher_mastalab"
android:roundIcon="@mipmap/ic_launcher_mastalab_round"
android:targetActivity=".activities.MainActivity">
<meta-data
android:name="icon"
android:value="mastalab" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View file

@ -26,8 +26,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@ -214,44 +212,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
BaseMainActivity.currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
}
Intent intentIni = getIntent();
PackageManager pm = getPackageManager();
try {
if (intentIni != null && intentIni.getComponent() != null) {
ActivityInfo ai = pm.getActivityInfo(intentIni.getComponent(), PackageManager.GET_META_DATA);
String icon;
Bundle b = ai.metaData;
if (b != null) {
icon = b.getString("icon");
if (icon != null) {
switch (icon) {
case "fediverse":
mLauncher = iconLauncher.FEDIVERSE;
break;
case "hero":
mLauncher = iconLauncher.HERO;
break;
case "atom":
mLauncher = iconLauncher.ATOM;
break;
case "braincrash":
mLauncher = iconLauncher.BRAINCRASH;
break;
default:
mLauncher = iconLauncher.BUBBLES;
}
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(getString(R.string.SET_LOGO_LAUNCHER), icon);
editor.apply();
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
mamageNewIntent(intentIni);
mamageNewIntent(getIntent());
ThemeHelper.initiliazeColors(BaseMainActivity.this);
filterFetched = false;
networkStateReceiver = new NetworkStateReceiver();

View file

@ -21,6 +21,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
@ -44,6 +45,7 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.ViewPager;
import com.github.stom79.mytransl.MyTransL;
@ -171,7 +173,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
statusToTranslate = Html.fromHtml(descriptionToTranslate, Html.FROM_HTML_MODE_LEGACY).toString();
else
statusToTranslate = Html.fromHtml(descriptionToTranslate).toString();
myTransL.translate(statusToTranslate, MyTransL.getLocale(), params, new Results() {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MediaActivity.this);
String translate = sharedpreferences.getString(getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
if (translate != null && translate.equalsIgnoreCase("default")) {
translate = MyTransL.getLocale();
}
myTransL.translate(statusToTranslate, translate, params, new Results() {
@Override
public void onSuccess(Translate translate) {
if (translate.getTranslatedContent() != null) {
@ -231,7 +238,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
statusToTranslate = Html.fromHtml(descriptionToTranslate, Html.FROM_HTML_MODE_LEGACY).toString();
else
statusToTranslate = Html.fromHtml(descriptionToTranslate).toString();
myTransL.translate(statusToTranslate, MyTransL.getLocale(), params, new Results() {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MediaActivity.this);
String translate = sharedpreferences.getString(getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
if (translate != null && translate.equalsIgnoreCase("default")) {
translate = MyTransL.getLocale();
}
myTransL.translate(statusToTranslate, translate, params, new Results() {
@Override
public void onSuccess(Translate translate) {
if (translate.getTranslatedContent() != null) {

View file

@ -16,12 +16,14 @@ package app.fedilab.android.ui.drawer;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;
import com.github.stom79.mytransl.MyTransL;
@ -88,7 +90,12 @@ public class ReleaseNoteAdapter extends RecyclerView.Adapter<ReleaseNoteAdapter.
params.setFormat(Params.fType.TEXT);
params.setSource_lang("auto");
myTransL.setLibretranslateDomain("translate.fedilab.app");
myTransL.translate(note.note, MyTransL.getLocale(), params, new Results() {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
if (translate != null && translate.equalsIgnoreCase("default")) {
translate = MyTransL.getLocale();
}
myTransL.translate(note.note, translate, params, new Results() {
@Override
public void onSuccess(Translate translate) {
if (translate.getTranslatedContent() != null) {

View file

@ -1804,11 +1804,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
params.setSource_lang("auto");
myTransL.setLibretranslateDomain("translate.fedilab.app");
String statusToTranslate;
String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
if (translate != null && translate.equalsIgnoreCase("default")) {
translate = MyTransL.getLocale();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
statusToTranslate = Html.fromHtml(statusToDeal.content, Html.FROM_HTML_MODE_LEGACY).toString();
else
statusToTranslate = Html.fromHtml(statusToDeal.content).toString();
myTransL.translate(statusToTranslate, MyTransL.getLocale(), params, new Results() {
myTransL.translate(statusToTranslate, translate, params, new Results() {
@Override
public void onSuccess(Translate translate) {
if (translate.getTranslatedContent() != null) {

View file

@ -28,6 +28,7 @@ import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.SeekBarPreference;
import app.fedilab.android.BuildConfig;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.LogoHelper;
@ -92,7 +93,7 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen
if (key.compareToIgnoreCase(getString(R.string.SET_TIMELINES_IN_A_LIST)) == 0) {
recreate = true;
}
editor.apply();
if (key.compareToIgnoreCase(getString(R.string.SET_LOGO_LAUNCHER)) == 0) {
ListPreference SET_LOGO_LAUNCHER = findPreference(getString(R.string.SET_LOGO_LAUNCHER));
if (SET_LOGO_LAUNCHER != null) {
@ -100,45 +101,44 @@ public class FragmentInterfaceSettings extends PreferenceFragmentCompat implemen
setIcon(requireActivity(), SET_LOGO_LAUNCHER.getValue());
SET_LOGO_LAUNCHER.setIcon(LogoHelper.getDrawable(SET_LOGO_LAUNCHER.getValue()));
setDrawable(SET_LOGO_LAUNCHER.getValue());
editor.putString(getString(R.string.SET_LOGO_LAUNCHER), SET_LOGO_LAUNCHER.getValue());
}
}
editor.apply();
}
}
private void hideAllIcons(Context context) {
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.Bubbles"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.Bubbles"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.Fediverse"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.Fediverse"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.Hero"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.Hero"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.Atom"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.Atom"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.BrainCrash"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.BrainCrash"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity.Mastalab"),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity.Mastalab"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
private void setIcon(Context context, String iconName) {
context.getPackageManager().setComponentEnabledSetting(
new ComponentName(context.getPackageName(), "app.fedilab.android.activities.MainActivity." + iconName),
new ComponentName(BuildConfig.APPLICATION_ID, "app.fedilab.android.activities.MainActivity." + iconName),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}

View file

@ -864,6 +864,40 @@
<item>sc</item>
</string-array>
<string-array name="SET_LIVE_TRANSLATE_ENTRIES" translatable="false">
<item>default</item>
<item>en</item>
<item>fr</item>
<item>de</item>
<item>it</item>
<item>ja</item>
<item>zh</item>
<item>ar</item>
<item>pt</item>
<item>es</item>
<item>sr</item>
<item>uk</item>
<item>ru</item>
</string-array>
<string-array name="SET_LIVE_TRANSLATE_VALUES" translatable="false">
<item>-----</item>
<item>English</item>
<item>Français</item>
<item>Deutsch</item>
<item>Italiano</item>
<item>日本語</item>
<item>繁體中文</item>
<item>العربية</item>
<item>Português</item>
<item>Español</item>
<item>Српски</item>
<item>Українська</item>
<item>Русский</item>
</string-array>
<string-array name="SET_TRANSLATE_VALUES" translatable="false">
<item>English</item>
<item>Français</item>
@ -955,6 +989,8 @@
<string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string>
<string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string>
<string name="SET_EXPAND_MEDIA" translatable="false">SET_EXPAND_MEDIA</string>
<string name="SET_LIVE_TRANSLATE" translatable="false">SET_LIVE_TRANSLATE</string>
<string name="SET_TRUNCATE_TOOTS_SIZE" translatable="false">SET_TRUNCATE_TOOTS_SIZE</string>
<string name="SET_ART_WITH_NSFW" translatable="false">SET_ART_WITH_NSFW</string>
<string name="SET_VIDEO_CACHE" translatable="false">SET_VIDEO_CACHE</string>
@ -1517,4 +1553,6 @@
<string name="action_unpin">Unpin message</string>
<string name="toast_unpin">The message is no longer pinned!</string>
<string name="toast_pin">The message has been pinned</string>
<string name="set_live_translate_title">Translate messages</string>
<string name="set_live_translate">Force translation to a specific language. Choose first value to reset to device settings</string>
</resources>

View file

@ -19,6 +19,16 @@
app:key="@string/SET_EXPAND_MEDIA"
app:singleLineTitle="false"
app:title="@string/expand_image" />
<ListPreference
android:defaultValue="default"
app:entries="@array/SET_LIVE_TRANSLATE_VALUES"
app:entryValues="@array/SET_LIVE_TRANSLATE_ENTRIES"
app:iconSpaceReserved="false"
app:key="@string/SET_LIVE_TRANSLATE"
app:summary="@string/set_live_translate"
app:title="@string/set_live_translate_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:defaultValue="true"
app:iconSpaceReserved="false"