- 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.accounts.Account;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -64,9 +66,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
private FileDataStorageManager mStorageManager; private FileDataStorageManager mStorageManager;
private Account mAccount; private Account mAccount;
private ComponentsGetter mTransferServiceGetter; private ComponentsGetter mTransferServiceGetter;
public enum sortOrders { NAME, DATE, SIZE } private String sortOrder;
private sortOrders sort = sortOrders.NAME; private Boolean sortAscending;
private boolean sortAscending = true; private SharedPreferences appPreferences;
public FileListListAdapter( public FileListListAdapter(
boolean justFolders, boolean justFolders,
@ -77,6 +79,15 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
mContext = context; mContext = context;
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
mTransferServiceGetter = transferServiceGetter; 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 @Override
@ -306,18 +317,12 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
* Sorts all filenames, regarding last user decision * Sorts all filenames, regarding last user decision
*/ */
private void sortDirectory(){ private void sortDirectory(){
switch (sort){ if (sortOrder.equals("name")){
case NAME: sortByName(sortAscending);
sortByName(sortAscending); } else if (sortOrder.equals("size")){
break;
case SIZE:
sortBySize(sortAscending); sortBySize(sortAscending);
break; } else if (sortOrder.equals("date")){
case DATE:
sortByDate(sortAscending); sortByDate(sortAscending);
break;
} }
notifyDataSetChanged(); notifyDataSetChanged();
@ -441,10 +446,15 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
}); });
} }
public void setSortOrder(sortOrders order, boolean descending) { public void setSortOrder(String order, boolean ascending) {
sort = order; SharedPreferences.Editor editor = appPreferences.edit();
sortAscending = descending; editor.putString("sortOrder", order);
editor.putBoolean("sortAscending", ascending);
editor.commit();
sortOrder = order;
sortAscending = ascending;
sortDirectory(); 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.FileDisplayActivity;
import com.owncloud.android.ui.activity.MoveActivity; import com.owncloud.android.ui.activity.MoveActivity;
import com.owncloud.android.ui.adapter.FileListListAdapter; 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.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
@ -388,14 +387,14 @@ public class OCFileListFragment extends ExtendedListFragment {
} }
public void sortByDate(boolean descending){ public void sortByDate(boolean descending){
mAdapter.setSortOrder(sortOrders.DATE, descending); mAdapter.setSortOrder("date", descending);
} }
public void sortBySize(boolean descending){ public void sortBySize(boolean descending){
mAdapter.setSortOrder(sortOrders.SIZE, descending); mAdapter.setSortOrder("size", descending);
} }
public void sortByName(boolean descending){ public void sortByName(boolean descending){
mAdapter.setSortOrder(sortOrders.NAME, descending); mAdapter.setSortOrder("name", descending);
} }
} }