Instance fixes when not available

This commit is contained in:
tom79 2019-11-24 16:07:36 +01:00
parent 8975b09175
commit ce05666038
6 changed files with 36 additions and 9 deletions

View File

@ -88,7 +88,7 @@ dependencies {
implementation "com.github.chrisbanes:PhotoView:$photoViewLibraryVersion"
implementation 'com.r0adkll:slidableactivity:2.1.0'
implementation 'com.github.stom79:country-picker-android:1.2.0'
implementation 'com.github.stom79:mytransl:1.5'
implementation 'com.github.stom79:mytransl:2.0'
implementation 'com.github.stom79:SparkButton:1.0.13'
implementation "com.koushikdutta.async:androidasync:2.+"
implementation 'com.vanniktech:emoji-one:0.6.0'

View File

@ -1065,6 +1065,8 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA
et = MyTransL.translatorEngine.YANDEX;
} else if (trans == Helper.TRANS_DEEPL) {
et = MyTransL.translatorEngine.DEEPL;
}else if (trans == Helper.TRANS_SYSTRAN) {
et = MyTransL.translatorEngine.SYSTRAN;
}
final MyTransL myTransL = MyTransL.getInstance(et);
myTransL.setObfuscation(true);
@ -1074,6 +1076,9 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA
} else if (trans == Helper.TRANS_DEEPL) {
api_key = sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, "");
myTransL.setDeeplAPIKey(api_key);
} else if (trans == Helper.TRANS_SYSTRAN) {
api_key = sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, "");
myTransL.setSystranAPIKey(api_key);
}

View File

@ -4073,13 +4073,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int trans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
MyTransL.translatorEngine et = MyTransL.translatorEngine.YANDEX;
String api_key = null;
String api_key;
if (trans == Helper.TRANS_YANDEX) {
et = MyTransL.translatorEngine.YANDEX;
} else if (trans == Helper.TRANS_DEEPL) {
et = MyTransL.translatorEngine.DEEPL;
} else if (trans == Helper.TRANS_SYSTRAN) {
et = MyTransL.translatorEngine.SYSTRAN;
}
final MyTransL myTransL = MyTransL.getInstance(et);
myTransL.setObfuscation(true);
@ -4089,6 +4091,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
} else if (trans == Helper.TRANS_DEEPL) {
api_key = sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, "");
myTransL.setDeeplAPIKey(api_key);
} else if (trans == Helper.TRANS_SYSTRAN) {
api_key = sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, "");
myTransL.setSystranAPIKey(api_key);
}
@ -4097,7 +4102,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
statusToTranslate = Html.fromHtml(status.getReblog() != null ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
statusToTranslate = Html.fromHtml(status.getReblog() != null ? status.getReblog().getContent() : status.getContent()).toString();
//TODO: removes the replaceAll once fixed with the lib
myTransL.translate(statusToTranslate, myTransL.getLocale(), new Results() {

View File

@ -716,6 +716,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
store = Helper.SET_YANDEX_API_KEY;
else if (translatore == Helper.TRANS_DEEPL)
store = Helper.SET_DEEPL_API_KEY;
else if (translatore == Helper.TRANS_SYSTRAN)
store = Helper.SET_SYSTRAN_API_KEY;
if (store != null)
if (s != null && s.length() > 0)
editor.putString(store, s.toString().trim());
@ -1833,8 +1835,13 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
your_api_key.setVisibility(View.VISIBLE);
your_api_key.setText(sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, ""));
break;
case Helper.TRANS_NONE:
case Helper.TRANS_SYSTRAN:
positionSpinnerTrans = 2;
your_api_key.setVisibility(View.VISIBLE);
your_api_key.setText(sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, ""));
break;
case Helper.TRANS_NONE:
positionSpinnerTrans = 3;
your_api_key.setVisibility(View.GONE);
break;
default:
@ -1853,17 +1860,25 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
your_api_key.setVisibility(View.VISIBLE);
editor.putInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
editor.apply();
if (sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, null) != null)
your_api_key.setText(sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, ""));
if (sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, null) != null)
your_api_key.setText(sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, null));
break;
case 1:
your_api_key.setVisibility(View.VISIBLE);
editor.putInt(Helper.SET_TRANSLATOR, Helper.TRANS_DEEPL);
editor.apply();
if (sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, null) != null)
your_api_key.setText(sharedpreferences.getString(Helper.SET_YANDEX_API_KEY, null));
if (sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, null) != null)
your_api_key.setText(sharedpreferences.getString(Helper.SET_DEEPL_API_KEY, ""));
break;
case 2:
your_api_key.setVisibility(View.VISIBLE);
editor.putInt(Helper.SET_TRANSLATOR, Helper.TRANS_SYSTRAN);
editor.apply();
if (sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, null) != null)
your_api_key.setText(sharedpreferences.getString(Helper.SET_SYSTRAN_API_KEY, ""));
break;
case 3:
your_api_key.setVisibility(View.GONE);
set_trans_forced.isChecked();
editor.putBoolean(Helper.SET_TRANS_FORCED, false);

View File

@ -416,7 +416,8 @@ public class Helper {
public static final int TRANS_YANDEX = 0;
public static final int TRANS_DEEPL = 1;
public static final int TRANS_NONE = 2;
public static final int TRANS_NONE = 3;
public static final int TRANS_SYSTRAN = 2;
public static final int ACTION_SILENT = 0;
public static final int ACTION_ACTIVE = 1;
@ -515,6 +516,7 @@ public class Helper {
public static final String USER_AGENT = System.getProperty("http.agent");
public static final String SET_YANDEX_API_KEY = "set_yandex_api_key";
public static final String SET_DEEPL_API_KEY = "set_deepl_api_key";
public static final String SET_SYSTRAN_API_KEY = "set_systran_api_key";
public static final String VIDEO_ID = "video_id_update";
public static final Pattern urlPattern = Pattern.compile(
"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",

View File

@ -337,6 +337,7 @@
<string-array name="settings_translation">
<item>Yandex</item>
<item>DeepL</item>
<item>Systran</item>
<item>No</item>
</string-array>