Skip to content

Commit

Permalink
Fixes for several bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Oct 13, 2023
1 parent 426b92d commit 03ad03c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.gsantner.markor.frontend.textview.TextViewUtils;
import net.gsantner.markor.model.AppSettings;
import net.gsantner.markor.util.MarkorContextUtils;
import net.gsantner.opoc.format.GsTextUtils;
import net.gsantner.opoc.frontend.GsAudioRecordOmDialog;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
import net.gsantner.opoc.util.GsFileUtils;
Expand Down Expand Up @@ -120,7 +121,7 @@ public static void showInsertImageOrLinkDialog(
final AlertDialog dialog = builder.setView(view).create();

// Helper func
final GsCallback.a1<InsertType> _insertItem = (type) -> insertItem(type, textFormatId, activity, edit, currentFile, dialog);
final GsCallback.a1<InsertType> _insertItem = (type) -> insertItem(type, textFormatId, activity, edit, currentFile, sel, dialog);

// Setup all the various choices
final InsertType browseType, okType;
Expand Down Expand Up @@ -216,14 +217,20 @@ private static void insertItem(
final Activity activity,
final Editable text,
final File currentFile,
@Nullable final int[] region,
@Nullable AlertDialog dialog
) {
final int[] sel = TextViewUtils.getSelection(text);
final int[] sel;
if (region != null && region.length > 1 && region[0] >= 0 && region[1] >= 0) {
sel = region;
} else {
sel = TextViewUtils.getSelection(text);
}

final AppSettings _appSettings = ApplicationObject.settings();
final File attachmentDir = _appSettings.getAttachmentFolder(currentFile);

// Source, dest to be written when the user hits accept
// Title, path to be written when the user hits accept
final GsCallback.a2<String, String> insertLink = (title, path) -> {
if (TextViewUtils.isNullOrEmpty(path)) {
return;
Expand All @@ -244,7 +251,7 @@ private static void insertItem(
newText = newText.replaceFirst("\\|]]$", "]]");
}

if (!text.subSequence(sel[0], sel[1]).equals(newText)) {
if (!newText.equals(text.subSequence(sel[0], sel[1]).toString())) {
text.replace(sel[0], sel[1], newText);
}

Expand Down Expand Up @@ -297,13 +304,17 @@ private static void insertItem(
}
case IMAGE_EDIT: {
if (pathEdit != null) {
String filepath = pathEdit.getText().toString().replace("%20", " ");
if (!filepath.startsWith("/")) {
filepath = new File(currentFile.getParent(), filepath).getAbsolutePath();
final String path = pathEdit.getText().toString().replace("%20", " ");

final File abs = new File(path).getAbsoluteFile();
if (abs.isFile()) {
shu.requestPictureEdit(activity, abs);
break;
}
File file = new File(filepath);
if (file.exists() && file.isFile()) {
shu.requestPictureEdit(activity, file);

final File rel = new File(currentFile.getParentFile(), path).getAbsoluteFile();
if (rel.isFile()) {
shu.requestPictureEdit(activity, rel);
}
}
break;
Expand Down Expand Up @@ -355,7 +366,7 @@ public static void insertCameraPhoto(
final Editable text,
final File currentFile
) {
insertItem(InsertType.IMAGE_CAMERA, textFormatId, activity, text, currentFile, null);
insertItem(InsertType.IMAGE_CAMERA, textFormatId, activity, text, currentFile, null, null);
}

public static void insertGalleryPhoto(
Expand All @@ -364,7 +375,7 @@ public static void insertGalleryPhoto(
final Editable text,
final File currentFile
) {
insertItem(InsertType.IMAGE_GALLERY, textFormatId, activity, text, currentFile, null);
insertItem(InsertType.IMAGE_GALLERY, textFormatId, activity, text, currentFile, null, null);
}

public static void insertAudioRecording(
Expand All @@ -373,6 +384,6 @@ public static void insertAudioRecording(
final Editable text,
final File currentFile
) {
insertItem(InsertType.AUDIO_RECORDING, textFormatId, activity, text, currentFile, null);
insertItem(InsertType.AUDIO_RECORDING, textFormatId, activity, text, currentFile, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onViewCreated(View root, @Nullable Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
Context context = getContext();
final Context context = getContext();

_recyclerList = root.findViewById(R.id.ui__filesystem_dialog__list);
_dialogTitle = root.findViewById(R.id.ui__filesystem_dialog__title_text);
Expand Down Expand Up @@ -197,7 +197,7 @@ public void onClicked(View view) {
break;
}
case R.id.ui__filesystem_dialog__button_cancel: {
onFsViewerNothingSelected(_dopt.requestId);
onFsViewerCancel(_dopt.requestId);
break;
}
case R.id.ui__filesystem_dialog__new_dir: {
Expand Down Expand Up @@ -258,9 +258,9 @@ public void onFsViewerMultiSelected(String request, File... files) {
}

@Override
public void onFsViewerNothingSelected(String request) {
public void onFsViewerCancel(String request) {
if (_callback != null) {
_callback.onFsViewerNothingSelected(_dopt.requestId);
_callback.onFsViewerCancel(_dopt.requestId);
}
dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void onClicked(View view) {
break;
}
case R.id.ui__filesystem_dialog__button_cancel: {
onFsViewerNothingSelected(_dopt.requestId);
onFsViewerCancel(_dopt.requestId);
break;
}

Expand Down Expand Up @@ -189,9 +189,9 @@ public void onFsViewerMultiSelected(String request, File... files) {
}

@Override
public void onFsViewerNothingSelected(String request) {
public void onFsViewerCancel(String request) {
if (_callback != null) {
_callback.onFsViewerNothingSelected(_dopt.requestId);
_callback.onFsViewerCancel(_dopt.requestId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface SelectionListener {

void onFsViewerMultiSelected(final String request, final File... files);

void onFsViewerNothingSelected(final String request);
void onFsViewerCancel(final String request);

void onFsViewerConfig(final Options dopt);

Expand Down Expand Up @@ -130,7 +130,7 @@ public void onFsViewerMultiSelected(String request, File... files) {
}

@Override
public void onFsViewerNothingSelected(String request) {
public void onFsViewerCancel(String request) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ protected void onStop() {

// only runs for a valid id
private void showWidgetSelectFolderDialog() {
final FragmentManager fragManager = getSupportFragmentManager();
MarkorFileBrowserFactory.showFolderDialog(new GsFileBrowserOptions.SelectionListenerAdapter() {
@Override
public void onFsViewerSelected(String request, File file, final Integer lineNumber) {
Expand All @@ -67,7 +66,13 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.titleText = R.string.select_folder;
dopt.rootFolder = ApplicationObject.settings().getNotebookDirectory();
}
}, fragManager, this);

@Override
public void onFsViewerCancel(final String request) {
finish();
}

}, getSupportFragmentManager(), this);
}

public static File getWidgetDirectory(final Context context, int id) {
Expand Down

0 comments on commit 03ad03c

Please sign in to comment.