hide settings instead of disabling

This commit is contained in:
Helium314 2023-09-07 13:29:21 +02:00
parent cb2495f5f0
commit 098628b9ee
5 changed files with 30 additions and 17 deletions

View file

@ -20,7 +20,6 @@ import static org.dslul.openboard.inputmethod.latin.permissions.PermissionsManag
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -68,8 +67,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
super.onCreate(icicle); super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_correction); addPreferencesFromResource(R.xml.prefs_screen_correction);
final Context context = getActivity(); final PackageManager pm = requireContext().getPackageManager();
final PackageManager pm = context.getPackageManager();
final Preference editPersonalDictionary = final Preference editPersonalDictionary =
findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY); findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
@ -79,7 +77,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
if (ri == null) { if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary); overwriteUserDictionaryPreference(editPersonalDictionary);
} }
mLookupContactsPreference = (SwitchPreferenceCompat) findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY); mLookupContactsPreference = findPreference(AndroidSpellCheckerService.PREF_USE_CONTACTS_KEY);
refreshEnabledSettings(); refreshEnabledSettings();
} }
@ -91,7 +89,7 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
&& !PermissionsUtil.checkAllPermissionsGranted( && !PermissionsUtil.checkAllPermissionsGranted(
getActivity() /* context */, Manifest.permission.READ_CONTACTS) getActivity() /* context */, Manifest.permission.READ_CONTACTS)
) { ) {
get(getActivity() /* context */).requestPermissions(this /* PermissionsResultCallback */, get(requireContext()).requestPermissions(this /* PermissionsResultCallback */,
getActivity() /* activity */, Manifest.permission.READ_CONTACTS); getActivity() /* activity */, Manifest.permission.READ_CONTACTS);
} }
refreshEnabledSettings(); refreshEnabledSettings();
@ -113,9 +111,9 @@ public final class CorrectionSettingsFragment extends SubScreenFragment
} }
private void refreshEnabledSettings() { private void refreshEnabledSettings() {
setPreferenceEnabled(Settings.PREF_AUTO_CORRECTION_CONFIDENCE, setPreferenceVisible(Settings.PREF_AUTO_CORRECTION_CONFIDENCE,
Settings.readAutoCorrectEnabled(getSharedPreferences(), getResources())); Settings.readAutoCorrectEnabled(getSharedPreferences(), getResources()));
setPreferenceEnabled(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)); setPreferenceVisible(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, getSharedPreferences().getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true));
turnOffLookupContactsIfNoPermission(); turnOffLookupContactsIfNoPermission();
} }

View file

@ -16,6 +16,8 @@
package org.dslul.openboard.inputmethod.latin.settings; package org.dslul.openboard.inputmethod.latin.settings;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.R;
@ -34,5 +36,20 @@ public final class GestureSettingsFragment extends SubScreenFragment {
public void onCreate(final Bundle icicle) { public void onCreate(final Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_gesture); addPreferencesFromResource(R.xml.prefs_screen_gesture);
refreshSettingsEnablement();
}
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
refreshSettingsEnablement();
}
private void refreshSettingsEnablement() {
final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources();
setPreferenceVisible(Settings.PREF_GESTURE_PREVIEW_TRAIL,
Settings.readGestureInputEnabled(prefs, res));
setPreferenceVisible(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT,
Settings.readGestureInputEnabled(prefs, res));
} }
} }

View file

@ -86,11 +86,11 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
private void refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings() { private void refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings() {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources(); final Resources res = getResources();
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS, setPreferenceVisible(Settings.PREF_VIBRATION_DURATION_SETTINGS,
Settings.readVibrationEnabled(prefs, res)); Settings.readVibrationEnabled(prefs, res));
setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, setPreferenceVisible(Settings.PREF_KEYPRESS_SOUND_VOLUME,
Settings.readKeypressSoundEnabled(prefs, res)); Settings.readKeypressSoundEnabled(prefs, res));
setPreferenceEnabled(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, setPreferenceVisible(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME,
Settings.readClipboardHistoryEnabled(prefs)); Settings.readClipboardHistoryEnabled(prefs));
} }

View file

@ -42,11 +42,11 @@ public abstract class SubScreenFragment extends PreferenceFragmentCompat
implements OnSharedPreferenceChangeListener { implements OnSharedPreferenceChangeListener {
private OnSharedPreferenceChangeListener mSharedPreferenceChangeListener; private OnSharedPreferenceChangeListener mSharedPreferenceChangeListener;
static void setPreferenceEnabled(final String prefKey, final boolean enabled, static void setPreferenceVisible(final String prefKey, final boolean visible,
final PreferenceScreen screen) { final PreferenceScreen screen) {
final Preference preference = screen.findPreference(prefKey); final Preference preference = screen.findPreference(prefKey);
if (preference != null) { if (preference != null) {
preference.setEnabled(enabled); preference.setVisible(visible);
} }
} }
@ -76,8 +76,8 @@ public abstract class SubScreenFragment extends PreferenceFragmentCompat
listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]); listPreference.setSummary(entryIndex < 0 ? null : entries[entryIndex]);
} }
final void setPreferenceEnabled(final String prefKey, final boolean enabled) { final void setPreferenceVisible(final String prefKey, final boolean visible) {
setPreferenceEnabled(prefKey, enabled, getPreferenceScreen()); setPreferenceVisible(prefKey, visible, getPreferenceScreen());
} }
final void removePreference(final String prefKey) { final void removePreference(final String prefKey) {

View file

@ -26,14 +26,12 @@
android:persistent="true" /> android:persistent="true" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="pref_gesture_floating_preview_text" android:key="pref_gesture_floating_preview_text"
android:dependency="gesture_input"
android:title="@string/gesture_floating_preview_text" android:title="@string/gesture_floating_preview_text"
android:summary="@string/gesture_floating_preview_text_summary" android:summary="@string/gesture_floating_preview_text_summary"
android:defaultValue="true" android:defaultValue="true"
android:persistent="true" /> android:persistent="true" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="pref_gesture_preview_trail" android:key="pref_gesture_preview_trail"
android:dependency="gesture_input"
android:title="@string/gesture_preview_trail" android:title="@string/gesture_preview_trail"
android:defaultValue="true" android:defaultValue="true"
android:persistent="true" /> android:persistent="true" />