From 58578ee36d0a85ae93bd70b232affb8873d6bf89 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 13 Nov 2016 17:44:19 +0100 Subject: [PATCH] convert config to kotlin --- .../simplemobiletools/filemanager/Config.java | 48 ------------------- .../simplemobiletools/filemanager/Config.kt | 34 +++++++++++++ .../filemanager/fragments/ItemsFragment.java | 2 +- 3 files changed, 35 insertions(+), 49 deletions(-) delete mode 100644 app/src/main/java/com/simplemobiletools/filemanager/Config.java create mode 100644 app/src/main/java/com/simplemobiletools/filemanager/Config.kt diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Config.java b/app/src/main/java/com/simplemobiletools/filemanager/Config.java deleted file mode 100644 index 927a535b..00000000 --- a/app/src/main/java/com/simplemobiletools/filemanager/Config.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.simplemobiletools.filemanager; - -import android.content.Context; -import android.content.SharedPreferences; - -public class Config { - private SharedPreferences mPrefs; - - public static Config newInstance(Context context) { - return new Config(context); - } - - public Config(Context context) { - mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); - } - - public boolean getIsFirstRun() { - return mPrefs.getBoolean(Constants.IS_FIRST_RUN, true); - } - - public void setIsFirstRun(boolean firstRun) { - mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply(); - } - - public boolean getIsDarkTheme() { - return mPrefs.getBoolean(Constants.IS_DARK_THEME, false); - } - - public void setIsDarkTheme(boolean isDarkTheme) { - mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply(); - } - - public boolean getShowHidden() { - return mPrefs.getBoolean(Constants.SHOW_HIDDEN, false); - } - - public void setShowHidden(boolean show) { - mPrefs.edit().putBoolean(Constants.SHOW_HIDDEN, show).apply(); - } - - public String getTreeUri() { - return mPrefs.getString(Constants.TREE_URI, ""); - } - - public void setTreeUri(String uri) { - mPrefs.edit().putString(Constants.TREE_URI, uri).apply(); - } -} diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Config.kt b/app/src/main/java/com/simplemobiletools/filemanager/Config.kt new file mode 100644 index 00000000..fe400f04 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/Config.kt @@ -0,0 +1,34 @@ +package com.simplemobiletools.filemanager + +import android.content.Context +import android.content.SharedPreferences + +class Config(context: Context) { + private val mPrefs: SharedPreferences + + companion object { + fun newInstance(context: Context): Config { + return Config(context) + } + } + + init { + mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE) + } + + var isFirstRun: Boolean + get() = mPrefs.getBoolean(Constants.IS_FIRST_RUN, true) + set(firstRun) = mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply() + + var isDarkTheme: Boolean + get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, false) + set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply() + + var showHidden: Boolean + get() = mPrefs.getBoolean(Constants.SHOW_HIDDEN, false) + set(show) = mPrefs.edit().putBoolean(Constants.SHOW_HIDDEN, show).apply() + + var treeUri: String + get() = mPrefs.getString(Constants.TREE_URI, "") + set(uri) = mPrefs.edit().putString(Constants.TREE_URI, uri).apply() +} diff --git a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java index d1d79f71..4199026c 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/fragments/ItemsFragment.java @@ -81,7 +81,7 @@ public class ItemsFragment extends android.support.v4.app.Fragment super.onViewCreated(view, savedInstanceState); if (mStates == null) mStates = new HashMap<>(); - mConfig = Config.newInstance(getContext()); + mConfig = Config.Companion.newInstance(getContext()); mShowHidden = mConfig.getShowHidden(); mItems = new ArrayList<>(); mToBeDeleted = new ArrayList<>();