- persist settings for sort order

This commit is contained in:
tobiasKaminsky 2014-10-04 12:23:16 +02:00
parent a622b1dcfb
commit 703187ea09
2 changed files with 30 additions and 21 deletions

View file

@ -24,6 +24,8 @@ import java.util.Vector;
import android.accounts.Account;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -64,9 +66,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
private FileDataStorageManager mStorageManager;
private Account mAccount;
private ComponentsGetter mTransferServiceGetter;
public enum sortOrders { NAME, DATE, SIZE }
private sortOrders sort = sortOrders.NAME;
private boolean sortAscending = true;
private String sortOrder;
private Boolean sortAscending;
private SharedPreferences appPreferences;
public FileListListAdapter(
boolean justFolders,
@ -77,6 +79,15 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
mContext = context;
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
mTransferServiceGetter = transferServiceGetter;
appPreferences = PreferenceManager
.getDefaultSharedPreferences(mContext);
// Read sorting order, default to sort by name ascending
sortOrder = appPreferences
.getString("sortOrder", "name");
sortAscending = appPreferences.getBoolean("sortAscending", true);
}
@Override
@ -306,18 +317,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
* Sorts all filenames, regarding last user decision
*/
private void sortDirectory(){
switch (sort){
case NAME:
if (sortOrder.equals("name")){
sortByName(sortAscending);
break;
case SIZE:
} else if (sortOrder.equals("size")){
sortBySize(sortAscending);
break;
case DATE:
} else if (sortOrder.equals("date")){
sortByDate(sortAscending);
break;
}
notifyDataSetChanged();
@ -441,9 +446,14 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
});
}
public void setSortOrder(sortOrders order, boolean descending) {
sort = order;
sortAscending = descending;
public void setSortOrder(String order, boolean ascending) {
SharedPreferences.Editor editor = appPreferences.edit();
editor.putString("sortOrder", order);
editor.putBoolean("sortAscending", ascending);
editor.commit();
sortOrder = order;
sortAscending = ascending;
sortDirectory();
}

View file

@ -37,7 +37,6 @@ import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.MoveActivity;
import com.owncloud.android.ui.adapter.FileListListAdapter;
import com.owncloud.android.ui.adapter.FileListListAdapter.sortOrders;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
@ -388,14 +387,14 @@ public class OCFileListFragment extends ExtendedListFragment {
}
public void sortByDate(boolean descending){
mAdapter.setSortOrder(sortOrders.DATE, descending);
mAdapter.setSortOrder("date", descending);
}
public void sortBySize(boolean descending){
mAdapter.setSortOrder(sortOrders.SIZE, descending);
mAdapter.setSortOrder("size", descending);
}
public void sortByName(boolean descending){
mAdapter.setSortOrder(sortOrders.NAME, descending);
mAdapter.setSortOrder("name", descending);
}
}