mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
fix #23, allow different sorting for folders and files
This commit is contained in:
parent
325e5fe6f3
commit
9612e53dbb
5 changed files with 28 additions and 10 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -225,7 +225,7 @@ public class MainActivity extends SimpleActivity
|
|||
}
|
||||
|
||||
final List<Directory> 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() {
|
||||
|
|
|
@ -143,7 +143,7 @@ public class MediaActivity extends SimpleActivity
|
|||
}
|
||||
|
||||
private void showSortingDialog() {
|
||||
new ChangeSorting(this);
|
||||
new ChangeSorting(this, false);
|
||||
}
|
||||
|
||||
private void deleteDirectoryIfEmpty() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue