Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Quick filter all files #2521

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
34f98b9
Initial system with janky ui
harshad1 Jan 3, 2025
54ba2a6
Merge remote-tracking branch 'upstream/master' into per_folder_sort_o…
harshad1 Jan 3, 2025
a02026d
Separate options - aborting
harshad1 Jan 3, 2025
6f79ce0
Switching to dialog
harshad1 Jan 4, 2025
20b7c5e
Switching to dialog based sort
harshad1 Jan 4, 2025
5a01163
Cleanups to dialog
harshad1 Jan 4, 2025
2f6cfcb
New approach to dialog using change callback
harshad1 Jan 6, 2025
342d83a
Must check in the callback :)
harshad1 Jan 7, 2025
3237d18
Fixes, wrap improvements
harshad1 Jan 10, 2025
b4d1d1a
Reverted reflow settings
harshad1 Jan 11, 2025
b35b3d5
Fixed diff
harshad1 Jan 11, 2025
2f6c5c1
Better icon
harshad1 Jan 11, 2025
22c75b2
Getting it to work
harshad1 Jan 12, 2025
ebb636c
Merge branch 'master' into per_folder_sort_order
gsantner Jan 18, 2025
1f82aed
Merge branch 'per_folder_sort_order' of github.com:harshad1/markor in…
harshad1 Jan 20, 2025
29b672c
Pulling file search changes
harshad1 Jan 30, 2025
b99822e
Fixing calling and references
harshad1 Jan 30, 2025
c7d0d7e
Maintianing state
harshad1 Jan 30, 2025
7298ea7
Fix for jumping to position
harshad1 Jan 30, 2025
9e0312f
Tweaks
harshad1 Feb 1, 2025
8afbca9
Tweaks to dialog state
harshad1 Feb 1, 2025
03be03f
Toolbar click need not be protected
harshad1 Feb 1, 2025
081a2ad
Proper handling of title bar
harshad1 Feb 3, 2025
85abee3
Fixing how files are selected
harshad1 Feb 4, 2025
3ec6d1e
Merge branch 'per_folder_sort_order' into quick_filter_all_files
harshad1 Feb 4, 2025
5c8133d
Pulled fixes and changes
harshad1 Feb 6, 2025
9142a2c
Merge remote-tracking branch 'upstream/master' into quick_filter_all_…
harshad1 Feb 6, 2025
428da2b
Fetching filename more correctly
harshad1 Feb 6, 2025
1413254
Fix
harshad1 Feb 6, 2025
3ae5467
Share to copy, long pres to open folder
harshad1 Feb 9, 2025
cfc2b1e
Fixes for showing
harshad1 Feb 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@

<data android:mimeType="text/plain" />
<data android:mimeType="text/*" />
<data android:mimeType="*/*" />
</intent-filter>

