implement the Go home and Set home buttons

This commit is contained in:
tibbi 2017-03-18 13:58:58 +01:00
parent 3247dc5ffb
commit 41d67fe498
3 changed files with 19 additions and 3 deletions

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.filemanager
import android.content.Context
import com.simplemobiletools.commons.extensions.getInternalStoragePath
import com.simplemobiletools.commons.helpers.BaseConfig
import java.io.File
class Config(context: Context) : BaseConfig(context) {
companion object {
@ -11,4 +13,14 @@ class Config(context: Context) : BaseConfig(context) {
var showHidden: Boolean
get() = prefs.getBoolean(SHOW_HIDDEN, false)
set(show) = prefs.edit().putBoolean(SHOW_HIDDEN, show).apply()
var homeFolder: String
get(): String {
var home = prefs.getString(HOME_FOLDER, "")
if (home.isEmpty() || !File(home).exists() || !File(home).isDirectory) {
home = context.getInternalStoragePath()
}
return home
}
set(homeFolder) = prefs.edit().putString(HOME_FOLDER, homeFolder).apply()
}

View File

@ -5,3 +5,4 @@ val SCROLL_STATE = "scroll_state"
// shared preferences
val SHOW_HIDDEN = "show_hidden"
val HOME_FOLDER = "home_folder"

View File

@ -44,6 +44,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
breadcrumbs.setListener(this)
tryInitFileManager()
storeStoragePaths()
checkWhatsNewDialog()
}
override fun onResume() {
@ -69,7 +70,6 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
private fun tryInitFileManager() {
if (hasWriteStoragePermission()) {
initRootFileManager()
checkWhatsNewDialog()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION)
}
@ -116,13 +116,16 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
}
private fun goHome() {
openPath(config.homeFolder)
}
private fun setAsHome() {
config.homeFolder = getCurrenPath()
toast(R.string.home_folder_updated)
}
private fun getCurrenPath() = (breadcrumbs.getChildAt(breadcrumbs.childCount - 1).tag as FileDirItem).path.trimEnd('/')
private fun launchAbout() {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME)
}