mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 15:32:52 +00:00
Added option to disable shortcuts
This commit is contained in:
parent
99106d4ebe
commit
29e6fb7076
4 changed files with 49 additions and 4 deletions
|
@ -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));
|
||||
|
|
|
@ -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<ShortcutInfoCompat> 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<ShortcutInfoCompat> shortcuts = new ArrayList<>();
|
||||
if (!enabled)
|
||||
return shortcuts;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
List<String> emails = new ArrayList<>();
|
||||
List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
|
||||
try (Cursor cursor = db.contact().getFrequentlyContacted()) {
|
||||
int colEmail = cursor.getColumnIndex("email");
|
||||
int colName = cursor.getColumnIndex("name");
|
||||
|
|
|
@ -40,6 +40,30 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swShortcuts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:enabled="true"
|
||||
android:text="@string/title_advanced_shortcuts"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvShortcutsHint"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:text="@string/title_advanced_english_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swShortcuts" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swConversationActions"
|
||||
android:layout_width="0dp"
|
||||
|
@ -49,7 +73,7 @@
|
|||
android:text="@string/title_advanced_conversation_actions"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvShortcutsHint"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
|
|
@ -426,6 +426,7 @@
|
|||
<string name="title_advanced_aes_key_size" translatable="false">Max AES key size: %1$d</string>
|
||||
|
||||
<string name="title_advanced_external_search">Allow other apps to search in messages</string>
|
||||
<string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string>
|
||||
<string name="title_advanced_conversation_actions">Show conversation actions</string>
|
||||
<string name="title_advanced_fts">Build search index</string>
|
||||
<string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string>
|
||||
|
|
Loading…
Reference in a new issue