From f1fd135d51de80401bceec60781d3340ecfd177d Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 1 Aug 2021 18:45:47 +0200 Subject: [PATCH] External answer improvement --- .../eu/faircode/email/ActivityAnswer.java | 27 ++++++++++++------- .../eu/faircode/email/FragmentAnswer.java | 8 +++--- .../faircode/email/FragmentOptionsMisc.java | 15 +++++++++-- .../main/res/layout/fragment_options_misc.xml | 13 ++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityAnswer.java b/app/src/main/java/eu/faircode/email/ActivityAnswer.java index 4f52cbbdd4..318516a9dc 100644 --- a/app/src/main/java/eu/faircode/email/ActivityAnswer.java +++ b/app/src/main/java/eu/faircode/email/ActivityAnswer.java @@ -47,7 +47,16 @@ public class ActivityAnswer extends ActivityBase { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getSupportActionBar().setSubtitle(getString(R.string.app_answer)); + Intent intent = getIntent(); + if (intent == null) { + finish(); + return; + } + + final CharSequence query = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT); + final boolean readonly = intent.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false); + + getSupportActionBar().setSubtitle(query == null ? null : query.toString()); View view = LayoutInflater.from(this).inflate(R.layout.activity_answer, null); setContentView(view); @@ -81,14 +90,10 @@ public class ActivityAnswer extends ActivityBase { cbm.setPrimaryClip(ClipData.newHtmlText(getString(R.string.app_name), text, html)); ToastEx.makeText(context, R.string.title_clipboard_copied, Toast.LENGTH_LONG).show(); - Intent intent = getIntent(); - if (intent != null) { - boolean readonly = intent.getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false); - if (!readonly) { - Intent result = new Intent(); - result.putExtra(Intent.EXTRA_PROCESS_TEXT, text); - setResult(RESULT_OK, result); - } + if (!readonly) { + Intent result = new Intent(); + result.putExtra(Intent.EXTRA_PROCESS_TEXT, text); + setResult(RESULT_OK, result); } finish(); @@ -127,4 +132,8 @@ public class ActivityAnswer extends ActivityBase { } }.execute(this, new Bundle(), "answers"); } + + static boolean canAnswer(Context context) { + return BuildConfig.DEBUG; + } } diff --git a/app/src/main/java/eu/faircode/email/FragmentAnswer.java b/app/src/main/java/eu/faircode/email/FragmentAnswer.java index b2f1cebe00..30cba932d0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAnswer.java +++ b/app/src/main/java/eu/faircode/email/FragmentAnswer.java @@ -188,6 +188,8 @@ public class FragmentAnswer extends FragmentBase { @Override protected void onExecuted(Bundle args, EntityAnswer answer) { + final Context context = getContext(); + if (copy > 0 && answer != null) { answer.applied = 0; answer.last_applied = null; @@ -215,14 +217,14 @@ public class FragmentAnswer extends FragmentBase { public Drawable getDrawable(String source) { if (source != null && source.startsWith("cid:")) source = null; - return ImageHelper.decodeImage(getContext(), -1, source, true, 0, 1.0f, etText); + return ImageHelper.decodeImage(context, -1, source, true, 0, 1.0f, etText); } - }, null, getContext())); + }, null, context)); } bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE); - if (BuildConfig.DEBUG) + if (ActivityAnswer.canAnswer(context)) cbExternal.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE); bottom_navigation.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 97684082c2..9321ccd5fd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -90,6 +90,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swPowerMenu; private SwitchCompat swExternalSearch; + private SwitchCompat swExternalAnswer; private SwitchCompat swShortcuts; private SwitchCompat swFts; private SwitchCompat swClassification; @@ -201,6 +202,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swPowerMenu = view.findViewById(R.id.swPowerMenu); swExternalSearch = view.findViewById(R.id.swExternalSearch); + swExternalAnswer = view.findViewById(R.id.swExternalAnswer); swShortcuts = view.findViewById(R.id.swShortcuts); swFts = view.findViewById(R.id.swFts); swClassification = view.findViewById(R.id.swClassification); @@ -274,8 +276,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { Helper.enableComponent(getContext(), ActivitySearch.class, checked); - if (BuildConfig.DEBUG) - Helper.enableComponent(getContext(), ActivityAnswer.class, checked); + } + }); + + swExternalAnswer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + Helper.enableComponent(getContext(), ActivityAnswer.class, checked); } }); @@ -838,6 +845,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc tvFtsIndexed.setText(null); + swExternalAnswer.setVisibility( + ActivityAnswer.canAnswer(getContext()) ? View.VISIBLE : View.GONE); + DB db = DB.getInstance(getContext()); db.message().liveFts().observe(getViewLifecycleOwner(), new Observer() { private TupleFtsStats last = null; @@ -981,6 +991,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) swPowerMenu.setChecked(Helper.isComponentEnabled(getContext(), ServicePowerControl.class)); swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class)); + swExternalAnswer.setChecked(Helper.isComponentEnabled(getContext(), ActivityAnswer.class)); swShortcuts.setChecked(prefs.getBoolean("shortcuts", true)); swFts.setChecked(prefs.getBoolean("fts", false)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index fac0205a4e..c54f6d291a 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -85,6 +85,17 @@ app:layout_constraintTop_toBottomOf="@id/swPowerMenu" app:switchPadding="12dp" /> + + Add actions to the Android power menu Allow other apps to search in messages + Provide reply templates to other apps Show frequently used contacts in Android share menu Build search index %1$d / %2$d messages indexed (%3$s)