Added draft message printing

This commit is contained in:
M66B
2023-03-31 17:50:24 +02:00
parent c7fb523222
commit 9c29824738
8 changed files with 398 additions and 280 deletions

View File

@@ -325,10 +325,11 @@ public class FragmentCompose extends FragmentBase {
private static final int REQUEST_OPENPGP = 10;
private static final int REQUEST_CONTACT_GROUP = 11;
private static final int REQUEST_SELECT_IDENTITY = 12;
private static final int REQUEST_LINK = 13;
private static final int REQUEST_DISCARD = 14;
private static final int REQUEST_SEND = 15;
private static final int REQUEST_REMOVE_ATTACHMENTS = 16;
private static final int REQUEST_PRINT = 13;
private static final int REQUEST_LINK = 14;
private static final int REQUEST_DISCARD = 15;
private static final int REQUEST_SEND = 16;
private static final int REQUEST_REMOVE_ATTACHMENTS = 17;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -1804,6 +1805,7 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_answer_insert).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_answer_create).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_clear).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_print).setEnabled(state == State.LOADED);
SpannableStringBuilder ssbZoom = new SpannableStringBuilder(getString(R.string.title_zoom));
ssbZoom.append(' ');
@@ -1962,6 +1964,9 @@ public class FragmentCompose extends FragmentBase {
} else if (itemId == R.id.menu_clear) {
StyleHelper.apply(R.id.menu_clear, getViewLifecycleOwner(), null, etBody);
return true;
} else if (itemId == R.id.menu_print) {
onMenuPrint();
return true;
} else if (itemId == R.id.menu_legend) {
onMenuLegend();
return true;
@@ -2381,6 +2386,66 @@ public class FragmentCompose extends FragmentBase {
fragment.show(getParentFragmentManager(), "select:identity");
}
private void onMenuPrint() {
Bundle extras = new Bundle();
extras.putBoolean("silent", true);
onAction(R.id.action_save, extras, "paragraph");
CharSequence selected = null;
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (start < 0)
start = 0;
if (end < 0)
end = 0;
if (start != end) {
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
selected = etBody.getText().subSequence(start, end);
}
Bundle args = new Bundle();
args.putLong("id", working);
args.putBoolean("headers", false);
args.putCharSequence("selected", selected);
args.putBoolean("draft", true);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
// Do nothing: serialize
return null;
}
@Override
protected void onExecuted(Bundle args, Void dummy) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (prefs.getBoolean("print_html_confirmed", false)) {
Intent data = new Intent();
data.putExtra("args", args);
onActivityResult(REQUEST_PRINT, RESULT_OK, data);
return;
}
FragmentDialogPrint ask = new FragmentDialogPrint();
ask.setArguments(args);
ask.setTargetFragment(FragmentCompose.this, REQUEST_PRINT);
ask.show(getParentFragmentManager(), "compose:print");
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.serial().execute(this, args, "compose:print");
}
private void onOpenAi() {
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
@@ -3028,6 +3093,10 @@ public class FragmentCompose extends FragmentBase {
if (resultCode == RESULT_OK && data != null)
onSelectIdentity(data.getBundleExtra("args"));
break;
case REQUEST_PRINT:
if (resultCode == RESULT_OK && data != null)
onPrint(data.getBundleExtra("args"));
break;
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
@@ -4527,6 +4596,10 @@ public class FragmentCompose extends FragmentBase {
}.serial().execute(this, args, "select:identity");
}
private void onPrint(Bundle args) {
FragmentDialogPrint.print((ActivityBase) getActivity(), getParentFragmentManager(), args);
}
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
boolean image = args.getBoolean("image");