diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java index 14a49c1457..5af3b7650b 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentShareIntoFragment.java @@ -54,12 +54,12 @@ public class DocumentShareIntoFragment extends MarkorBaseFragment { public static final String TEXT_TOKEN = "{{text}}"; public static DocumentShareIntoFragment newInstance(Intent intent) { - DocumentShareIntoFragment f = new DocumentShareIntoFragment(); - Bundle args = new Bundle(); + final DocumentShareIntoFragment f = new DocumentShareIntoFragment(); + final Bundle args = new Bundle(); final String sharedText = formatLink(intent.getStringExtra(Intent.EXTRA_SUBJECT), intent.getStringExtra(Intent.EXTRA_TEXT)); - Object intentFile = intent.getSerializableExtra(Document.EXTRA_PATH); + final Object intentFile = intent.getSerializableExtra(Document.EXTRA_PATH); if (intentFile instanceof File && ((File) intentFile).isDirectory()) { f.workingDir = (File) intentFile; } @@ -245,36 +245,31 @@ private String formatShare(final String shared) { } private void showAppendDialog(int keyId) { + final File startFolder; + switch (keyId) { + case R.string.pref_key__favourite_files: { + startFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_FAVOURITE; + break; + } + case R.string.pref_key__popular_documents: { + startFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_POPULAR; + break; + } + case R.string.pref_key__recent_documents: { + startFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_RECENTS; + break; + } + default: { + startFolder = _appSettings.getNotebookDirectory(); + break; + } + } MarkorFileBrowserFactory.showFileDialog(new GsFileBrowserOptions.SelectionListenerAdapter() { @Override public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { + dopt.rootFolder = startFolder; dopt.newDirButtonEnable = false; - switch (keyId) { - case R.string.pref_key__favourite_files: { - dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_FAVOURITE; - break; - } - case R.string.pref_key__popular_documents: { - dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_POPULAR; - break; - } - case R.string.pref_key__recent_documents: { - dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_RECENTS; - break; - } - default: { - dopt.rootFolder = _appSettings.getNotebookDirectory(); - dopt.newDirButtonEnable = true; - dopt.createFileCallback = (dir, callback) -> NewFileDialog.newInstance(dir, false, (ok, f) -> { - if (ok && f.isFile()) { - appendToExistingDocumentAndClose(f, true); - } - } - ).show(getActivity().getSupportFragmentManager(), NewFileDialog.FRAGMENT_TAG); - break; - } - } } @Override @@ -286,23 +281,29 @@ public void onFsViewerSelected(String request, File file, final Integer lineNumb } - private void createNewDocument() { - MarkorFileBrowserFactory.showFolderDialog(new GsFileBrowserOptions.SelectionListenerAdapter() { + private void createSelectNewDocument() { + MarkorFileBrowserFactory.showFileDialog(new GsFileBrowserOptions.SelectionListenerAdapter() { @Override public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { - dopt.rootFolder = (workingDir == null) ? _appSettings.getNotebookDirectory() : workingDir; + dopt.rootFolder = _appSettings.getNotebookDirectory(); + dopt.startFolder = workingDir; + dopt.okButtonText = R.string.create_new_document; + dopt.okButtonEnable = true; } @Override - public void onFsViewerSelected(String request, File dir, final Integer lineNumber) { - NewFileDialog dialog = NewFileDialog.newInstance(dir, false, (ok, f) -> { - if (ok && f.isFile()) { - appendToExistingDocumentAndClose(f, true); - } - }); - dialog.show(getActivity().getSupportFragmentManager(), NewFileDialog.FRAGMENT_TAG); + public void onFsViewerSelected(final String request, final File sel, final Integer lineNumber) { + if (sel.isDirectory()) { + NewFileDialog.newInstance(sel, false, (ok, f) -> { + if (ok && f.isFile()) { + appendToExistingDocumentAndClose(f, true); + } + }).show(getActivity().getSupportFragmentManager(), NewFileDialog.FRAGMENT_TAG); + } else { + appendToExistingDocumentAndClose(sel, true); + } } - }, getParentFragmentManager(), getActivity()); + }, getParentFragmentManager(), getActivity(), MarkorFileBrowserFactory.IsMimeText); } private void showInDocumentActivity(final Document document) { @@ -327,7 +328,10 @@ public Boolean onPreferenceClicked(Preference preference, String key, int keyId) close = true; break; } - case R.string.pref_key__select_create_document: + case R.string.pref_key__select_create_document: { + createSelectNewDocument(); + return true; + } case R.string.pref_key__favourite_files: case R.string.pref_key__popular_documents: case R.string.pref_key__recent_documents: { diff --git a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java index 4c2c80e330..f92f2de366 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java +++ b/app/src/main/java/net/gsantner/markor/frontend/filebrowser/MarkorFileBrowserFactory.java @@ -29,7 +29,11 @@ public class MarkorFileBrowserFactory { public static GsCallback.b2 IsMimeAudio = (context, file) -> file != null && GsContextUtils.instance.getMimeType(context, file).startsWith("audio/"); public static GsCallback.b2 IsMimeVideo = (context, file) -> file != null && GsContextUtils.instance.getMimeType(context, file).startsWith("video/"); - public static GsFileBrowserOptions.Options prepareFsViewerOpts(Context context, boolean doSelectFolder, GsFileBrowserOptions.SelectionListener listener) { + public static GsFileBrowserOptions.Options prepareFsViewerOpts( + final Context context, + final boolean doSelectFolder, + final GsFileBrowserOptions.SelectionListener listener + ) { final GsFileBrowserOptions.Options opts = new GsFileBrowserOptions.Options(); final MarkorContextUtils cu = new MarkorContextUtils(context); final AppSettings appSettings = ApplicationObject.settings(); @@ -40,9 +44,10 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(Context context, opts.doSelectFolder = doSelectFolder; opts.doSelectFile = !doSelectFolder; + opts.okButtonEnable = opts.doSelectFolder || opts.doSelectMultiple; + opts.searchButtonImage = R.drawable.ic_search_black_24dp; opts.newDirButtonImage = R.drawable.baseline_create_new_folder_24; - opts.newFileButtonImage = R.drawable.ic_add_white_24dp; opts.homeButtonImage = R.drawable.ic_home_black_24dp; opts.selectedItemImage = R.drawable.ic_check_black_24dp; opts.newDirButtonText = R.string.create_folder; @@ -85,7 +90,7 @@ public static File[] strlistToArray(List strlist) { return files; } - private static void showDialog(FragmentManager fm, GsFileBrowserOptions.Options opts) { + private static void showDialog(final FragmentManager fm, final GsFileBrowserOptions.Options opts) { GsFileBrowserDialog filesystemViewerDialog = GsFileBrowserDialog.newInstance(opts); filesystemViewerDialog.show(fm, GsFileBrowserDialog.FRAGMENT_TAG); } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index d3c9a28101..268de40abc 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -53,8 +53,8 @@ public class GsFileBrowserDialog extends DialogFragment implements GsFileBrowser //######################## public static final String FRAGMENT_TAG = "FilesystemViewerCreator"; - public static GsFileBrowserDialog newInstance(GsFileBrowserOptions.Options options) { - GsFileBrowserDialog f = new GsFileBrowserDialog(); + public static GsFileBrowserDialog newInstance(final GsFileBrowserOptions.Options options) { + final GsFileBrowserDialog f = new GsFileBrowserDialog(); f.setStyle(DialogFragment.STYLE_NO_TITLE, 0); options.listener.onFsViewerConfig(options); f.setDialogOptions(options); @@ -71,7 +71,6 @@ public static GsFileBrowserDialog newInstance(GsFileBrowserOptions.Options optio private FloatingActionButton _homeButton; private FloatingActionButton _buttonSearch; private FloatingActionButton _buttonNewDir; - private FloatingActionButton _buttonNewFile; private EditText _searchEdit; private GsFileBrowserListAdapter _filesystemViewerAdapter; @@ -103,13 +102,12 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _buttonCancel = root.findViewById(R.id.ui__filesystem_dialog__button_cancel); _buttonOk = root.findViewById(R.id.ui__filesystem_dialog__button_ok); _homeButton = root.findViewById(R.id.ui__filesystem_dialog__home); - _buttonNewFile = root.findViewById(R.id.ui__filesystem_dialog__new_file); _buttonNewDir = root.findViewById(R.id.ui__filesystem_dialog__new_dir); _buttonSearch = root.findViewById(R.id.ui__filesystem_dialog__search_button); _searchEdit = root.findViewById(R.id.ui__filesystem_dialog__search_edit); _searchEdit.addTextChangedListener(GsTextWatcherAdapter.on(this::changeAdapterFilter)); - for (final View v : new View[]{_homeButton, _buttonSearch, _buttonNewDir, _buttonCancel, _buttonOk, _buttonNewFile}) { + for (final View v : new View[]{_homeButton, _buttonSearch, _buttonNewDir, _buttonCancel, _buttonOk}) { v.setOnClickListener(this::onClicked); } @@ -143,10 +141,6 @@ public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { _buttonNewDir.setVisibility(_dopt.newDirButtonEnable ? View.VISIBLE : View.GONE); _buttonNewDir.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); - _buttonNewFile.setImageResource(_dopt.newFileButtonImage); - _buttonNewFile.setVisibility(_dopt.createFileCallback != null ? View.VISIBLE : View.GONE); - _buttonNewFile.setColorFilter(rcolor(_dopt.primaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); - _searchEdit.setHint(_dopt.searchHint); _searchEdit.setTextColor(rcolor(_dopt.primaryTextColor)); _searchEdit.setHintTextColor(rcolor(_dopt.secondaryTextColor)); @@ -174,7 +168,6 @@ private void setDialogOptions(GsFileBrowserOptions.Options options) { _dopt = options; _callback = _dopt.listener; _dopt.listener = this; - checkOptions(); } public void changeAdapterFilter(CharSequence s, int start, int before, int count) { @@ -204,16 +197,13 @@ public void onClicked(final View view) { } case R.id.ui__filesystem_dialog__button_cancel: { onFsViewerNothingSelected(_dopt.requestId); + dismiss(); break; } case R.id.ui__filesystem_dialog__new_dir: { showNewDirDialog(); break; } - case R.id.ui__filesystem_dialog__new_file: { - showCreateFile(); - break; - } } } @@ -223,17 +213,6 @@ public void onDismiss(final DialogInterface dialog) { GsContextUtils.instance.showSoftKeyboard(getActivity(), false, _searchEdit); } - private void showCreateFile() { - // Initially implementing with create and show file - _dopt.createFileCallback.callback(_filesystemViewerAdapter.getCurrentFolder(), - (newFile) -> { - _filesystemViewerAdapter.reloadCurrentFolder(); - if (newFile != null) { - _recyclerList.postDelayed(() -> _filesystemViewerAdapter.showAndBlink(newFile, _recyclerList), 200); - } - }); - } - private void showNewDirDialog() { final Activity activity = getActivity(); @@ -256,14 +235,8 @@ private void showNewDirDialog() { GsSearchOrCustomTextDialog.showMultiChoiceDialogWithSearchFilterUI(activity, dopt); } - private void checkOptions() { - if (_dopt.doSelectFile && !_dopt.doSelectMultiple) { - _dopt.okButtonEnable = false; - } - } - @Override - public void onFsViewerSelected(String request, File file, final Integer lineNumber) { + public void onFsViewerSelected(final String request, final File file, final Integer lineNumber) { if (_callback != null) { _callback.onFsViewerSelected(_dopt.requestId, file, lineNumber); } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java index f4a4034525..c3e69e8bd2 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java @@ -321,7 +321,7 @@ public void onClick(View view) { switch (view.getId()) { case R.id.opoc_filesystem_item__root: { // A own item was clicked - TagContainer data = (TagContainer) view.getTag(); + final TagContainer data = (TagContainer) view.getTag(); if (data != null && data.file != null) { File file = data.file; if (_virtualMapping.containsKey(file)) { @@ -353,7 +353,7 @@ public void onClick(View view) { case R.id.ui__filesystem_dialog__button_ok: { if (_dopt.doSelectMultiple && areItemsSelected()) { _dopt.listener.onFsViewerMultiSelected(_dopt.requestId, _currentSelection.toArray(new File[0])); - } else if (_dopt.doSelectFolder && (_currentFolder.exists() || isCurrentFolderVirtual())) { + } else { _dopt.listener.onFsViewerSelected(_dopt.requestId, _currentFolder, null); } return; diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java index a34f7ebd25..f814f80313 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java @@ -9,7 +9,6 @@ #########################################################*/ package net.gsantner.opoc.frontend.filebrowser; -import android.app.Activity; import android.content.Context; import android.os.Environment; @@ -77,13 +76,6 @@ public static class Options { public GsCallback.b2 fileOverallFilter = (context, file) -> true; - /** - * First argument is the directory in which the file is to be created - * Second argument is a callback which can be called after the file is created. - * Calling this callback is optional. It will show and blink the created file. - */ - public GsCallback.a2> createFileCallback = null; - @StringRes public int cancelButtonText = android.R.string.cancel; @StringRes @@ -107,8 +99,6 @@ public static class Options { @DrawableRes public int newDirButtonImage = android.R.drawable.ic_menu_add; @DrawableRes - public int newFileButtonImage = android.R.drawable.ic_menu_add; - @DrawableRes public int folderImage = android.R.drawable.ic_menu_view; @DrawableRes public int selectedItemImage = android.R.drawable.checkbox_on_background; diff --git a/app/src/main/res/layout/opoc_filesystem_dialog.xml b/app/src/main/res/layout/opoc_filesystem_dialog.xml index 30e6e19c08..ec9b3fdcc2 100644 --- a/app/src/main/res/layout/opoc_filesystem_dialog.xml +++ b/app/src/main/res/layout/opoc_filesystem_dialog.xml @@ -67,24 +67,10 @@ android:layout_height="wrap_content" app:fabSize="mini" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toTopOf="@id/ui__filesystem_dialog__new_file" - android:layout_marginRight="10dp" - android:layout_marginBottom="15dp" - android:alpha="0.50" - tools:ignore="ContentDescription" - app:shapeAppearance="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"/> - - @@ -98,7 +84,7 @@ app:layout_constraintBottom_toTopOf="@id/ui__filesystem_dialog__home" android:layout_marginRight="10dp" android:layout_marginBottom="15dp" - android:alpha="0.50" + android:alpha="0.75" tools:ignore="ContentDescription" app:shapeAppearance="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"/> @@ -112,7 +98,7 @@ app:layout_constraintBottom_toTopOf="@id/ui__filesystem_dialog__buttons" android:layout_marginRight="10dp" android:layout_marginBottom="15dp" - android:alpha="0.50" + android:alpha="0.75" tools:ignore="ContentDescription" app:shapeAppearance="@style/ShapeAppearanceOverlay.Material3.FloatingActionButton"/>