Skip to content

Commit

Permalink
Improved show and flash
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jun 30, 2024
1 parent f27d0ea commit b22a046
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
final File file = MarkorContextUtils.getValidIntentFile(intent, null);
if (_notebook != null && file != null) {
_viewPager.setCurrentItem(tabIdToPos(R.id.nav_notebook), false);
if (file.isDirectory() || GsFileBrowserListAdapter.isVirtualFolder(file)) {
_notebook.post(() -> _notebook.setCurrentFolder(file));
_notebook.setCurrentFolder(file);
} else {
_notebook.post(() -> _notebook.getAdapter().showFile(file));
_notebook.getAdapter().showFile(file);
}
_bottomNav.postDelayed(() -> _bottomNav.setSelectedItemId(R.id.nav_notebook), 10);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,46 +538,32 @@ 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;
}

// We wait for data to change and then a subsequent layout pass
registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
unregisterAdapterDataObserver(this);
_recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
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();
}
});
}
});
}

// Switch to folder and show the file
public void showFile(final File file) {
if (file == null || !file.exists() || _recyclerView == null) {
return;
}

final File dir = file.getParentFile();
if (dir == null) {
return;
}

if (getFilePosition(file) < 0) {
loadFolder(dir, file);
final File dir = file.getParentFile();
if (dir != null) {
loadFolder(dir, file);
}
} else {
showAndFlash(file);
}
}

private void doAfterChange(final GsCallback.a0 callback) {
_recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int l, int t, int r, int b, int ol, int ot, int or, int ob) {
_recyclerView.removeOnLayoutChangeListener(this);
callback.callback();
}
});
}

/**
* Show a file in the current folder and blink it
*
Expand All @@ -586,11 +572,13 @@ public void showFile(final File file) {
private void showAndFlash(final File file) {
final int pos = getFilePosition(file);
if (pos >= 0 && _layoutManager != null) {
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
_layoutManager.scrollToPosition(pos);
_recyclerView.post(() -> GsContextUtils.blinkView(holder.itemView));
}
doAfterChange(() -> _recyclerView.postDelayed(() -> {
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
GsContextUtils.blinkView(holder.itemView);
}
}, 400));
_layoutManager.scrollToPosition(pos);
}
}

Expand Down Expand Up @@ -729,7 +717,7 @@ private void loadFolder(final File folder, final @Nullable File toShow) {
}

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

0 comments on commit b22a046

Please sign in to comment.