External answer improvement

This commit is contained in:
M66B 2021-08-01 18:45:47 +02:00
parent a344c2a270
commit f1fd135d51
5 changed files with 49 additions and 15 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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<TupleFtsStats>() {
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));

View File

@ -85,6 +85,17 @@
app:layout_constraintTop_toBottomOf="@id/swPowerMenu"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExternalAnswer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_external_answer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swShortcuts"
android:layout_width="0dp"
@ -94,7 +105,7 @@
android:text="@string/title_advanced_shortcuts"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
app:layout_constraintTop_toBottomOf="@id/swExternalAnswer"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

View File

@ -582,6 +582,7 @@
<string name="title_advanced_power_menu">Add actions to the Android power menu</string>
<string name="title_advanced_external_search">Allow other apps to search in messages</string>
<string name="title_advanced_external_answer" translatable="false">Provide reply templates to other apps</string>
<string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</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>