diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt index db2a618a..1b5137a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/Config.kt @@ -4,6 +4,7 @@ import android.content.Context import com.simplemobiletools.commons.extensions.getInternalStoragePath import com.simplemobiletools.commons.helpers.BaseConfig import java.io.File +import java.util.* class Config(context: Context) : BaseConfig(context) { companion object { @@ -23,4 +24,20 @@ class Config(context: Context) : BaseConfig(context) { return home } set(homeFolder) = prefs.edit().putString(HOME_FOLDER, homeFolder).apply() + + fun addFavorite(path: String) { + val currFavorites = HashSet(favorites) + currFavorites.add(path) + favorites = currFavorites + } + + fun removeFavorite(path: String) { + val currFavorites = HashSet(favorites) + currFavorites.remove(path) + favorites = currFavorites + } + + var favorites: MutableSet + get() = prefs.getStringSet(FAVORITES, HashSet()) + set(favorites) = prefs.edit().remove(FAVORITES).putStringSet(FAVORITES, favorites).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt index c334a6ab..3a35e82b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/Constants.kt @@ -6,3 +6,4 @@ val SCROLL_STATE = "scroll_state" // shared preferences val SHOW_HIDDEN = "show_hidden" val HOME_FOLDER = "home_folder" +val FAVORITES = "favorites" 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 4f91c7d8..1eadb2f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -29,6 +29,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br var latestFragment: ItemsFragment? = null var mScrollStates = HashMap() var mStoredTextColor = 0 + var currentPath = "" companion object { private val STORAGE_PERMISSION = 1 @@ -52,7 +53,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br if (mStoredTextColor != config.textColor) { mStoredTextColor = config.textColor breadcrumbs.setTextColor(mStoredTextColor) - openPath(getCurrenPath()) + openPath(currentPath) } } @@ -96,10 +97,17 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br setListener(this@MainActivity) supportFragmentManager.beginTransaction().replace(R.id.fragment_holder, this).addToBackStack(path).commitAllowingStateLoss() } + currentPath = path + invalidateOptionsMenu() } override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu, menu) + + val favorites = config.favorites + menu.findItem(R.id.add_favorite).isVisible = !favorites.contains(currentPath) + menu.findItem(R.id.remove_favorite).isVisible = favorites.contains(currentPath) + return true } @@ -121,20 +129,20 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br } private fun addFavorite() { - + config.addFavorite(currentPath) + invalidateOptionsMenu() } private fun removeFavorite() { - + config.removeFavorite(currentPath) + invalidateOptionsMenu() } private fun setAsHome() { - config.homeFolder = getCurrenPath() + config.homeFolder = currentPath 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) } @@ -174,7 +182,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br override fun breadcrumbClicked(id: Int) { if (id == 0) { - StoragePickerDialog(this@MainActivity, getCurrenPath()) { + StoragePickerDialog(this@MainActivity, currentPath) { openPath(it) } } else {