<intent-filter tools:ignore="AppLinkUrlError">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class DocumentActivity extends MarkorBaseActivity {
private static boolean nextLaunchTransparentBg = false;

public static void launch(final Activity activity, final Intent intent) {
final File file = MarkorContextUtils.getIntentFile(intent, null);
final File file = MarkorContextUtils.getIntentFile(intent);
final Integer lineNumber = intent.hasExtra(Document.EXTRA_FILE_LINE_NUMBER) ? intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1) : null;
final Boolean doPreview = intent.hasExtra(Document.EXTRA_DO_PREVIEW) ? intent.getBooleanExtra(Document.EXTRA_DO_PREVIEW, false) : null;
launch(activity, file, doPreview, lineNumber);
Expand Down Expand Up @@ -167,26 +167,19 @@ private void handleLaunchingIntent(final Intent intent) {

// Pull the file from the intent
// -----------------------------------------------------------------------
File file = (File) intent.getSerializableExtra(Document.EXTRA_FILE);
File file = MarkorContextUtils.getIntentFile(intent, this);

final boolean intentIsView = Intent.ACTION_VIEW.equals(intentAction);
final boolean intentIsSend = Intent.ACTION_SEND.equals(intentAction);
final boolean intentIsSend = Intent.ACTION_SEND.equals(intentAction) || Intent.ACTION_SEND_MULTIPLE.equals(intentAction);
final boolean intentIsEdit = Intent.ACTION_EDIT.equals(intentAction);

if (intentIsSend && intent.hasExtra(Intent.EXTRA_TEXT)) {
if (intentIsSend) {
showShareInto(intent);
return;
} else if (Intent.ACTION_PROCESS_TEXT.equals(intentAction) && intent.hasExtra(Intent.EXTRA_PROCESS_TEXT)) {
intent.putExtra(Intent.EXTRA_TEXT, intent.getStringExtra("android.intent.extra.PROCESS_TEXT"));
showShareInto(intent);
return;
} else if (file == null && (intentIsView || intentIsEdit || intentIsSend)) {
file = _cu.extractFileFromIntent(this, intent);
if (file == null) {
// More permissive - file may not exist
// Will be filtered out in next stage
file = MarkorContextUtils.getIntentFile(intent, null);
}
}

// Decide what to do with the file
Expand Down Expand Up @@ -294,7 +287,7 @@ public void showTextEditor(final Document document, final Integer lineNumber, fi

public void showShareInto(Intent intent) {
setTitle(getString(R.string.share_into));
showFragment(DocumentShareIntoFragment.newInstance(intent));
showFragment(DocumentShareIntoFragment.newInstance(intent, this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public static DocumentEditAndViewFragment newInstance(final @NonNull Document do
private boolean _isPreviewVisible;
private boolean _nextConvertToPrintMode = false;


public DocumentEditAndViewFragment() {
super();
}
Expand Down Expand Up @@ -141,7 +140,6 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
_webView = view.findViewById(R.id.document__fragment_view_webview);
_primaryScrollView = view.findViewById(R.id.document__fragment__edit__content_editor__scrolling_parent);
_lineNumbersView = view.findViewById(R.id.document__fragment__edit__line_numbers_view);

_cu = new MarkorContextUtils(activity);

// Using `if (_document != null)` everywhere is dangerous
Expand Down Expand Up @@ -284,6 +282,9 @@ protected void onFragmentFirstTimeVisible() {
public void onResume() {
loadDocument();
_webView.onResume();
if (_editTextUndoRedoHelper != null && _editTextUndoRedoHelper.getTextView() != _hlEditor) {
_editTextUndoRedoHelper.setTextView(_hlEditor);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We simplify loadContent and allow the undo-redo tracker to undo file load.

}
super.onResume();
}

Expand Down Expand Up @@ -438,31 +439,15 @@ public boolean loadDocument() {
}

if (!_document.isContentSame(_hlEditor.getText())) {

final int[] sel = TextViewUtils.getSelection(_hlEditor);
sel[0] = Math.min(sel[0], content.length());
sel[1] = Math.min(sel[1], content.length());

if (_editTextUndoRedoHelper != null) {
_editTextUndoRedoHelper.disconnect();
_editTextUndoRedoHelper.clearHistory();
}

_hlEditor.withAutoFormatDisabled(() -> _hlEditor.setText(content));

if (_editTextUndoRedoHelper == null) {
_editTextUndoRedoHelper = new TextViewUndoRedo(_hlEditor);
} else {
_editTextUndoRedoHelper.setTextView(_hlEditor);
}

TextViewUtils.setSelectionAndShow(_hlEditor, sel);
_hlEditor.withAutoFormatDisabled(() -> _hlEditor.setTextKeepState(content));
}

checkTextChangeState();

if (_isPreviewVisible) {
updateViewModeText();
}

return true;
}
return false;
Expand Down Expand Up @@ -659,10 +644,7 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
}
case R.id.action_show_file_browser: {
// Delay because I want menu to close before we open the file browser
_hlEditor.postDelayed(() -> {
final Intent intent = new Intent(activity, MainActivity.class).putExtra(Document.EXTRA_FILE, _document.file);
GsContextUtils.instance.animateToActivity(activity, intent, false, null);
}, 250);
_hlEditor.postDelayed(() -> MainActivity.launch(activity, _document.file, false), 250);
return true;
}
case R.id.action_toggle_case:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -50,6 +49,7 @@
import net.gsantner.opoc.frontend.base.GsPreferenceFragmentBase;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserListAdapter;
import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions;
import net.gsantner.opoc.util.GsContextUtils;
import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.wrapper.GsTextWatcherAdapter;

Expand All @@ -62,28 +62,19 @@

public class DocumentShareIntoFragment extends MarkorBaseFragment {
public static final String FRAGMENT_TAG = "DocumentShareIntoFragment";
public static final String EXTRA_SHARED_TEXT = "EXTRA_SHARED_TEXT";
public static final String TEXT_TOKEN = "{{text}}";

private static final String CHECKBOX_TAG = "insert_link_checkbox";

public static DocumentShareIntoFragment newInstance(final Intent intent) {
public static DocumentShareIntoFragment newInstance(final Intent intent, final Context context) {
final DocumentShareIntoFragment f = new DocumentShareIntoFragment();
final Bundle args = new Bundle();

final String sharedText = extractShareText(intent);

final Object intentFile = intent.getSerializableExtra(Document.EXTRA_FILE);
if (intentFile instanceof File && ((File) intentFile).isDirectory()) {
f.workingDir = (File) intentFile;
}

args.putString(EXTRA_SHARED_TEXT, sharedText);
f.setArguments(args);
f.sharedText = extractShareText(intent);
f.intentFile = MarkorContextUtils.getIntentFile(intent, context);
return f;
}

private File workingDir;
private File intentFile;
private String sharedText;

public DocumentShareIntoFragment() {
}
Expand All @@ -98,12 +89,11 @@ public void onViewCreated(final @NonNull View view, final Bundle savedInstanceSt
super.onViewCreated(view, savedInstanceState);
final HighlightingEditor _hlEditor = view.findViewById(R.id.document__fragment__share_into__highlighting_editor);

final String sharedText = (getArguments() != null ? getArguments().getString(EXTRA_SHARED_TEXT, "") : "").trim();
final ShareIntoImportOptionsFragment _shareIntoImportOptionsFragment;
if (_savedInstanceState == null) {
FragmentTransaction t = getChildFragmentManager().beginTransaction();
_shareIntoImportOptionsFragment = new ShareIntoImportOptionsFragment();
_shareIntoImportOptionsFragment.setWorkingDir(workingDir);
_shareIntoImportOptionsFragment.setIntentFile(intentFile);
t.replace(R.id.document__share_into__fragment__placeholder_fragment, _shareIntoImportOptionsFragment, ShareIntoImportOptionsFragment.TAG).commit();
} else {
_shareIntoImportOptionsFragment = (ShareIntoImportOptionsFragment) getChildFragmentManager().findFragmentByTag(ShareIntoImportOptionsFragment.TAG);
Expand All @@ -114,6 +104,10 @@ public void onViewCreated(final @NonNull View view, final Bundle savedInstanceSt
_shareIntoImportOptionsFragment._linkCheckBox = addCheckBoxToToolbar();
}

if (GsTextUtils.isNullOrEmpty(sharedText)) {
sharedText = intentFile != null ? GsFileUtils.getFilenameWithoutExtension(intentFile) : "";
}

_hlEditor.setTextSize(TypedValue.COMPLEX_UNIT_SP, _appSettings.getFontSize());
_hlEditor.setTypeface(Typeface.create(_appSettings.getFontFamily(), Typeface.NORMAL));
_hlEditor.setHighlighter(new PlaintextSyntaxHighlighter(_appSettings));
Expand Down Expand Up @@ -145,10 +139,7 @@ private CheckBox addCheckBoxToToolbar() {
checkBox.setTag(CHECKBOX_TAG);
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(Color.WHITE));
checkBox.setTextColor(Color.WHITE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
checkBox.setLayoutDirection(CheckBox.LAYOUT_DIRECTION_RTL);
}
checkBox.setLayoutDirection(CheckBox.LAYOUT_DIRECTION_RTL);

final Toolbar.LayoutParams layoutParams = new Toolbar.LayoutParams(
Toolbar.LayoutParams.WRAP_CONTENT,
Expand Down Expand Up @@ -189,7 +180,7 @@ public String getFragmentTag() {

public static class ShareIntoImportOptionsFragment extends GsPreferenceFragmentBase<AppSettings> {
public static final String TAG = "ShareIntoImportOptionsFragment";
private File workingDir;
private File intentFile;

private EditText _editor = null;
private CheckBox _linkCheckBox = null;
Expand All @@ -199,8 +190,9 @@ public boolean isDividerVisible() {
return true;
}

public void setWorkingDir(File dir) {
workingDir = dir;
public ShareIntoImportOptionsFragment setIntentFile(File file) {
intentFile = file;
return this;
}

@Override
Expand Down Expand Up @@ -229,13 +221,23 @@ protected void afterOnCreate(Bundle savedInstances, Context context) {
_editor.addTextChangedListener(GsTextWatcherAdapter.on((ctext, arg2, arg3, arg4) ->
_linkCheckBox.setVisibility(hasLinks(_editor.getText()) ? View.VISIBLE : View.GONE)));
}

findPreference(R.string.pref_key__select_create_directory).setVisible(intentFile != null);
findPreference(R.string.pref_key__share_into__clipboard).setVisible(intentFile == null);
findPreference(R.string.pref_key__share_into__calendar_event).setVisible(intentFile == null);
}

private boolean shareAsLink() {
return _linkCheckBox != null && _linkCheckBox.getVisibility() == View.VISIBLE && _linkCheckBox.isChecked();
}

private void appendToExistingDocumentAndClose(final File file, final boolean showEditor) {
/**
* Attach file to document or copy to directory and close
*
* @param file File or directory to attach to
* @param showEditor Whether to show the editor after attaching
*/
private void attachOrCopyAndClose(final File file, final boolean showEditor) {
final Activity activity = getActivity();
if (activity == null) {
return;
Expand All @@ -244,7 +246,14 @@ private void appendToExistingDocumentAndClose(final File file, final boolean sho
final Document document = new Document(file);
final int format = _appSettings.getDocumentFormat(document.path, document.getFormat());
final boolean asLink = shareAsLink();
final String formatted = getFormatted(asLink, file, format);

final String formatted;
if (intentFile != null) {
final String title = _editor.getText().toString().trim();
formatted = AttachLinkOrFileDialog.makeAttachmentLink(format, title, intentFile, file);
} else {
formatted = getFormatted(asLink, file, format);
}

final String oldContent = document.loadContent(activity);
if (oldContent != null) {
Expand Down Expand Up @@ -411,21 +420,53 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {

@Override
public void onFsViewerSelected(String request, File file, final Integer lineNumber) {
appendToExistingDocumentAndClose(file, true);
attachOrCopyAndClose(file, true);
}

}, getParentFragmentManager(), getActivity(), MarkorFileBrowserFactory.IsMimeText);
}

private void createSelectNewDirectory() {
MarkorFileBrowserFactory.showFolderDialog(new GsFileBrowserOptions.SelectionListenerAdapter() {
GsFileBrowserOptions.Options _dopt = null;

@Override
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_ROOT;
dopt.startFolder = _appSettings.getNotebookDirectory();
dopt.okButtonEnable = true;
dopt.dismissAfterCallback = true;
_dopt = dopt;
}

@Override
public void onFsViewerSelected(final String request, final File dir, final Integer lineNumber) {
if (dir != null && intentFile != null && dir.isDirectory() && dir.canWrite()) {
final File local = GsFileUtils.findNonConflictingDest(dir, intentFile.getName());
if (GsFileUtils.copyFile(intentFile, local)) {
MainActivity.launch(getActivity(), local, true);
return;
}
}
Toast.makeText(getContext(), "❌", Toast.LENGTH_SHORT).show();
}

@Override
public void onFsViewerCancel(final String request) {
// Will cause the dialog to dismiss after this callback
_dopt.dismissAfterCallback = true;
}
}, getParentFragmentManager(), getActivity());
}

private void createSelectNewDocument() {
MarkorFileBrowserFactory.showFileDialog(new GsFileBrowserOptions.SelectionListenerAdapter() {
GsFileBrowserOptions.Options _dopt = null;

@Override
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.rootFolder = _appSettings.getNotebookDirectory();
dopt.startFolder = workingDir;
dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_ROOT;
dopt.startFolder = intentFile.isDirectory() ? intentFile : null;
dopt.okButtonText = R.string.create_new_document;
dopt.okButtonEnable = true;
dopt.dismissAfterCallback = false;
Expand All @@ -439,11 +480,11 @@ public void onFsViewerSelected(final String request, final File sel, final Integ
} else if (sel.isDirectory()) {
NewFileDialog.newInstance(sel, false, f -> {
if (f.isFile()) {
appendToExistingDocumentAndClose(f, true);
attachOrCopyAndClose(f, true);
}
}).show(getChildFragmentManager(), NewFileDialog.FRAGMENT_TAG);
} else {
appendToExistingDocumentAndClose(sel, true);
attachOrCopyAndClose(sel, true);
}
}

Expand Down Expand Up @@ -482,18 +523,22 @@ public Boolean onPreferenceClicked(Preference preference, String key, int keyId)
createSelectNewDocument();
return true;
}
case R.string.pref_key__select_create_directory: {
createSelectNewDirectory();
return true;
}
case R.string.pref_key__favourite_files:
case R.string.pref_key__popular_documents:
case R.string.pref_key__recent_documents: {
showAppendDialog(keyId);
return true;
}
case R.string.pref_key__share_into__quicknote: {
appendToExistingDocumentAndClose(_appSettings.getQuickNoteFile(), false);
attachOrCopyAndClose(_appSettings.getQuickNoteFile(), false);
break;
}
case R.string.pref_key__share_into__todo: {
appendToExistingDocumentAndClose(_appSettings.getTodoFile(), false);
attachOrCopyAndClose(_appSettings.getTodoFile(), false);
break;
}
case R.string.pref_key__share_into__open_in_browser: {
Expand All @@ -519,7 +564,7 @@ public Boolean onPreferenceClicked(Preference preference, String key, int keyId)
}

if (preference.getKey().startsWith("/")) {
appendToExistingDocumentAndClose(new File(preference.getKey()), true);
attachOrCopyAndClose(new File(preference.getKey()), true);
}

if (close) {
Expand Down
Loading