Added option for DeepL integration

This commit is contained in:
M66B 2021-06-28 10:10:44 +02:00
parent 2333cca3a7
commit 13f809e3c8
5 changed files with 64 additions and 7 deletions

View File

@ -479,6 +479,10 @@ public class ApplicationEx extends Application
String key = prefs.getString("deepl", null);
editor.putString("deepl_key", key).remove("deepl");
}
} else if (version < 1630) {
boolean experiments = prefs.getBoolean("experiments", false);
if (experiments)
editor.putBoolean("deepl_enabled", true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)

View File

@ -73,8 +73,8 @@ public class DeepL {
public static boolean isAvailable(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean experiments = prefs.getBoolean("experiments", false);
return (experiments && !BuildConfig.PLAY_STORE_RELEASE);
boolean deepl_enabled = prefs.getBoolean("deepl_enabled", false);
return (deepl_enabled && !BuildConfig.PLAY_STORE_RELEASE);
}
public static boolean canTranslate(Context context) {

View File

@ -95,6 +95,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvFtsPro;
private Spinner spLanguage;
private ImageButton ibResetLanguage;
private SwitchCompat swDeepL;
private ImageButton ibDeepL;
private SwitchCompat swWatchdog;
private SwitchCompat swUpdates;
private SwitchCompat swCheckWeekly;
@ -132,6 +134,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Button btnCiphers;
private Button btnFiles;
private Group grpDeepL;
private Group grpUpdates;
private CardView cardDebug;
@ -142,7 +145,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{
"shortcuts", "fts",
"classification", "class_min_probability", "class_min_difference",
"language", "watchdog", "updates", "weekly",
"language", "deepl_enabled", "watchdog", "updates", "weekly",
"experiments", "wal", "query_threads", "crash_reports", "cleanup_attachments",
"protocol", "debug", "log_level",
"use_modseq", "perform_expunge",
@ -203,6 +206,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvFtsPro = view.findViewById(R.id.tvFtsPro);
spLanguage = view.findViewById(R.id.spLanguage);
ibResetLanguage = view.findViewById(R.id.ibResetLanguage);
swDeepL = view.findViewById(R.id.swDeepL);
ibDeepL = view.findViewById(R.id.ibDeepL);
swWatchdog = view.findViewById(R.id.swWatchdog);
swUpdates = view.findViewById(R.id.swUpdates);
swCheckWeekly = view.findViewById(R.id.swWeekly);
@ -240,6 +245,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
btnCiphers = view.findViewById(R.id.btnCiphers);
btnFiles = view.findViewById(R.id.btnFiles);
grpDeepL = view.findViewById(R.id.grpDeepL);
grpUpdates = view.findViewById(R.id.grpUpdates);
cardDebug = view.findViewById(R.id.cardDebug);
@ -415,6 +421,20 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swDeepL.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("deepl_enabled", checked).apply();
}
});
ibDeepL.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 167, true);
}
});
swWatchdog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -825,6 +845,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
grpDeepL.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE);
grpUpdates.setVisibility(!BuildConfig.DEBUG &&
(Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext()))
? View.GONE : View.VISIBLE);
setLastCleanup(prefs.getLong("last_cleanup", -1));
swExactAlarms.setEnabled(AlarmManagerCompatEx.canScheduleExactAlarms(getContext()));
@ -977,13 +1003,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
if (selected >= 0)
spLanguage.setSelection(selected);
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));
swCheckWeekly.setEnabled(swUpdates.isChecked());
grpUpdates.setVisibility(!BuildConfig.DEBUG &&
(Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext()))
? View.GONE : View.VISIBLE);
swExperiments.setChecked(prefs.getBoolean("experiments", false));
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
tvUuid.setText(prefs.getString("uuid", null));

View File

@ -284,6 +284,28 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spLanguage" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDeepL"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_deepl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageHint"
app:switchPadding="12dp" />
<ImageButton
android:id="@+id/ibDeepL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/title_info"
android:tooltipText="@string/title_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDeepL"
app:srcCompat="@drawable/twotone_info_24" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWatchdog"
android:layout_width="0dp"
@ -293,7 +315,7 @@
android:text="@string/title_advanced_watchdog"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLanguageHint"
app:layout_constraintTop_toBottomOf="@id/ibDeepL"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
@ -513,6 +535,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDebug" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpDeepL"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="swDeepL,ibDeepL" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpUpdates"
android:layout_width="0dp"

View File

@ -556,6 +556,7 @@
<string name="title_advanced_class_min_difference">Minimum class difference: %1$s %%</string>
<string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string>
<string name="title_advanced_deepl">DeepL integration</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
<string name="title_advanced_updates">Check for GitHub updates</string>
<string name="title_advanced_check_weekly">Check weekly instead of daily</string>