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

Navigation and highlighting improvements #2377

Merged
merged 34 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a25a941
Many fixes to navigation and go back
harshad1 Jul 29, 2024
7de0995
Revert name change
harshad1 Jul 29, 2024
8ea9255
Revert revert
harshad1 Jul 29, 2024
4bae533
Cleanups to fragment handling
harshad1 Aug 8, 2024
fafd54a
Merge remote-tracking branch 'upstream/master' into file_browser_impr…
harshad1 Aug 8, 2024
d987437
Tweaks to showing keyboard
harshad1 Aug 14, 2024
c46d692
Final tweaks to activity stacks
harshad1 Aug 15, 2024
4f5428a
Removed unnecessary 'synchronized' calls for perf
harshad1 Aug 16, 2024
fdc484a
Cleanups
harshad1 Aug 16, 2024
c0e7b5c
Tweaks to highlighting
harshad1 Aug 17, 2024
587c005
Reverted some highlighting changes
harshad1 Aug 17, 2024
12ced96
More reverts
harshad1 Aug 17, 2024
287c271
Fix template cursor start
harshad1 Aug 17, 2024
00eae25
Improvements to display of file browser dialog / fragment
harshad1 Aug 17, 2024
092f22e
Initial set of changes for async
harshad1 Aug 18, 2024
4268201
Using canonical paths and and static members
harshad1 Aug 18, 2024
f731478
Merge branch 'file_browser_improvements' into highlight_in_separate_t…
harshad1 Aug 18, 2024
3ee43ac
Twesks to get it to work
harshad1 Aug 18, 2024
daeeeb0
Merge remote-tracking branch 'upstream/master' into file_browser_impr…
harshad1 Aug 18, 2024
3f906a1
Merge branch 'file_browser_improvements' into highlight_in_separate_t…
harshad1 Aug 19, 2024
d0417a8
Some small cleanups
harshad1 Aug 19, 2024
dd39531
Need index
harshad1 Aug 19, 2024
a656226
Cleaned op order of tests
harshad1 Aug 20, 2024
4631024
Defensive logic for indices
harshad1 Aug 23, 2024
1ca5698
Tweaks
harshad1 Aug 25, 2024
0d037ef
Batching fixup for reduced computation
harshad1 Aug 27, 2024
c620feb
Switching back to start end as it made no difference
harshad1 Aug 27, 2024
6b1bc6c
Yet more massaging spans for performance
harshad1 Aug 27, 2024
3a2daaa
Tweaks to reflow
harshad1 Aug 27, 2024
3738d2b
Tweaks and documentation
harshad1 Aug 28, 2024
372d7b5
Tweaks to launching; file paths -> canonical
harshad1 Sep 4, 2024
7cdb847
Fixed deps
harshad1 Sep 4, 2024
2cdef58
imports
harshad1 Sep 4, 2024
8c63366
Fixed wikitext link formatting
harshad1 Sep 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,24 @@
import net.gsantner.opoc.util.GsFileUtils;

import java.io.File;
import java.util.Stack;

import other.so.AndroidBug5497Workaround;

public class DocumentActivity extends MarkorBaseActivity {
public static final String EXTRA_DO_PREVIEW = "EXTRA_DO_PREVIEW";

private Toolbar _toolbar;

private FragmentManager _fragManager;

private static boolean nextLaunchTransparentBg = false;

public static void launch(final Activity activity, final Intent intent) {
final File file = MarkorContextUtils.getIntentFile(intent, null);
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);
}

