show warning that disabling persinalized suggestions will clear learned words

This commit is contained in:
Helium314 2023-11-20 10:49:15 +01:00
parent 92815c6af6
commit a31b408351
2 changed files with 13 additions and 6 deletions

View file

@ -14,10 +14,11 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import androidx.preference.TwoStatePreference;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager;
@ -73,13 +74,17 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
if (TextUtils.equals(key, AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY)
if (AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY.equals(key)
&& prefs.getBoolean(key, false)
&& !PermissionsUtil.checkAllPermissionsGranted(
getActivity() /* context */, Manifest.permission.READ_CONTACTS)
&& !PermissionsUtil.checkAllPermissionsGranted(getActivity(), Manifest.permission.READ_CONTACTS)
) {
get(requireContext()).requestPermissions(this /* PermissionsResultCallback */,
getActivity() /* activity */, Manifest.permission.READ_CONTACTS);
get(requireContext()).requestPermissions(this, getActivity(), Manifest.permission.READ_CONTACTS);
} else if (Settings.PREF_KEY_USE_PERSONALIZED_DICTS.equals(key) && !prefs.getBoolean(key, true)) {
new AlertDialog.Builder(requireContext())
.setMessage(R.string.disable_personalized_dicts_message)
.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> ((TwoStatePreference) findPreference(key)).setChecked(true))
.setPositiveButton(android.R.string.ok, null)
.show();
}
refreshEnabledSettings();
}

View file

@ -83,6 +83,8 @@
<string name="use_contacts_dict_summary">Use names from Contacts for suggestions and corrections</string>
<!-- Option name for enabling the use by the keyboards of sent/received messages, e-mail and typing history to improve suggestion accuracy [CHAR LIMIT=25] -->
<string name="use_personalized_dicts">Personalized suggestions</string>
<!-- Dialog message informing that dictionaries will be deleted on changing the setting -->
<string name="disable_personalized_dicts_message">Warning: Disabling this setting will clear learned data</string>
<!-- Option name for adding learned words to personal dictionary -->
<string name="add_to_personal_dictionary">Add words to personal dictionary</string>
<!-- Description for option to add learned words to system-wide user dictionary -->