diff --git a/app/src/main/java/com/simplemobiletools/gallery/Config.java b/app/src/main/java/com/simplemobiletools/gallery/Config.java index 9d7e98bda..9218d6b0e 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Config.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Config.java @@ -37,4 +37,12 @@ public class Config { public void setSorting(int order) { mPrefs.edit().putInt(Constants.SORT_ORDER, order).apply(); } + + public int getDirectorySorting() { + return mPrefs.getInt(Constants.DIRECTORY_SORT_ORDER, Constants.SORT_BY_NAME); + } + + public void setDirectorySorting(int order) { + mPrefs.edit().putInt(Constants.DIRECTORY_SORT_ORDER, order).apply(); + } } diff --git a/app/src/main/java/com/simplemobiletools/gallery/Constants.java b/app/src/main/java/com/simplemobiletools/gallery/Constants.java index 0b572fcc4..c5a083303 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Constants.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Constants.java @@ -12,6 +12,7 @@ public class Constants { public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_DARK_THEME = "is_dark_theme"; public static final String SORT_ORDER = "sort_order"; + public static final String DIRECTORY_SORT_ORDER = "directory_sort_order"; // sorting public static final int SORT_BY_NAME = 1; 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 62f2bed54..d244ba68d 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -225,7 +225,7 @@ public class MainActivity extends SimpleActivity } final List dirs = new ArrayList<>(directories.values()); - Directory.mSorting = mConfig.getSorting(); + Directory.mSorting = mConfig.getDirectorySorting(); Collections.sort(dirs); final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]); @@ -236,7 +236,7 @@ public class MainActivity extends SimpleActivity // sort the files at querying too, just to get the correct thumbnail private String getSortOrder() { - final int sorting = mConfig.getSorting(); + final int sorting = mConfig.getDirectorySorting(); String sortBy = MediaStore.Images.Media.DATE_TAKEN; if ((sorting & Constants.SORT_BY_NAME) != 0) { sortBy = MediaStore.Images.Media.DATA; @@ -249,7 +249,7 @@ public class MainActivity extends SimpleActivity } private void showSortingDialog() { - new ChangeSorting(this); + new ChangeSorting(this, true); } private void prepareForDeleting() { diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index 8dc26b271..bd507f2f5 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -143,7 +143,7 @@ public class MediaActivity extends SimpleActivity } private void showSortingDialog() { - new ChangeSorting(this); + new ChangeSorting(this, false); } private void deleteDirectoryIfEmpty() { 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 5bf4cdfd0..6312a1077 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java +++ b/app/src/main/java/com/simplemobiletools/gallery/dialogs/ChangeSorting.java @@ -15,11 +15,14 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac private static Config mConfig; private static ChangeDialogListener mListener; private static View mHolder; - private static int mCurrSorting; - public ChangeSorting(Activity act) { + private static int mCurrSorting; + private static boolean mIsDirectorySorting; + + public ChangeSorting(Activity act, boolean isDirectorySorting) { super(act.getApplicationContext()); + mIsDirectorySorting = isDirectorySorting; mListener = (ChangeDialogListener) act; mConfig = Config.newInstance(getContext()); mHolder = act.getLayoutInflater().inflate(R.layout.change_sorting, null); @@ -28,7 +31,7 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac builder.setTitle(act.getResources().getString(R.string.sort_by)); builder.setView(mHolder); - mCurrSorting = mConfig.getSorting(); + mCurrSorting = (mIsDirectorySorting ? mConfig.getDirectorySorting() : mConfig.getSorting()); setupSortRadio(); setupOrderRadio(); @@ -78,10 +81,16 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac sorting |= Constants.SORT_DESCENDING; } - if (mConfig.getSorting() != sorting) { - mConfig.setSorting(sorting); - mListener.dialogClosed(); + if (mIsDirectorySorting) { + if (mConfig.getDirectorySorting() != sorting) { + mConfig.setDirectorySorting(sorting); + } + } else { + if (mConfig.getSorting() != sorting) { + mConfig.setSorting(sorting); + } } + mListener.dialogClosed(); } public interface ChangeDialogListener {