public static void launch(
final Activity activity,
final File file,
Expand Down Expand Up @@ -90,18 +96,16 @@ private static void launch(

intent.putExtra(Document.EXTRA_FILE, file);

if (lineNumber != null && lineNumber >= 0) {
if (lineNumber != null) {
intent.putExtra(Document.EXTRA_FILE_LINE_NUMBER, lineNumber);
}

if (doPreview != null) {
intent.putExtra(DocumentActivity.EXTRA_DO_PREVIEW, doPreview);
intent.putExtra(Document.EXTRA_DO_PREVIEW, doPreview);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled() && !(activity instanceof DocumentActivity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

nextLaunchTransparentBg = (activity instanceof MainActivity);
Expand Down Expand Up @@ -190,7 +194,7 @@ private void handleLaunchingIntent(final Intent intent) {
final Document doc = new Document(file);
Integer startLine = null;
if (intent.hasExtra(Document.EXTRA_FILE_LINE_NUMBER)) {
startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, -1);
startLine = intent.getIntExtra(Document.EXTRA_FILE_LINE_NUMBER, Document.EXTRA_FILE_LINE_NUMBER_LAST);
} else if (intentData != null) {
final String line = intentData.getQueryParameter("line");
if (line != null) {
Expand All @@ -203,7 +207,7 @@ private void handleLaunchingIntent(final Intent intent) {
if (startLine != null) {
// If a line is requested, open in edit mode so the line is shown
startInPreview = false;
} else if (intent.getBooleanExtra(EXTRA_DO_PREVIEW, false) || file.getName().startsWith("index.")) {
} else if (intent.getBooleanExtra(Document.EXTRA_DO_PREVIEW, false) || file.getName().startsWith("index.")) {
startInPreview = true;
}

Expand Down Expand Up @@ -272,7 +276,7 @@ public void setDocumentTitle(final String title) {
}

public void showTextEditor(final Document document, final Integer lineNumber, final Boolean startPreview) {
final GsFragmentBase currentFragment = getCurrentVisibleFragment();
final GsFragmentBase<?, ?> currentFragment = getCurrentVisibleFragment();

final boolean sameDocumentRequested = (
currentFragment instanceof DocumentEditAndViewFragment &&
Expand All @@ -297,21 +301,15 @@ protected void onResume() {
@Override
@SuppressWarnings("StatementWithEmptyBody")
public void onBackPressed() {
FragmentManager fragMgr = getSupportFragmentManager();
GsFragmentBase top = getCurrentVisibleFragment();
if (top != null) {
if (!top.onBackPressed()) {
if (fragMgr.getBackStackEntryCount() == 1) {
// Back action was not handled by fragment, handle in activity
} else if (fragMgr.getBackStackEntryCount() > 0) {
// Back action was to go one fragment back
fragMgr.popBackStack();
return;
}
} else {
// Was handled by child fragment
return;
}
final int entryCount = _fragManager.getBackStackEntryCount();
final GsFragmentBase<?, ?> top = getCurrentVisibleFragment();

// We pop the stack to go back to the previous fragment
// if the top fragment does not handle the back press
// Doesn't actually get called as we have 1 fragment in the stack
if (top != null && !top.onBackPressed() && entryCount > 1) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Back now goes to previous directory

_fragManager.popBackStack();
return;
}

// Handle in this activity
Expand All @@ -324,10 +322,10 @@ public void onBackPressed() {

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onReceiveKeyPress(getCurrentVisibleFragment(), keyCode, event) ? true : super.onKeyDown(keyCode, event);
return super.onReceiveKeyPress(getCurrentVisibleFragment(), keyCode, event) || super.onKeyDown(keyCode, event);
}

public GsFragmentBase showFragment(GsFragmentBase fragment) {
public GsFragmentBase<?, ?> showFragment(GsFragmentBase<?, ?> fragment) {
if (fragment != getCurrentVisibleFragment()) {
_fragManager.beginTransaction()
.replace(R.id.document__placeholder_fragment, fragment, fragment.getFragmentTag())
Expand All @@ -338,11 +336,11 @@ public GsFragmentBase showFragment(GsFragmentBase fragment) {
return fragment;
}

public synchronized GsFragmentBase getExistingFragment(final String fragmentTag) {
return (GsFragmentBase) getSupportFragmentManager().findFragmentByTag(fragmentTag);
public synchronized GsFragmentBase<?, ?> getExistingFragment(final String fragmentTag) {
return (GsFragmentBase<?, ?>) getSupportFragmentManager().findFragmentByTag(fragmentTag);
}

private GsFragmentBase getCurrentVisibleFragment() {
return (GsFragmentBase) getSupportFragmentManager().findFragmentById(R.id.document__placeholder_fragment);
private GsFragmentBase<?, ?> getCurrentVisibleFragment() {
return (GsFragmentBase<?, ?>) getSupportFragmentManager().findFragmentById(R.id.document__placeholder_fragment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,9 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
}
});
}
}

@Override
public void onFragmentFirstTimeVisible() {
_primaryScrollView.invalidate();
int startPos = _appSettings.getLastEditPosition(_document.getPath(), _hlEditor.length());

// First start - overwrite start position if needed
if (_savedInstanceState == null) {
final Bundle args = getArguments();
if (savedInstanceState == null) {
int startPos = _appSettings.getLastEditPosition(_document.getPath(), _hlEditor.length());
if (args != null && args.containsKey(Document.EXTRA_FILE_LINE_NUMBER)) {
final int lno = args.getInt(Document.EXTRA_FILE_LINE_NUMBER);
if (lno >= 0) {
Expand All @@ -269,9 +262,9 @@ public void onFragmentFirstTimeVisible() {
startPos = _hlEditor.length();
}
}
}

TextViewUtils.setSelectionAndShow(_hlEditor, startPos);
TextViewUtils.setSelectionAndShow(_hlEditor, startPos);
}
}

@Override
Expand Down Expand Up @@ -442,8 +435,7 @@ public boolean loadDocument() {
_editTextUndoRedoHelper.setTextView(_hlEditor);
}

_hlEditor.setSelection(sel[0], sel[1]);
TextViewUtils.showSelection(_hlEditor);
TextViewUtils.setSelectionAndShow(_hlEditor, sel);
}
checkTextChangeState();

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

import other.writeily.widget.WrMarkorWidgetProvider;

public class MainActivity extends MarkorBaseActivity implements GsFileBrowserFragment.FilesystemFragmentOptionsListener, NavigationBarView.OnItemSelectedListener {
public class MainActivity extends MarkorBaseActivity implements GsFileBrowserFragment.FilesystemFragmentOptionsListener {

public static boolean IS_DEBUG_ENABLED = false;

Expand Down Expand Up @@ -101,7 +101,11 @@ public void onPageSelected(int position) {
// Setup viewpager
_viewPager.setAdapter(new SectionsPagerAdapter(getSupportFragmentManager()));
_viewPager.setOffscreenPageLimit(4);
_bottomNav.setOnItemSelectedListener(this);
_bottomNav.setOnItemSelectedListener((item) -> {
_viewPager.setCurrentItem(tabIdToPos(item.getItemId()));
return true;
});

reduceViewpagerSwipeSensitivity();

// noinspection PointlessBooleanExpression - Send Test intent
Expand Down Expand Up @@ -343,12 +347,6 @@ public void onBackPressed() {
new Handler().postDelayed(() -> _doubleBackToExitPressedOnce = false, 2000);
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
_viewPager.setCurrentItem(tabIdToPos(item.getItemId()));
return true;
}

public String getFileBrowserTitle() {
final File file = _appSettings.getFileBrowserLastBrowsedFolder();
String title = getString(R.string.app_name);
Expand Down Expand Up @@ -406,7 +404,7 @@ public void onViewPagerPageSelected(final int pos) {

if (pos == tabIdToPos(R.id.nav_notebook)) {
_fab.show();
_cu.showSoftKeyboard(this, false);
_cu.showSoftKeyboard(this, false, _notebook.getView());
} else {
_fab.hide();
restoreDefaultToolbar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

import net.gsantner.markor.activity.DocumentActivity;
import net.gsantner.markor.activity.MarkorBaseActivity;
import net.gsantner.markor.util.MarkorContextUtils;

import java.io.File;

/**
* This Activity exists solely to launch DocumentActivity with the correct intent
Expand All @@ -28,10 +25,7 @@ protected void onNewIntent(final Intent intent) {
}

private void launchActivityAndFinish(Intent intent) {
final File file = MarkorContextUtils.getIntentFile(intent, null);
if (file != null) {
DocumentActivity.launch(this, file, null, null);
}
DocumentActivity.launch(this, intent);
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static void showSttFilteringDialog(final Activity activity, final EditTex

// Delete view
doptView.neutralButtonText = R.string.delete;
doptView.isSoftInputVisible = false;
doptView.neutralButtonCallback = viewDialog -> {
final DialogOptions confirmDopt = new DialogOptions();
baseConf(activity, confirmDopt);
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/net/gsantner/markor/frontend/NewFileDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,12 @@ public static NewFileDialog newInstance(
public Dialog onCreateDialog(Bundle savedInstanceState) {
final File file = (File) getArguments().getSerializable(EXTRA_DIR);
final boolean allowCreateDir = getArguments().getBoolean(EXTRA_ALLOW_CREATE_DIR);

LayoutInflater inflater = LayoutInflater.from(getActivity());
AlertDialog.Builder dialogBuilder = makeDialog(file, allowCreateDir, inflater);
AlertDialog dialog = dialogBuilder.show();
Window w;
if ((w = dialog.getWindow()) != null) {
w.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
return dialog;
final LayoutInflater inflater = LayoutInflater.from(getActivity());
return makeDialog(file, allowCreateDir, inflater);
}

@SuppressLint("SetTextI18n")
private AlertDialog.Builder makeDialog(final File basedir, final boolean allowCreateDir, LayoutInflater inflater) {
private AlertDialog makeDialog(final File basedir, final boolean allowCreateDir, LayoutInflater inflater) {
final Activity activity = getActivity();
final AppSettings appSettings = ApplicationObject.settings();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(inflater.getContext(), R.style.Theme_AppCompat_DayNight_Dialog_Rounded);
Expand Down Expand Up @@ -349,9 +342,15 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
final List<Integer> indices = GsCollectionUtils.indices(formats, f -> f.format == lastUsedType);
typeSpinner.setSelection(indices.isEmpty() ? 0 : indices.get(0));

titleEdit.requestFocus();
final AlertDialog dialog = dialogBuilder.show();
final Window win = dialog.getWindow();
if (win != null) {
win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
titleEdit.post(titleEdit::requestFocus);

return dialogBuilder;
return dialog;
}

private void callback(final File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(
opts.newDirButtonText = R.string.create_folder;
opts.upButtonEnable = true;
opts.homeButtonEnable = true;
opts.mustStartWithRootFolder = false;
opts.contentDescriptionFolder = R.string.folder;
opts.contentDescriptionSelected = R.string.selected;
opts.contentDescriptionFile = R.string.file;
Expand All @@ -68,6 +67,7 @@ public static GsFileBrowserOptions.Options prepareFsViewerOpts(
opts.folderColor = R.color.folder;
opts.fileImage = R.drawable.ic_file_white_24dp;
opts.folderImage = R.drawable.ic_folder_white_24dp;
opts.descriptionFormat = appSettings.getString(R.string.pref_key__file_description_format, "");

opts.titleText = R.string.select;

Expand Down Expand Up @@ -109,6 +109,7 @@ public static GsFileBrowserDialog showFileDialog(
) {
final GsFileBrowserOptions.Options opts = prepareFsViewerOpts(context, false, listener);
opts.fileOverallFilter = fileOverallFilter;
opts.descModtimeInsteadOfParent = true;
return showDialog(fm, opts);
}

Expand All @@ -119,6 +120,7 @@ public static GsFileBrowserDialog showFolderDialog(
) {
final GsFileBrowserOptions.Options opts = prepareFsViewerOpts(context, true, listener);
opts.okButtonText = R.string.select_this_folder;
opts.descModtimeInsteadOfParent = true;
return showDialog(fm, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ protected void onDraw(Canvas canvas) {
// ---------------------------------------------------------------------------------------------

private boolean isScrollSignificant() {
return (_oldHlRect.top - _hlRect.top) > _hlShiftThreshold ||
(_hlRect.bottom - _oldHlRect.bottom) > _hlShiftThreshold;
return Math.abs(_oldHlRect.top - _hlRect.top) > _hlShiftThreshold ||
Math.abs(_hlRect.bottom - _oldHlRect.bottom) > _hlShiftThreshold;
}

private void updateHighlighting(final boolean recompute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static void setSelectionAndShow(final EditText edit, final int... sel) {
}

edit.setSelection(start, end);
edit.postDelayed(() -> showSelection(edit, start, end), 250);
edit.post(() -> showSelection(edit, start, end));
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void addRecentFile(final File file) {
public void setFavouriteFiles(final Collection<File> files) {
final Set<String> set = new LinkedHashSet<>();
for (final File f : files) {
if (f != null && (f.exists() || GsFileBrowserListAdapter.isVirtualStorage(f))) {
gsantner marked this conversation as resolved.
Show resolved Hide resolved
if (f != null && (f.exists() || GsFileBrowserListAdapter.isVirtualFolder(f))) {
set.add(f.getAbsolutePath());
}
}
Expand Down Expand Up @@ -600,7 +600,7 @@ public static Set<File> getFileSet(final List<String> paths) {
final Set<File> set = new LinkedHashSet<>();
for (final String fp : paths) {
final File f = new File(fp);
if (f.exists() || GsFileBrowserListAdapter.isVirtualStorage(f)) {
if (f.exists() || GsFileBrowserListAdapter.isVirtualFolder(f)) {
set.add(f);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/net/gsantner/markor/model/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Document implements Serializable {
public static final String EXTRA_DOCUMENT = "EXTRA_DOCUMENT"; // Document
public static final String EXTRA_FILE = "EXTRA_FILE"; // java.io.File
public static final String EXTRA_FILE_LINE_NUMBER = "EXTRA_FILE_LINE_NUMBER"; // int
public static final String EXTRA_DO_PREVIEW = "EXTRA_DO_PREVIEW";
gsantner marked this conversation as resolved.
Show resolved Hide resolved
public static final int EXTRA_FILE_LINE_NUMBER_LAST = -919385553; // Flag for last line

private final File _file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi
if (dopt.isSearchEnabled) {
if (dopt.isSoftInputVisible) {
win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
searchEditText.postDelayed(() -> win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED), 500);
gsantner marked this conversation as resolved.
Show resolved Hide resolved
searchEditText.requestFocus();
} else {
win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
Expand All @@ -377,10 +379,6 @@ public static void showMultiChoiceDialogWithSearchFilterUI(final Activity activi
neutralButton.setOnClickListener((button) -> dopt.neutralButtonCallback.callback(dialog));
}

if (dopt.isSearchEnabled) {
searchEditText.requestFocus();
}

if (dopt.defaultText != null) {
listAdapter.filter(searchEditText.getText());
}
Expand Down Expand Up @@ -543,7 +541,6 @@ private static View makeSearchView(final Context context, final DialogOptions do
final AppCompatEditText searchEditText = new AppCompatEditText(context);
searchEditText.setText(dopt.defaultText);
searchEditText.setSingleLine(true);
searchEditText.setMaxLines(1);
searchEditText.setTextColor(dopt.textColor);
searchEditText.setHintTextColor((dopt.textColor & 0x00FFFFFF) | 0x99000000);
searchEditText.setHint(dopt.searchHintText);
Expand Down
Loading
Loading