Skip to content

Commit

Permalink
Small features and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jun 14, 2024
1 parent 984f992 commit 7862ce1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/net/gsantner/markor/format/ActionButtonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.os.Build;
import android.os.Handler;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
Expand Down Expand Up @@ -827,6 +829,17 @@ protected final boolean runCommonLongPressAction(@StringRes int action) {
AttachLinkOrFileDialog.insertCameraPhoto(_activity, _document.getFormat(), _hlEditor.getText(), _document.getFile());
return true;
}
case R.string.abid_common_new_line_below: {
// Long press = line above
final Editable text = _hlEditor.getText();
if (text != null) {
final int sel = TextViewUtils.getSelection(text)[0];
final int lineStart = TextViewUtils.getLineStart(text, sel);
text.insert(lineStart, "\n");
_hlEditor.setSelection(lineStart);
}
return true;
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private AlertDialog.Builder makeDialog(final File basedir, final boolean allowCr

String format = formatEdit.getText().toString().trim();
if (format.isEmpty() && title.isEmpty()) {
format = "`yyyy-MM-dd'T'hhMMss`";
format = "`yyyy-MM-dd'T'HHmmss`";
} else if (format.isEmpty()) {
format = "{{title}}";
} else if (!title.isEmpty() && !format.contains("{{title}}")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ public Set<String> getTitleFormats() {
formats.addAll(Arrays.asList(
"{{date}}_{{title}}",
"{{date}}T{{time}}_{{title}}",
"`yyyyMMddHHmmSS`_{{title}}",
"`yyyyMMddHHmmss`_{{title}}",
"{{uuid}}"
));
return formats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
Expand Down Expand Up @@ -539,6 +538,7 @@ public File createDirectoryHere(final CharSequence name, final boolean show) {
return null;
}

// This method tries several methods to ensure that the recyclerview is updated after data changes
public void doAfterChange(final GsCallback.a0 callback) {
if (_recyclerView == null) {
return;
Expand All @@ -548,15 +548,14 @@ public void doAfterChange(final GsCallback.a0 callback) {
registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
final ViewTreeObserver vto = _recyclerView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
unregisterAdapterDataObserver(this);
_recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onGlobalLayout() {
_recyclerView.postDelayed(callback::callback, 250);
vto.removeOnGlobalLayoutListener(this);
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
_recyclerView.removeOnLayoutChangeListener(this);
callback.callback();
}
});
unregisterAdapterDataObserver(this);
}
});
}
Expand Down Expand Up @@ -586,25 +585,11 @@ public void showFile(final File file) {
*/
private void showAndFlash(final File file) {
final int pos = getFilePosition(file);

if (pos >= 0 && _layoutManager != null) {

final GsCallback.a0 blink = () -> {
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
GsContextUtils.blinkView(holder.itemView);
}
};

final int firstVisible = _layoutManager.findFirstCompletelyVisibleItemPosition();
final int lastVisible = _layoutManager.findLastCompletelyVisibleItemPosition();
if (pos < firstVisible || pos > lastVisible) {
// Scroll to position if needed and call.
// The delay works better than a listener on the scroll state
_layoutManager.scrollToPositionWithOffset(pos, 1);
_recyclerView.postDelayed(blink::callback, 500);
} else {
blink.callback();
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
_layoutManager.scrollToPosition(pos);
_recyclerView.post(() -> GsContextUtils.blinkView(holder.itemView));
}
}
}
Expand Down Expand Up @@ -734,16 +719,19 @@ private void loadFolder(final File folder, final @Nullable File toShow) {
_fileIdMap.clear();
}

if (folderChanged && GsFileUtils.isChild(_currentFolder, toShow)) {
doAfterChange(() -> showAndFlash(toShow));
}

// TODO - add logic to notify the changed bits
notifyDataSetChanged();

if (folderChanged && _layoutManager != null && _recyclerView != null) {
final Parcelable state = _folderScrollMap.remove(_currentFolder);
_recyclerView.post(() -> _layoutManager.onRestoreInstanceState(state));
if (folderChanged) {
_recyclerView.post(() -> {
if (_layoutManager != null) {
_layoutManager.onRestoreInstanceState(_folderScrollMap.remove(_currentFolder));
}

if (GsFileUtils.isChild(_currentFolder, toShow)) {
_recyclerView.postDelayed(() -> showAndFlash(toShow), 400);
}
});
}

if (_dopt.listener != null) {
Expand Down

0 comments on commit 7862ce1

Please sign in to comment.