diff --git a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java index c0d0a7d685..1eeb2f3f72 100644 --- a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java +++ b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java @@ -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); } } 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 341f28b6be..44c9bef98f 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 @@ -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 * @@ -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); } } @@ -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)); } }); }