diff --git a/app/src/main/java/com/simplemobiletools/gallery/Config.java b/app/src/main/java/com/simplemobiletools/gallery/Config.java deleted file mode 100644 index 19516648f..000000000 --- a/app/src/main/java/com/simplemobiletools/gallery/Config.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.simplemobiletools.gallery; - -import android.content.Context; -import android.content.SharedPreferences; - -import java.util.HashSet; -import java.util.Set; - -public class Config { - private SharedPreferences mPrefs; - - public static Config newInstance(Context context) { - return new Config(context); - } - - private 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, true); - } - - public void setIsDarkTheme(boolean isDarkTheme) { - mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply(); - } - - public boolean getIsSameSorting() { - return mPrefs.getBoolean(Constants.IS_SAME_SORTING, true); - } - - public void setIsSameSorting(boolean isSameSorting) { - mPrefs.edit().putBoolean(Constants.IS_SAME_SORTING, isSameSorting).apply(); - } - - public int getSorting() { - if (getIsSameSorting()) - return getDirectorySorting(); - - return mPrefs.getInt(Constants.SORT_ORDER, Constants.SORT_BY_DATE | Constants.SORT_DESCENDING); - } - - public void setSorting(int order) { - if (getIsSameSorting()) - setDirectorySorting(order); - else - mPrefs.edit().putInt(Constants.SORT_ORDER, order).apply(); - } - - public int getDirectorySorting() { - return mPrefs.getInt(Constants.DIRECTORY_SORT_ORDER, Constants.SORT_BY_DATE | Constants.SORT_DESCENDING); - } - - public void setDirectorySorting(int order) { - mPrefs.edit().putInt(Constants.DIRECTORY_SORT_ORDER, order).apply(); - } - - public boolean getShowHiddenFolders() { - return mPrefs.getBoolean(Constants.SHOW_HIDDEN_FOLDERS, false); - } - - public void setShowHiddenFolders(boolean showHiddenFolders) { - mPrefs.edit().putBoolean(Constants.SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply(); - } - - public void addHiddenDirectory(String path) { - final Set hiddenFolders = getHiddenFolders(); - hiddenFolders.add(path); - mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); - } - - public void addHiddenDirectories(Set paths) { - final Set hiddenFolders = getHiddenFolders(); - hiddenFolders.addAll(paths); - mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); - } - - public void removeHiddenDirectory(String path) { - final Set hiddenFolders = getHiddenFolders(); - hiddenFolders.remove(path); - mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); - } - - public void removeHiddenDirectories(Set paths) { - final Set hiddenFolders = getHiddenFolders(); - hiddenFolders.removeAll(paths); - mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); - } - - public Set getHiddenFolders() { - return mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, new HashSet()); - } - - public boolean getIsFolderHidden(String path) { - return getHiddenFolders().contains(path); - } - - public boolean getAutoplayVideos() { - return mPrefs.getBoolean(Constants.AUTOPLAY_VIDEOS, false); - } - - public void setAutoplayVideos(boolean autoplay) { - mPrefs.edit().putBoolean(Constants.AUTOPLAY_VIDEOS, autoplay).apply(); - } - - public String getTreeUri() { - return mPrefs.getString(Constants.TREE_URI, ""); - } - - public void setTreeUri(String uri) { - mPrefs.edit().putString(Constants.TREE_URI, uri).apply(); - } - - public boolean getDisplayFileNames() { - return mPrefs.getBoolean(Constants.DISPLAY_FILE_NAMES, false); - } - - public void setDisplayFileNames(boolean display) { - mPrefs.edit().putBoolean(Constants.DISPLAY_FILE_NAMES, display).apply(); - } -} diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 4e4e14100..43bf8dbcc 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -145,7 +145,7 @@ public class MainActivity extends SimpleActivity @Override protected void onDestroy() { super.onDestroy(); - mConfig.setIsFirstRun(false); + mConfig.setFirstRun(false); } private void tryloadGallery() { @@ -338,7 +338,7 @@ public class MainActivity extends SimpleActivity getDirectories(); msgId = copiedAll ? R.string.moving_success : R.string.moving_success_partial; } else { - msgId = copiedAll? R.string.copying_success : R.string.copying_success_partial; + msgId = copiedAll ? R.string.copying_success : R.string.copying_success_partial; } Utils.Companion.showToast(getApplicationContext(), msgId); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java b/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java index 4fce26755..83cf701b8 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java +++ b/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java @@ -24,7 +24,7 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac mIsDirectorySorting = isDirectorySorting; mListener = (ChangeDialogListener) act; - mConfig = Config.newInstance(getContext()); + mConfig = Config.Companion.newInstance(getContext()); mHolder = act.getLayoutInflater().inflate(R.layout.change_sorting, null); final AlertDialog.Builder builder = new AlertDialog.Builder(act); diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java index 106bb845f..55dd03646 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/VideoFragment.java @@ -94,7 +94,7 @@ public class VideoFragment extends ViewPagerFragment super.setMenuVisibility(menuVisible); mIsFragmentVisible = menuVisible; if (menuVisible) { - if (getContext() != null && Config.newInstance(getContext()).getAutoplayVideos()) { + if (getContext() != null && Config.Companion.newInstance(getContext()).getAutoplayVideos()) { playVideo(); } } @@ -409,7 +409,7 @@ public class VideoFragment extends ViewPagerFragment setupTimeHolder(); setProgress(mCurrTime); - if (mIsFragmentVisible && Config.newInstance(getContext()).getAutoplayVideos()) + if (mIsFragmentVisible && Config.Companion.newInstance(getContext()).getAutoplayVideos()) playVideo(); } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt new file mode 100644 index 000000000..7d61b04ab --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt @@ -0,0 +1,86 @@ +package com.simplemobiletools.gallery + +import android.content.Context +import android.content.SharedPreferences +import java.util.* + +class Config private constructor(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(isFirstRun) = mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, isFirstRun).apply() + + var isDarkTheme: Boolean + get() = mPrefs.getBoolean(Constants.IS_DARK_THEME, true) + set(isDarkTheme) = mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply() + + var isSameSorting: Boolean + get() = mPrefs.getBoolean(Constants.IS_SAME_SORTING, true) + set(isSameSorting) = mPrefs.edit().putBoolean(Constants.IS_SAME_SORTING, isSameSorting).apply() + + var sorting: Int + get() = if (isSameSorting) directorySorting else mPrefs.getInt(Constants.SORT_ORDER, Constants.SORT_BY_DATE or Constants.SORT_DESCENDING) + set(order) = if (isSameSorting) directorySorting = order else mPrefs.edit().putInt(Constants.SORT_ORDER, order).apply() + + var directorySorting: Int + get() = mPrefs.getInt(Constants.DIRECTORY_SORT_ORDER, Constants.SORT_BY_DATE or Constants.SORT_DESCENDING) + set(order) = mPrefs.edit().putInt(Constants.DIRECTORY_SORT_ORDER, order).apply() + + var showHiddenFolders: Boolean + get() = mPrefs.getBoolean(Constants.SHOW_HIDDEN_FOLDERS, false) + set(showHiddenFolders) = mPrefs.edit().putBoolean(Constants.SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply() + + fun addHiddenDirectory(path: String) { + val hiddenFolders = hiddenFolders + hiddenFolders.add(path) + mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply() + } + + fun addHiddenDirectories(paths: Set) { + val hiddenFolders = hiddenFolders + hiddenFolders.addAll(paths) + mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply() + } + + fun removeHiddenDirectory(path: String) { + val hiddenFolders = hiddenFolders + hiddenFolders.remove(path) + mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply() + } + + fun removeHiddenDirectories(paths: Set) { + val hiddenFolders = hiddenFolders + hiddenFolders.removeAll(paths) + mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply() + } + + val hiddenFolders: MutableSet + get() = mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, HashSet()) + + fun getIsFolderHidden(path: String): Boolean { + return hiddenFolders.contains(path) + } + + var autoplayVideos: Boolean + get() = mPrefs.getBoolean(Constants.AUTOPLAY_VIDEOS, false) + set(autoplay) = mPrefs.edit().putBoolean(Constants.AUTOPLAY_VIDEOS, autoplay).apply() + + var treeUri: String + get() = mPrefs.getString(Constants.TREE_URI, "") + set(uri) = mPrefs.edit().putString(Constants.TREE_URI, uri).apply() + + var displayFileNames: Boolean + get() = mPrefs.getBoolean(Constants.DISPLAY_FILE_NAMES, false) + set(display) = mPrefs.edit().putBoolean(Constants.DISPLAY_FILE_NAMES, display).apply() +} diff --git a/app/src/main/java/com/simplemobiletools/gallery/Utils.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt similarity index 100% rename from app/src/main/java/com/simplemobiletools/gallery/Utils.kt rename to app/src/main/kotlin/com/simplemobiletools/gallery/Utils.kt