From b0cdbfc486259ed16d60afd6585be261aa8e354c Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Sat, 11 Nov 2023 17:44:58 -0600 Subject: [PATCH] Reverted change meant for another PR --- .../frontend/AttachLinkOrFileDialog.java | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java index 4a0ffdb76f..9e1a50ef6e 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java +++ b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java @@ -259,15 +259,6 @@ private static void insertItem( } }; - // Pull dialog elements - final EditText nameEdit, pathEdit; - if (dialog != null) { - nameEdit = dialog.findViewById(R.id.ui__select_path_dialog__name); - pathEdit = dialog.findViewById(R.id.ui__select_path_dialog__url); - } else { - nameEdit = pathEdit = null; - } - final GsCallback.a1 insertFileLink = (file) -> { // If path is not under notebook, copy it to the res folder if (!GsFileUtils.isChild(_appSettings.getNotebookDirectory(), file)) { @@ -276,20 +267,13 @@ private static void insertItem( GsFileUtils.copyFile(file, local); file = local; } - - final String title; - if (nameEdit != null) { - title = nameEdit.getText().toString(); - } else { - title = GsFileUtils.getFilenameWithoutExtension(file); - } - + final String title = GsFileUtils.getFilenameWithoutExtension(file); final String path = GsFileUtils.relativePath(currentFile, file); insertLink.callback(title, path); }; final MarkorContextUtils shu = new MarkorContextUtils(activity); - final BroadcastReceiver receiver = shu.receiveResultFromLocalBroadcast( + final BroadcastReceiver br = shu.receiveResultFromLocalBroadcast( activity, (intent, _br) -> insertFileLink.callback(new File(intent.getStringExtra(MarkorContextUtils.EXTRA_FILEPATH))), true, @@ -298,8 +282,13 @@ private static void insertItem( "" + MarkorContextUtils.REQUEST_RECORD_AUDIO ); + final EditText nameEdit, pathEdit; if (dialog != null) { - dialog.setOnDismissListener(d -> LocalBroadcastManager.getInstance(activity).unregisterReceiver(receiver)); + nameEdit = dialog.findViewById(R.id.ui__select_path_dialog__name); + pathEdit = dialog.findViewById(R.id.ui__select_path_dialog__url); + dialog.setOnDismissListener(d -> LocalBroadcastManager.getInstance(activity).unregisterReceiver(br)); + } else { + nameEdit = pathEdit = null; } // Do each thing as necessary