- sort dialog shows the right selected item

This commit is contained in:
tobiasKaminsky 2014-10-04 12:40:35 +02:00
parent 703187ea09
commit be7eb6e932
3 changed files with 30 additions and 22 deletions

View file

@ -154,8 +154,6 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
private OCFile mWaitingToSend;
private Integer sortItemChecked = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
@ -494,12 +492,18 @@ OnSslUntrustedCertListener, SwipeRefreshLayout.OnRefreshListener {
break;
}
case R.id.action_sort: {
SharedPreferences appPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
// Read sorting order, default to sort by name ascending
Integer sortOrder = appPreferences
.getInt("sortOrder", 0);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.actionbar_sort_title)
.setSingleChoiceItems(R.array.actionbar_sortby, sortItemChecked , new DialogInterface.OnClickListener() {
.setSingleChoiceItems(R.array.actionbar_sortby, sortOrder , new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
sortItemChecked = which;
switch (which){
case 0:
sortByName(true);

View file

@ -66,7 +66,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
private FileDataStorageManager mStorageManager;
private Account mAccount;
private ComponentsGetter mTransferServiceGetter;
private String sortOrder;
private Integer sortOrder;
private Boolean sortAscending;
private SharedPreferences appPreferences;
@ -85,7 +85,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
// Read sorting order, default to sort by name ascending
sortOrder = appPreferences
.getString("sortOrder", "name");
.getInt("sortOrder", 0);
sortAscending = appPreferences.getBoolean("sortAscending", true);
}
@ -317,14 +317,18 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
* Sorts all filenames, regarding last user decision
*/
private void sortDirectory(){
if (sortOrder.equals("name")){
sortByName(sortAscending);
} else if (sortOrder.equals("size")){
sortBySize(sortAscending);
} else if (sortOrder.equals("date")){
switch (sortOrder){
case 0:
sortByName(sortAscending);
break;
case 1:
sortByDate(sortAscending);
break;
case 2:
sortBySize(sortAscending);
break;
}
notifyDataSetChanged();
}
@ -446,9 +450,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
});
}
public void setSortOrder(String order, boolean ascending) {
public void setSortOrder(Integer order, boolean ascending) {
SharedPreferences.Editor editor = appPreferences.edit();
editor.putString("sortOrder", order);
editor.putInt("sortOrder", order);
editor.putBoolean("sortAscending", ascending);
editor.commit();

View file

@ -386,15 +386,15 @@ public class OCFileListFragment extends ExtendedListFragment {
}
}
public void sortByName(boolean descending){
mAdapter.setSortOrder(0, descending);
}
public void sortByDate(boolean descending){
mAdapter.setSortOrder("date", descending);
mAdapter.setSortOrder(1, descending);
}
public void sortBySize(boolean descending){
mAdapter.setSortOrder("size", descending);
}
public void sortByName(boolean descending){
mAdapter.setSortOrder("name", descending);
}
mAdapter.setSortOrder(2, descending);
}
}