mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	implement the Go home and Set home buttons
This commit is contained in:
		| @@ -1,7 +1,9 @@ | |||||||
| package com.simplemobiletools.filemanager | package com.simplemobiletools.filemanager | ||||||
|  |  | ||||||
| import android.content.Context | import android.content.Context | ||||||
|  | import com.simplemobiletools.commons.extensions.getInternalStoragePath | ||||||
| import com.simplemobiletools.commons.helpers.BaseConfig | import com.simplemobiletools.commons.helpers.BaseConfig | ||||||
|  | import java.io.File | ||||||
|  |  | ||||||
| class Config(context: Context) : BaseConfig(context) { | class Config(context: Context) : BaseConfig(context) { | ||||||
|     companion object { |     companion object { | ||||||
| @@ -11,4 +13,14 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|     var showHidden: Boolean |     var showHidden: Boolean | ||||||
|         get() = prefs.getBoolean(SHOW_HIDDEN, false) |         get() = prefs.getBoolean(SHOW_HIDDEN, false) | ||||||
|         set(show) = prefs.edit().putBoolean(SHOW_HIDDEN, show).apply() |         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 | // shared preferences | ||||||
| val SHOW_HIDDEN = "show_hidden" | val SHOW_HIDDEN = "show_hidden" | ||||||
|  | val HOME_FOLDER = "home_folder" | ||||||
|   | |||||||
| @@ -44,6 +44,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br | |||||||
|         breadcrumbs.setListener(this) |         breadcrumbs.setListener(this) | ||||||
|         tryInitFileManager() |         tryInitFileManager() | ||||||
|         storeStoragePaths() |         storeStoragePaths() | ||||||
|  |         checkWhatsNewDialog() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun onResume() { |     override fun onResume() { | ||||||
| @@ -69,7 +70,6 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br | |||||||
|     private fun tryInitFileManager() { |     private fun tryInitFileManager() { | ||||||
|         if (hasWriteStoragePermission()) { |         if (hasWriteStoragePermission()) { | ||||||
|             initRootFileManager() |             initRootFileManager() | ||||||
|             checkWhatsNewDialog() |  | ||||||
|         } else { |         } else { | ||||||
|             ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION) |             ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION) | ||||||
|         } |         } | ||||||
| @@ -116,13 +116,16 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun goHome() { |     private fun goHome() { | ||||||
|  |         openPath(config.homeFolder) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setAsHome() { |     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() { |     private fun launchAbout() { | ||||||
|         startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME) |         startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT, BuildConfig.VERSION_NAME) | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user