From b425ab9a347df8c6209d696038be6fce415ab5d4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 30 Oct 2016 17:49:27 +0100 Subject: [PATCH] allow changing the storage in the main activity --- .../filemanager/activities/MainActivity.kt | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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 9cc693ed..b2da18d3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -12,12 +12,14 @@ import com.simplemobiletools.filemanager.Constants import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.Utils import com.simplemobiletools.filemanager.fragments.ItemsFragment +import com.simplemobiletools.filepicker.dialogs.StoragePickerDialog import com.simplemobiletools.filepicker.extensions.getInternalPath import com.simplemobiletools.filepicker.models.FileDirItem import com.simplemobiletools.filepicker.views.Breadcrumbs import kotlinx.android.synthetic.main.activity_main.* class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener { + var mBasePath = getInternalPath() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -56,11 +58,11 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br } private fun initRootFileManager() { - openPath(getInternalPath()) + openPath(mBasePath) } private fun openPath(path: String) { - breadcrumbs.setBreadcrumb(path, getInternalPath()) + breadcrumbs.setBreadcrumb(path, mBasePath) val bundle = Bundle() bundle.putString(Constants.PATH, path) @@ -123,12 +125,20 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br } override fun breadcrumbClicked(id: Int) { - val item = breadcrumbs.getChildAt(id).tag as FileDirItem - openPath(item.path) + if (id == 0) { + StoragePickerDialog(this@MainActivity, mBasePath, object : StoragePickerDialog.OnStoragePickerListener { + override fun onPick(pickedPath: String) { + mBasePath = pickedPath + openPath(pickedPath) + } + }) + } else { + val item = breadcrumbs.getChildAt(id).tag as FileDirItem + openPath(item.path) + } } companion object { - private val STORAGE_PERMISSION = 1 private val BACK_PRESS_TIMEOUT = 5000