always create a new list adapter to ensure proper scroll state

This commit is contained in:
tibbi 2018-01-08 15:50:52 +01:00
parent e41d5de4aa
commit 90c854dbf2
3 changed files with 21 additions and 24 deletions

View File

@ -41,7 +41,7 @@ ext {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.6.3' implementation 'com.simplemobiletools:commons:3.6.11'
implementation files('../libs/RootTools.jar') implementation files('../libs/RootTools.jar')

View File

@ -261,7 +261,9 @@ class MainActivity : SimpleActivity() {
if (!wasBackJustPressed) { if (!wasBackJustPressed) {
wasBackJustPressed = true wasBackJustPressed = true
toast(R.string.press_back_again) toast(R.string.press_back_again)
Handler().postDelayed({ wasBackJustPressed = false }, BACK_PRESS_TIMEOUT.toLong()) Handler().postDelayed({
wasBackJustPressed = false
}, BACK_PRESS_TIMEOUT.toLong())
} else { } else {
finish() finish()
} }
@ -318,8 +320,10 @@ class MainActivity : SimpleActivity() {
} }
fun openedDirectory() { fun openedDirectory() {
if (searchMenuItem != null) {
MenuItemCompat.collapseActionView(searchMenuItem) MenuItemCompat.collapseActionView(searchMenuItem)
} }
}
private fun checkWhatsNewDialog() { private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply { arrayListOf<Release>().apply {

View File

@ -139,8 +139,6 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
mView.breadcrumbs.setBreadcrumb(currentPath) mView.breadcrumbs.setBreadcrumb(currentPath)
storedItems = items storedItems = items
val currAdapter = items_list.adapter
if (currAdapter == null) {
ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) { ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller) {
itemClicked(it as FileDirItem) itemClicked(it as FileDirItem)
}.apply { }.apply {
@ -152,15 +150,10 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
items_fastscroller.setViews(items_list, items_swipe_refresh) { items_fastscroller.setViews(items_list, items_swipe_refresh) {
items_fastscroller.updateBubbleText(storedItems.getOrNull(it)?.getBubbleText() ?: "") items_fastscroller.updateBubbleText(storedItems.getOrNull(it)?.getBubbleText() ?: "")
} }
} else {
(currAdapter as ItemsAdapter).updateItems(storedItems)
val savedState = scrollStates[currentPath] getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath])
if (savedState != null) { items_list.onGlobalLayout {
getRecyclerLayoutManager().onRestoreInstanceState(savedState) items_fastscroller.setScrollTo(items_list.computeVerticalScrollOffset())
} else {
getRecyclerLayoutManager().scrollToPosition(0)
}
} }
} }
} }