mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
convert Config to Kotlin + move Utils
This commit is contained in:
parent
c6779c8047
commit
856913520a
6 changed files with 91 additions and 134 deletions
|
@ -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<String> hiddenFolders = getHiddenFolders();
|
||||
hiddenFolders.add(path);
|
||||
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
|
||||
}
|
||||
|
||||
public void addHiddenDirectories(Set<String> paths) {
|
||||
final Set<String> hiddenFolders = getHiddenFolders();
|
||||
hiddenFolders.addAll(paths);
|
||||
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
|
||||
}
|
||||
|
||||
public void removeHiddenDirectory(String path) {
|
||||
final Set<String> hiddenFolders = getHiddenFolders();
|
||||
hiddenFolders.remove(path);
|
||||
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
|
||||
}
|
||||
|
||||
public void removeHiddenDirectories(Set<String> paths) {
|
||||
final Set<String> hiddenFolders = getHiddenFolders();
|
||||
hiddenFolders.removeAll(paths);
|
||||
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
|
||||
}
|
||||
|
||||
public Set<String> getHiddenFolders() {
|
||||
return mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, new HashSet<String>());
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
86
app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt
Normal file
86
app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt
Normal file
|
@ -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<String>) {
|
||||
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<String>) {
|
||||
val hiddenFolders = hiddenFolders
|
||||
hiddenFolders.removeAll(paths)
|
||||
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply()
|
||||
}
|
||||
|
||||
val hiddenFolders: MutableSet<String>
|
||||
get() = mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, HashSet<String>())
|
||||
|
||||
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()
|
||||
}
|
Loading…
Reference in a new issue