fix #23, allow different sorting for folders and files

This commit is contained in:
tibbi 2016-08-23 20:53:07 +02:00
parent 325e5fe6f3
commit 9612e53dbb
5 changed files with 28 additions and 10 deletions

View file

@ -37,4 +37,12 @@ public class Config {
public void setSorting(int order) { public void setSorting(int order) {
mPrefs.edit().putInt(Constants.SORT_ORDER, order).apply(); 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();
}
} }

View file

@ -12,6 +12,7 @@ public class Constants {
public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_FIRST_RUN = "is_first_run";
public static final String IS_DARK_THEME = "is_dark_theme"; public static final String IS_DARK_THEME = "is_dark_theme";
public static final String SORT_ORDER = "sort_order"; public static final String SORT_ORDER = "sort_order";
public static final String DIRECTORY_SORT_ORDER = "directory_sort_order";
// sorting // sorting
public static final int SORT_BY_NAME = 1; public static final int SORT_BY_NAME = 1;

View file

@ -225,7 +225,7 @@ public class MainActivity extends SimpleActivity
} }
final List<Directory> dirs = new ArrayList<>(directories.values()); final List<Directory> dirs = new ArrayList<>(directories.values());
Directory.mSorting = mConfig.getSorting(); Directory.mSorting = mConfig.getDirectorySorting();
Collections.sort(dirs); Collections.sort(dirs);
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]); 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 // sort the files at querying too, just to get the correct thumbnail
private String getSortOrder() { private String getSortOrder() {
final int sorting = mConfig.getSorting(); final int sorting = mConfig.getDirectorySorting();
String sortBy = MediaStore.Images.Media.DATE_TAKEN; String sortBy = MediaStore.Images.Media.DATE_TAKEN;
if ((sorting & Constants.SORT_BY_NAME) != 0) { if ((sorting & Constants.SORT_BY_NAME) != 0) {
sortBy = MediaStore.Images.Media.DATA; sortBy = MediaStore.Images.Media.DATA;
@ -249,7 +249,7 @@ public class MainActivity extends SimpleActivity
} }
private void showSortingDialog() { private void showSortingDialog() {
new ChangeSorting(this); new ChangeSorting(this, true);
} }
private void prepareForDeleting() { private void prepareForDeleting() {

View file

@ -143,7 +143,7 @@ public class MediaActivity extends SimpleActivity
} }
private void showSortingDialog() { private void showSortingDialog() {
new ChangeSorting(this); new ChangeSorting(this, false);
} }
private void deleteDirectoryIfEmpty() { private void deleteDirectoryIfEmpty() {

View file

@ -15,11 +15,14 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac
private static Config mConfig; private static Config mConfig;
private static ChangeDialogListener mListener; private static ChangeDialogListener mListener;
private static View mHolder; 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()); super(act.getApplicationContext());
mIsDirectorySorting = isDirectorySorting;
mListener = (ChangeDialogListener) act; mListener = (ChangeDialogListener) act;
mConfig = Config.newInstance(getContext()); mConfig = Config.newInstance(getContext());
mHolder = act.getLayoutInflater().inflate(R.layout.change_sorting, null); 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.setTitle(act.getResources().getString(R.string.sort_by));
builder.setView(mHolder); builder.setView(mHolder);
mCurrSorting = mConfig.getSorting(); mCurrSorting = (mIsDirectorySorting ? mConfig.getDirectorySorting() : mConfig.getSorting());
setupSortRadio(); setupSortRadio();
setupOrderRadio(); setupOrderRadio();
@ -78,10 +81,16 @@ public class ChangeSorting extends AlertDialog.Builder implements DialogInterfac
sorting |= Constants.SORT_DESCENDING; sorting |= Constants.SORT_DESCENDING;
} }
if (mConfig.getSorting() != sorting) { if (mIsDirectorySorting) {
mConfig.setSorting(sorting); if (mConfig.getDirectorySorting() != sorting) {
mListener.dialogClosed(); mConfig.setDirectorySorting(sorting);
}
} else {
if (mConfig.getSorting() != sorting) {
mConfig.setSorting(sorting);
}
} }
mListener.dialogClosed();
} }
public interface ChangeDialogListener { public interface ChangeDialogListener {