From 90c854dbf20de7d25e89e866efe2215c7c48a4b3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 8 Jan 2018 15:50:52 +0100 Subject: [PATCH] always create a new list adapter to ensure proper scroll state --- app/build.gradle | 2 +- .../filemanager/activities/MainActivity.kt | 8 +++-- .../filemanager/fragments/ItemsFragment.kt | 35 ++++++++----------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 664a797c..62f2b467 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.6.3' + implementation 'com.simplemobiletools:commons:3.6.11' implementation files('../libs/RootTools.jar') diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 7e8211d5..d3bd4fed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -261,7 +261,9 @@ class MainActivity : SimpleActivity() { if (!wasBackJustPressed) { wasBackJustPressed = true toast(R.string.press_back_again) - Handler().postDelayed({ wasBackJustPressed = false }, BACK_PRESS_TIMEOUT.toLong()) + Handler().postDelayed({ + wasBackJustPressed = false + }, BACK_PRESS_TIMEOUT.toLong()) } else { finish() } @@ -318,7 +320,9 @@ class MainActivity : SimpleActivity() { } fun openedDirectory() { - MenuItemCompat.collapseActionView(searchMenuItem) + if (searchMenuItem != null) { + MenuItemCompat.collapseActionView(searchMenuItem) + } } private fun checkWhatsNewDialog() { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index a483751b..95e079bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -139,28 +139,21 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum mView.breadcrumbs.setBreadcrumb(currentPath) storedItems = items - val currAdapter = items_list.adapter - if (currAdapter == null) { - ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) { - itemClicked(it as FileDirItem) - }.apply { - setupDragListener(true) - addVerticalDividers(true) - items_list.adapter = this - } - items_fastscroller.allowBubbleDisplay = context.config.showInfoBubble - items_fastscroller.setViews(items_list, items_swipe_refresh) { - items_fastscroller.updateBubbleText(storedItems.getOrNull(it)?.getBubbleText() ?: "") - } - } else { - (currAdapter as ItemsAdapter).updateItems(storedItems) + ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) { + itemClicked(it as FileDirItem) + }.apply { + setupDragListener(true) + addVerticalDividers(true) + items_list.adapter = this + } + items_fastscroller.allowBubbleDisplay = context.config.showInfoBubble + items_fastscroller.setViews(items_list, items_swipe_refresh) { + items_fastscroller.updateBubbleText(storedItems.getOrNull(it)?.getBubbleText() ?: "") + } - val savedState = scrollStates[currentPath] - if (savedState != null) { - getRecyclerLayoutManager().onRestoreInstanceState(savedState) - } else { - getRecyclerLayoutManager().scrollToPosition(0) - } + getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath]) + items_list.onGlobalLayout { + items_fastscroller.setScrollTo(items_list.computeVerticalScrollOffset()) } } }