Skip to content

Commit

Permalink
add specific sort order for upload/local/trashbin
Browse files Browse the repository at this point in the history
trashbin: new->old by default

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Oct 30, 2018
1 parent 27ea573 commit 03f4d30
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 101 deletions.
85 changes: 73 additions & 12 deletions src/main/java/com/owncloud/android/db/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
*
* @author David A. Velasco
* Copyright (C) 2016 ownCloud Inc.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ public static boolean isUseFingerprint(Context context) {
*
* @param context Caller {@link Context}, used to access to preferences manager.
* @param folder Folder
* @return preference value, default is
* @return preference value, default is
* {@link com.owncloud.android.ui.fragment.OCFileListFragment#FOLDER_LAYOUT_LIST}
*/
public static String getFolderLayout(Context context, OCFile folder) {
Expand All @@ -257,19 +257,57 @@ public static void setFolderLayout(Context context, OCFile folder, String layout
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return sort order the sort order, default is {@link FileSortOrder#sort_a_to_z} (sort by name)
*/
public static FileSortOrder getSortOrder(Context context, OCFile folder) {
public static FileSortOrder getSortOrderByFolder(Context context, OCFile folder) {
return FileSortOrder.sortOrders.get(getFolderPreference(context, PREF__FOLDER_SORT_ORDER, folder,
FileSortOrder.sort_a_to_z.mName));
FileSortOrder.sort_a_to_z.name));
}

/**
* Set preferred folder sort order.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param sortOrder the sort order
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param sortOrder the sort order
*/
public static void setSortOrder(Context context, OCFile folder, FileSortOrder sortOrder) {
setFolderPreference(context, PREF__FOLDER_SORT_ORDER, folder, sortOrder.mName);
setFolderPreference(context, PREF__FOLDER_SORT_ORDER, folder, sortOrder.name);
}

public static FileSortOrder getSortOrderByType(Context context, FileSortOrder.Type type) {
return getSortOrderByType(context, type, FileSortOrder.sort_a_to_z);
}

/**
* Get preferred folder sort order.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @return sort order the sort order, default is {@link FileSortOrder#sort_a_to_z} (sort by name)
*/
public static FileSortOrder getSortOrderByType(Context context, FileSortOrder.Type type,
FileSortOrder defaultOrder) {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);

if (account == null) {
return defaultOrder;
}

ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());

String value = dataProvider.getValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type);

return value.isEmpty() ? defaultOrder : FileSortOrder.sortOrders.get(value);
}

/**
* Set preferred folder sort order.
*
* @param context Caller {@link Context}, used to access to shared preferences manager.
* @param sortOrder the sort order
*/
public static void setSortOrder(Context context, FileSortOrder.Type type, FileSortOrder sortOrder) {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());

dataProvider.storeOrUpdateKeyValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name);
}

/**
Expand All @@ -289,14 +327,14 @@ public static String getFolderPreference(Context context, String preferenceName,
if (account == null) {
return defaultValue;
}

ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
FileDataStorageManager storageManager = ((ComponentsGetter)context).getStorageManager();

if (storageManager == null) {
storageManager = new FileDataStorageManager(account, context.getContentResolver());
}

String value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, folder));
while (folder != null && value.isEmpty()) {
folder = storageManager.getFileById(folder.getParentId());
Expand All @@ -305,6 +343,29 @@ public static String getFolderPreference(Context context, String preferenceName,
return value.isEmpty() ? defaultValue : value;
}

/**
* Get preference value for a view.
*
* @param context Context object.
* @param preferenceName Name of the preference to lookup.
* @param type view which view
* @param defaultValue Fallback value in case nothing is set.
* @return Preference value
*/
public static String getTypePreference(Context context, String preferenceName, String type, String defaultValue) {
Account account = AccountUtils.getCurrentOwnCloudAccount(context);

if (account == null) {
return defaultValue;
}

ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());

String value = dataProvider.getValue(account.name, preferenceName + "_" + type);

return value.isEmpty() ? defaultValue : value;
}

/**
* Set preference value for a folder.
*
Expand All @@ -322,7 +383,7 @@ public static void setFolderPreference(Context context, String preferenceName, O
private static String getKeyFromFolder(String preferenceName, OCFile folder) {
final String folderIdString = String.valueOf(folder != null ? folder.getFileId() :
FileDataStorageManager.ROOT_PARENT_ID);

return preferenceName + "_" + folderIdString;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@
import java.util.Collection;
import java.util.List;

import static com.owncloud.android.db.PreferenceManager.getSortOrder;

/**
* Displays, what files the user has available in his ownCloud. This is the main view.
*/
Expand Down Expand Up @@ -890,7 +888,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
ft.addToBackStack(null);

SortingOrderDialogFragment mSortingOrderDialogFragment = SortingOrderDialogFragment.newInstance(
getSortOrder(this, getListOfFilesFragment().getCurrentFile()));
PreferenceManager.getSortOrderByFolder(this, getListOfFilesFragment().getCurrentFile()));
mSortingOrderDialogFragment.show(ft, SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT);

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@
import java.util.Stack;
import java.util.Vector;

import static com.owncloud.android.db.PreferenceManager.getSortOrder;


/**
* This can be used to upload things to an ownCloud instance.
*/
Expand Down Expand Up @@ -170,7 +167,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (parentPath != null) {
mParents.addAll(Arrays.asList(parentPath.split("/")));
}

mFile = savedInstanceState.getParcelable(KEY_FILE);
}
mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
Expand Down Expand Up @@ -264,7 +261,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new Builder(getActivity());
builder.setIcon(R.drawable.ic_warning);
builder.setTitle(R.string.uploader_wrn_no_account_title);
builder.setMessage(String.format(getString(R.string.uploader_wrn_no_account_text),
builder.setMessage(String.format(getString(R.string.uploader_wrn_no_account_text),
getString(R.string.app_name)));
builder.setCancelable(false);
builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, (dialog, which) -> {
Expand Down Expand Up @@ -653,7 +650,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
// filter on dirtype
Vector<OCFile> files = new Vector<>();
files.addAll(tmpFiles);

if (files.size() < position) {
throw new IndexOutOfBoundsException("Incorrect item selected");
}
Expand Down Expand Up @@ -800,7 +797,7 @@ private void populateDirectoryList() {
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this)));
}

Button btnNewFolder = findViewById(R.id.uploader_cancel);
btnNewFolder.setOnClickListener(this);

Expand Down Expand Up @@ -857,7 +854,7 @@ private void startSyncFolderOperation(OCFile folder) {
}

private List<OCFile> sortFileList(List<OCFile> files) {
FileSortOrder sortOrder = getSortOrder(this, mFile);
FileSortOrder sortOrder = PreferenceManager.getSortOrderByFolder(this, mFile);
return sortOrder.sortCloudFiles(files);
}

Expand Down Expand Up @@ -1079,7 +1076,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.action_sort:
SortingOrderDialogFragment mSortingOrderDialogFragment = SortingOrderDialogFragment.newInstance(
getSortOrder(this, mFile));
PreferenceManager.getSortOrderByFolder(this, mFile));
mSortingOrderDialogFragment.show(getSupportFragmentManager(),
SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT);
break;
Expand Down
Loading

0 comments on commit 03f4d30

Please sign in to comment.