diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 150bb40a27..f0e81c9374 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -53,6 +53,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase; public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { private SwitchCompat swExternalSearch; + private SwitchCompat swShortcuts; private SwitchCompat swConversationActions; private SwitchCompat swFts; private TextView tvFtsIndexed; @@ -79,7 +80,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private Group grpDebug; private final static String[] RESET_OPTIONS = new String[]{ - "conversation_actions", "fts", "english", "watchdog", "auto_optimize", "updates", "experiments", "crash_reports", "debug" + "shortcuts", "conversation_actions", "fts", "english", "watchdog", "auto_optimize", "updates", "experiments", "crash_reports", "debug" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -100,6 +101,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc // Get controls swExternalSearch = view.findViewById(R.id.swExternalSearch); + swShortcuts = view.findViewById(R.id.swShortcuts); swConversationActions = view.findViewById(R.id.swConversationActions); swFts = view.findViewById(R.id.swFts); tvFtsIndexed = view.findViewById(R.id.tvFtsIndexed); @@ -144,6 +146,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swShortcuts.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("shortcuts", checked).commit(); // apply won't work here + restart(); + } + }); + swConversationActions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -389,6 +399,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc int state = pm.getComponentEnabledSetting(new ComponentName(getContext(), ActivitySearch.class)); swExternalSearch.setChecked(state != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); + swShortcuts.setChecked(prefs.getBoolean("shortcuts", true)); swConversationActions.setChecked(prefs.getBoolean("conversation_actions", true)); swConversationActions.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ? View.VISIBLE : View.GONE); swFts.setChecked(prefs.getBoolean("fts", false)); diff --git a/app/src/main/java/eu/faircode/email/Shortcuts.java b/app/src/main/java/eu/faircode/email/Shortcuts.java index 7e0ce337f8..8130dd11dd 100644 --- a/app/src/main/java/eu/faircode/email/Shortcuts.java +++ b/app/src/main/java/eu/faircode/email/Shortcuts.java @@ -23,6 +23,7 @@ import android.Manifest; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ShortcutManager; import android.database.Cursor; import android.graphics.Bitmap; @@ -38,6 +39,7 @@ import androidx.core.content.pm.ShortcutInfoCompat; import androidx.core.content.pm.ShortcutManagerCompat; import androidx.core.graphics.drawable.IconCompat; import androidx.lifecycle.LifecycleOwner; +import androidx.preference.PreferenceManager; import java.io.InputStream; import java.util.ArrayList; @@ -57,15 +59,22 @@ class Shortcuts { @Override @TargetApi(Build.VERSION_CODES.N_MR1) protected List onExecute(Context context, Bundle args) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean enabled = prefs.getBoolean("shortcuts", true); + ShortcutManager sm = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); int app = sm.getMaxShortcutCountPerActivity(); int manifest = sm.getManifestShortcuts().size(); int count = Math.min(app - manifest, MAX_SHORTCUTS); - EntityLog.log(context, "Shortcuts count=" + count + " app=" + app + " manifest=" + manifest); + EntityLog.log(context, "Shortcuts count=" + count + + " app=" + app + " manifest=" + manifest + " enabled=" + enabled); + + List shortcuts = new ArrayList<>(); + if (!enabled) + return shortcuts; DB db = DB.getInstance(context); List emails = new ArrayList<>(); - List shortcuts = new ArrayList<>(); try (Cursor cursor = db.contact().getFrequentlyContacted()) { int colEmail = cursor.getColumnIndex("email"); int colName = cursor.getColumnIndex("name"); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index f5f82af8eb..80d59a5970 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -40,6 +40,30 @@ app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral" app:switchPadding="12dp" /> + + + + Max AES key size: %1$d Allow other apps to search in messages + Show frequently used contacts in Android share menu Show conversation actions Build search index %1$d / %2$d messages indexed (%3$s)