remember the scroll state when browsing between folders
This commit is contained in:
parent
7c1ede4f4a
commit
3eb48cb3b1
3 changed files with 28 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.simplemobiletools.filemanager
|
package com.simplemobiletools.filemanager
|
||||||
|
|
||||||
val PATH = "path"
|
val PATH = "path"
|
||||||
|
val SCROLL_STATE = "scroll_state"
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
val PREFS_KEY = "File Manager"
|
val PREFS_KEY = "File Manager"
|
||||||
|
|
|
@ -5,11 +5,13 @@ import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
import android.os.Parcelable
|
||||||
import android.support.v4.app.ActivityCompat
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.filemanager.PATH
|
import com.simplemobiletools.filemanager.PATH
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
|
import com.simplemobiletools.filemanager.SCROLL_STATE
|
||||||
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
import com.simplemobiletools.filemanager.fragments.ItemsFragment
|
||||||
import com.simplemobiletools.filepicker.dialogs.StoragePickerDialog
|
import com.simplemobiletools.filepicker.dialogs.StoragePickerDialog
|
||||||
import com.simplemobiletools.filepicker.extensions.getInternalStoragePath
|
import com.simplemobiletools.filepicker.extensions.getInternalStoragePath
|
||||||
|
@ -19,9 +21,12 @@ import com.simplemobiletools.filepicker.models.FileDirItem
|
||||||
import com.simplemobiletools.filepicker.views.Breadcrumbs
|
import com.simplemobiletools.filepicker.views.Breadcrumbs
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
||||||
var mBasePath = getInternalStoragePath()
|
var mBasePath = getInternalStoragePath()
|
||||||
|
var latestFragment: ItemsFragment? = null
|
||||||
|
var mScrollStates = HashMap<String, Parcelable>()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val STORAGE_PERMISSION = 1
|
private val STORAGE_PERMISSION = 1
|
||||||
|
@ -59,10 +64,18 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(PATH, path)
|
bundle.putString(PATH, path)
|
||||||
|
|
||||||
val fragment = ItemsFragment()
|
if (mScrollStates.containsKey(path.trimEnd('/'))) {
|
||||||
fragment.arguments = bundle
|
bundle.putParcelable(SCROLL_STATE, mScrollStates[path.trimEnd('/')])
|
||||||
fragment.setListener(this)
|
}
|
||||||
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, fragment).addToBackStack(path).commitAllowingStateLoss()
|
|
||||||
|
if (latestFragment != null) {
|
||||||
|
mScrollStates.put(latestFragment!!.mPath.trimEnd('/'), latestFragment!!.getScrollState())
|
||||||
|
}
|
||||||
|
|
||||||
|
latestFragment = ItemsFragment()
|
||||||
|
latestFragment!!.arguments = bundle
|
||||||
|
latestFragment!!.setListener(this)
|
||||||
|
supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, latestFragment).addToBackStack(path).commitAllowingStateLoss()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
|
|
@ -5,7 +5,9 @@ import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Parcelable
|
||||||
import android.support.design.widget.Snackbar
|
import android.support.design.widget.Snackbar
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -13,6 +15,7 @@ import android.webkit.MimeTypeMap
|
||||||
import com.simplemobiletools.filemanager.Config
|
import com.simplemobiletools.filemanager.Config
|
||||||
import com.simplemobiletools.filemanager.PATH
|
import com.simplemobiletools.filemanager.PATH
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
|
import com.simplemobiletools.filemanager.SCROLL_STATE
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||||
|
@ -31,8 +34,8 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat
|
||||||
lateinit var mConfig: Config
|
lateinit var mConfig: Config
|
||||||
lateinit var mToBeDeleted: MutableList<String>
|
lateinit var mToBeDeleted: MutableList<String>
|
||||||
|
|
||||||
private var mPath = ""
|
|
||||||
private var mShowHidden = false
|
private var mShowHidden = false
|
||||||
|
var mPath = ""
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) =
|
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?) =
|
||||||
inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
inflater!!.inflate(R.layout.items_fragment, container, false)!!
|
||||||
|
@ -87,8 +90,14 @@ class ItemsFragment : android.support.v4.app.Fragment(), ItemsAdapter.ItemOperat
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as ItemsAdapter).updateItems(mItems)
|
(currAdapter as ItemsAdapter).updateItems(mItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRecyclerLayoutManager().onRestoreInstanceState(arguments.getParcelable<Parcelable>(SCROLL_STATE))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getRecyclerLayoutManager() = (items_list.layoutManager as LinearLayoutManager)
|
||||||
|
|
||||||
|
fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
|
||||||
|
|
||||||
fun setListener(listener: ItemInteractionListener) {
|
fun setListener(listener: ItemInteractionListener) {
|
||||||
mListener = listener
|
mListener = listener
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue