mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-03-09 16:10:08 +01:00
implement the Go home and Set home buttons
This commit is contained in:
parent
3247dc5ffb
commit
41d67fe498
@ -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()
|
||||
}
|
||||
|
@ -5,3 +5,4 @@ val SCROLL_STATE = "scroll_state"
|
||||
|
||||
// shared preferences
|
||||
val SHOW_HIDDEN = "show_hidden"
|
||||
val HOME_FOLDER = "home_folder"
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user