Skip to content

Commit

Permalink
Reworked how attachments are added
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Sep 10, 2023
1 parent d8ffc01 commit ff79bf2
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 487 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,10 @@
<package android:name="org.mozilla.klar" />
<package android:name="org.mozilla.focus" />

<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>

<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

// Edit / Preview switch
menu.findItem(R.id.action_edit).setVisible(isText && _isPreviewVisible);
menu.findItem(R.id.submenu_attach).setVisible(false);
menu.findItem(R.id.action_preview).setVisible(isText && !_isPreviewVisible);
menu.findItem(R.id.action_search).setVisible(isText && !_isPreviewVisible);
menu.findItem(R.id.action_search_view).setVisible(isText && _isPreviewVisible);
Expand Down Expand Up @@ -516,24 +515,6 @@ public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
_cu.draftEmail(getActivity(), "Debug Log " + getString(R.string.app_name_real), text, "[email protected]");
return true;
}

case R.id.action_attach_color: {
_format.getActions().showColorPickerDialog();
return true;
}
case R.id.action_attach_date: {
DatetimeFormatDialog.showDatetimeFormatDialog(activity, _hlEditor);
return true;
}
case R.id.action_attach_audio:
case R.id.action_attach_file:
case R.id.action_attach_image:
case R.id.action_attach_link: {
int actionId = (itemId == R.id.action_attach_audio ? 4 : (itemId == R.id.action_attach_image ? 2 : 3));
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(actionId, _document.getFormat(), activity, _hlEditor, _document.getFile());
return true;
}

case R.id.action_load_epub: {
MarkorFileBrowserFactory.showFileDialog(new GsFileBrowserOptions.SelectionListenerAdapter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ protected void onStop() {
restoreDefaultToolbar();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
_cu.extractResultFromActivityResult(this, requestCode, resultCode, data);
}

/**
* Restores the default toolbar. Used when changing the tab or moving to another activity
* while {@link GsFileBrowserFragment} action mode is active (e.g. when renaming a file)
Expand Down
40 changes: 13 additions & 27 deletions app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ protected void runIndentLines(final boolean deIndent) {
// Some actions common to multiple file types
// Can be called _explicitly_ by a derived class
protected final boolean runCommonAction(final @StringRes int action) {
final Editable text = _hlEditor.getText();
switch (action) {
case R.string.abid_common_unordered_list_char: {
runRegularPrefixAction(_appSettings.getUnorderedListCharacter() + " ", true);
Expand All @@ -563,35 +564,21 @@ protected final boolean runCommonAction(final @StringRes int action) {
case R.string.abid_common_time: {
DatetimeFormatDialog.showDatetimeFormatDialog(getActivity(), _hlEditor);
return true;
}
case R.string.abid_common_time_insert_timestamp: {

}
case R.string.abid_common_accordion: {
_hlEditor.insertOrReplaceTextOnCursor("<details markdown='1'><summary>" + rstr(R.string.expand_collapse) + "</summary>\n" + HighlightingEditor.PLACE_CURSOR_HERE_TOKEN + "\n\n</details>");
return true;
}
case R.string.abid_common_attach_something: {
MarkorDialogFactory.showAttachSomethingDialog(getActivity(), itemId -> {
switch (itemId) {
case R.id.action_attach_color: {
showColorPickerDialog();
break;
}
case R.id.action_attach_date: {
DatetimeFormatDialog.showDatetimeFormatDialog(getActivity(), _hlEditor);
break;
}
case R.id.action_attach_audio:
case R.id.action_attach_file:
case R.id.action_attach_image:
case R.id.action_attach_link: {
int actionId = (itemId == R.id.action_attach_audio ? 4 : (itemId == R.id.action_attach_image ? 2 : 3));
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(actionId, _document.getFormat(), getActivity(), _hlEditor, _document.getFile());
break;
}
}
});
case R.string.abid_common_insert_audio: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.AUDIO_ACTION, _document.getFormat(), getActivity(), text, _document.getFile());
return true;
}
case R.string.abid_common_insert_link: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.FILE_OR_LINK_ACTION, _document.getFormat(), getActivity(), text, _document.getFile());
return true;
}
case R.string.abid_common_insert_image: {
AttachLinkOrFileDialog.showInsertImageOrLinkDialog(AttachLinkOrFileDialog.IMAGE_ACTION, _document.getFormat(), getActivity(), text, _document.getFile());
return true;
}
case R.string.abid_common_ordered_list_renumber: {
Expand Down Expand Up @@ -619,7 +606,7 @@ protected final boolean runCommonAction(final @StringRes int action) {
}
case R.string.abid_common_open_link_browser: {
String url;
if ((url = GsTextUtils.tryExtractUrlAroundPos(_hlEditor.getText().toString(), _hlEditor.getSelectionStart())) != null) {
if ((url = GsTextUtils.tryExtractUrlAroundPos(text.toString(), _hlEditor.getSelectionStart())) != null) {
if (url.endsWith(")")) {
url = url.substring(0, url.length() - 1);
}
Expand All @@ -633,13 +620,12 @@ protected final boolean runCommonAction(final @StringRes int action) {
}
case R.string.abid_common_new_line_below: {
// Go to end of line, works with wrapped lines too
_hlEditor.setSelection(TextViewUtils.getLineEnd(_hlEditor.getText(), TextViewUtils.getSelection(_hlEditor)[1]));
_hlEditor.setSelection(TextViewUtils.getLineEnd(text, TextViewUtils.getSelection(_hlEditor)[1]));
_hlEditor.simulateKeyPress(KeyEvent.KEYCODE_ENTER);
return true;
}
case R.string.abid_common_delete_lines: {
final int[] sel = TextViewUtils.getLineSelection(_hlEditor);
final Editable text = _hlEditor.getText();
final boolean lastLine = sel[1] == text.length();
final boolean firstLine = sel[0] == 0;
text.delete(sel[0] - (lastLine && !firstLine ? 1 : 0), sel[1] + (lastLine ? 0 : 1));
Expand Down
Loading

0 comments on commit ff79bf2

Please sign in to comment.