From: tobiasKaminsky Date: Thu, 29 Oct 2015 17:41:52 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/sortInUploadFilesActivity' into beta X-Git-Tag: beta-20151122~83 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c7a3b092ceb08ad2f74d66d660cf82244c328311?hp=-c Merge remote-tracking branch 'remotes/upstream/sortInUploadFilesActivity' into beta --- c7a3b092ceb08ad2f74d66d660cf82244c328311 diff --combined CHANGELOG.md index cc2f6a65,308e8a7d..79e012b8 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@@ -1,14 -1,31 +1,15 @@@ - -## 1.7.1 (April 2015) - -- Share link even with password enforced by server -- Get the app ready for oc 8.1 servers -- Added option to create new folder in uploads from external apps -- Improved management of deleted users -- Bugs fixed - + Fixed crash on Android 2.x devices - + Improvements on uploads - -## 1.7.0 (February 2015) - -- Download full folders -- Grid view for images -- Remote thumbnails (OC Server 8.0+) -- Added number of files and folders at the end of the list -- "Open with" in contextual menu -- Downloads added to Media Provider -- Uploads: - + Local thumbnails in section "Files" - + Multiple selection in "Content from other apps" (Android 4.3+) -- Gallery: - + proper handling of EXIF - + obey sorting in the list of files -- Settings view updated -- Improved subjects in e-mails -- Bugs fixed - - - +# 2015-10-29 +- PR [#1099](https://github.com/owncloud/android/pull/1099) "Switch list vs grid" merged +- PR [#1100](https://github.com/owncloud/android/pull/1100) "Material FAB with speed dial implementation" merged +- PR [#1209](https://github.com/owncloud/android/pull/1209) "Material buttons - before in #1090" merged +- PR [#1205](https://github.com/owncloud/android/pull/1205) "Switch between online and offline files" merged +- PR [#1195](https://github.com/owncloud/android/pull/1195) "Resize Cache" merged +- PR [#1187](https://github.com/owncloud/android/pull/1187) "Video: Big thumbnails" merged ++- PR [#1058](https://github.com/owncloud/android/pull/1058) "add sort to UploadFileActiviy" merged + + +# 2015-10-26 +- start of branch +- PR [#745](https://github.com/owncloud/android/pull/745) merged +- PR [#1044](https://github.com/owncloud/android/pull/1044) merged: < 8.1: GalleryPlus app needed, >= 8.2 Gallery app needed +- PR [#1111](https://github.com/owncloud/android/pull/1111) merged diff --combined src/com/owncloud/android/ui/activity/UploadFilesActivity.java index 9a3ce178,fa5c9cdb..9341dd06 --- a/src/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadFilesActivity.java @@@ -20,13 -20,21 +20,19 @@@ package com.owncloud.android.ui.activity; -import java.io.File; - import android.accounts.Account; + import android.app.AlertDialog; + import android.content.DialogInterface; import android.content.Intent; + import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; + import android.preference.PreferenceManager; import android.support.v4.app.DialogFragment; import android.support.v7.app.ActionBar; + import android.view.Menu; + import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@@ -38,13 -46,12 +44,13 @@@ import android.widget.TextView import com.owncloud.android.R; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; -import com.owncloud.android.ui.dialog.IndeterminateProgressDialog; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; +import com.owncloud.android.ui.dialog.IndeterminateProgressDialog; import com.owncloud.android.ui.fragment.LocalFileListFragment; -import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; +import java.io.File; + /** * Displays local files and let the user choose what of them wants to upload @@@ -116,6 -123,7 +122,6 @@@ public class UploadFilesActivity extend // Action bar setup ActionBar actionBar = getSupportActionBar(); - actionBar.setIcon(DisplayUtils.getSeasonalIconId()); actionBar.setHomeButtonEnabled(true); // mandatory since Android ICS, according to the // official documentation actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null); @@@ -132,6 -140,13 +138,13 @@@ Log_OC.d(TAG, "onCreate() end"); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.uploader_menu, menu); + return true; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { @@@ -143,6 -158,34 +156,34 @@@ } break; } + case R.id.action_sort: { + SharedPreferences appPreferences = PreferenceManager + .getDefaultSharedPreferences(this); + + // Read sorting order, default to sort by name ascending + Integer sortOrder = appPreferences + .getInt("sortOrder", FileStorageUtils.SORT_NAME); + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.actionbar_sort_title) + .setSingleChoiceItems(R.array.actionbar_sortby, sortOrder , + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + switch (which){ + case 0: + mFileListFragment.sortByName(true); + break; + case 1: + mFileListFragment.sortByDate(false); + break; + } + + dialog.dismiss(); + } + }); + builder.create().show(); + break; + } default: retval = super.onOptionsItemSelected(item); } diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 900d186c,b48f9d4e..ab596c96 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -4,7 -4,6 +4,7 @@@ * @author Bartek Przybylski * @author Tobias Kaminsky * @author David A. Velasco + * @author masensio * Copyright (C) 2011 Bartek Przybylski * Copyright (C) 2015 ownCloud Inc. * @@@ -55,7 -54,6 +55,7 @@@ import com.owncloud.android.services.Op import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.MimetypeIconUtil; /** @@@ -154,7 -152,7 +154,7 @@@ public class FileListListAdapter extend ViewType viewType; if (!mGridMode){ viewType = ViewType.LIST_ITEM; - } else if (file.isImage()){ + } else if (file.isImage() || file.isVideo()){ viewType = ViewType.GRID_IMAGE; } else { viewType = ViewType.GRID_ITEM; @@@ -194,7 -192,6 +194,7 @@@ switch (viewType){ case LIST_ITEM: TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); TextView lastModV = (TextView) view.findViewById(R.id.last_mod); ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); @@@ -203,7 -200,6 +203,7 @@@ checkBoxV.setVisibility(View.GONE); + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); @@@ -215,17 -211,16 +215,17 @@@ } else { if (parentList.isItemChecked(position)) { checkBoxV.setImageResource( - android.R.drawable.checkbox_on_background); + R.drawable.ic_checkbox_marked); } else { checkBoxV.setImageResource( - android.R.drawable.checkbox_off_background); + R.drawable.ic_checkbox_blank_outline); } checkBoxV.setVisibility(View.VISIBLE); } } } else { //Folder + fileSizeSeparatorV.setVisibility(View.INVISIBLE); fileSizeV.setVisibility(View.INVISIBLE); } @@@ -273,14 -268,15 +273,14 @@@ } // share with me icon - if (!file.isFolder()) { - ImageView sharedWithMeIconV = (ImageView) - view.findViewById(R.id.sharedWithMeIcon); - sharedWithMeIconV.bringToFront(); - if (checkIfFileIsSharedWithMe(file)) { - sharedWithMeIconV.setVisibility(View.VISIBLE); - } else { - sharedWithMeIconV.setVisibility(View.GONE); - } + ImageView sharedWithMeIconV = (ImageView) + view.findViewById(R.id.sharedWithMeIcon); + sharedWithMeIconV.bringToFront(); + if (checkIfFileIsSharedWithMe(file) && + (!file.isFolder() || !mGridMode)) { + sharedWithMeIconV.setVisibility(View.VISIBLE); + } else { + sharedWithMeIconV.setVisibility(View.GONE); } break; @@@ -290,7 -286,7 +290,7 @@@ // this if-else is needed even though favorite icon is visible by default // because android reuses views in listview - if (!file.keepInSync()) { + if (!file.isFavorite()) { view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE); } else { view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE); @@@ -322,26 -318,27 +322,26 @@@ task ); fileIcon.setImageDrawable(asyncDrawable); - task.execute(file); + task.execute(file, true); } } + + if (file.getMimetype().equalsIgnoreCase("image/png")) { + fileIcon.setBackgroundColor(mContext.getResources() + .getColor(R.color.background_color)); + } + + } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(file.getMimetype(), file.getFileName())); } } else { // Folder - if (checkIfFileIsSharedWithMe(file)) { - fileIcon.setImageResource(R.drawable.shared_with_me_folder); - } else if (file.isShareByLink()) { - // If folder is sharedByLink, icon folder must be changed to - // folder-public one - fileIcon.setImageResource(R.drawable.folder_public); - } else { - fileIcon.setImageResource( - DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()) - ); - } + fileIcon.setImageResource( + MimetypeIconUtil.getFolderTypeIconId( + checkIfFileIsSharedWithMe(file), file.isShareByLink())); } } @@@ -411,14 -408,15 +411,14 @@@ * mStorageManager if is different (and not NULL) */ public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager - /*, boolean onlyOnDevice*/) { + , boolean onlyOnDevice) { mFile = directory; if (updatedStorageManager != null && updatedStorageManager != mStorageManager) { mStorageManager = updatedStorageManager; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } if (mStorageManager != null) { - // TODO Enable when "On Device" is recovered ? - mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/); + mFiles = mStorageManager.getFolderContent(mFile, onlyOnDevice); mFilesOrig.clear(); mFilesOrig.addAll(mFiles); @@@ -429,7 -427,7 +429,7 @@@ mFiles = null; } - mFiles = FileStorageUtils.sortFolder(mFiles); + mFiles = FileStorageUtils.sortOcFolder(mFiles); notifyDataSetChanged(); } @@@ -476,7 -474,7 +476,7 @@@ FileStorageUtils.mSortAscending = ascending; - mFiles = FileStorageUtils.sortFolder(mFiles); + mFiles = FileStorageUtils.sortOcFolder(mFiles); notifyDataSetChanged(); } @@@ -489,8 -487,4 +489,8 @@@ public void setGridMode(boolean gridMode) { mGridMode = gridMode; } + + public boolean isGridMode() { + return mGridMode; + } } diff --combined src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index a6839e55,a5f11cea..af3bdf0a --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@@ -25,7 -25,9 +25,9 @@@ import java.util.Arrays import java.util.Comparator; import android.content.Context; + import android.content.SharedPreferences; import android.graphics.Bitmap; + import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@@ -37,25 -39,31 +39,35 @@@ import android.widget.TextView import com.owncloud.android.R; import com.owncloud.android.datamodel.ThumbnailsCacheManager; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.MimetypeIconUtil; + import com.owncloud.android.utils.FileStorageUtils; /** * This Adapter populates a ListView with all files and directories contained * in a local directory */ public class LocalFileListAdapter extends BaseAdapter implements ListAdapter { - + + private static final String TAG = LocalFileListAdapter.class.getSimpleName(); + private Context mContext; private File mDirectory; private File[] mFiles = null; + private SharedPreferences mAppPreferences; public LocalFileListAdapter(File directory, Context context) { mContext = context; + + mAppPreferences = PreferenceManager + .getDefaultSharedPreferences(mContext); + + // Read sorting order, default to sort by name ascending + FileStorageUtils.mSortOrder = mAppPreferences.getInt("sortOrder", 0); + FileStorageUtils.mSortAscending = mAppPreferences.getBoolean("sortAscending", true); + swapDirectory(directory); } @@@ -107,12 -115,6 +119,12 @@@ fileName.setText(name); ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail); + + /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or + * {@link ThumbnailsCacheManager#cancelPotentialWork} will NEVER cancel any task. + **/ + boolean allowedToCreateNewThumbnail = (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)); + if (!file.isDirectory()) { fileIcon.setImageResource(R.drawable.file); } else { @@@ -121,11 -123,9 +133,11 @@@ fileIcon.setTag(file.hashCode()); TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); TextView lastModV = (TextView) view.findViewById(R.id.last_mod); ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); if (!file.isDirectory()) { + fileSizeSeparatorV.setVisibility(View.VISIBLE); fileSizeV.setVisibility(View.VISIBLE); fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.length())); @@@ -136,9 -136,9 +148,9 @@@ checkBoxV.setVisibility(View.GONE); } else { if (parentList.isItemChecked(position)) { - checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_marked); } else { - checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline); } checkBoxV.setVisibility(View.VISIBLE); } @@@ -154,7 -154,7 +166,7 @@@ } else { // generate new Thumbnail - if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) { + if (allowedToCreateNewThumbnail) { final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon); if (thumbnail == null) { @@@ -168,16 -168,13 +180,16 @@@ ); fileIcon.setImageDrawable(asyncDrawable); task.execute(file); - } + Log_OC.v(TAG, "Executing task to generate a new thumbnail"); + + } // else, already being generated, don't restart it } } else { - fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(null, file.getName())); + fileIcon.setImageResource(MimetypeIconUtil.getFileTypeIconId(null, file.getName())); } } else { + fileSizeSeparatorV.setVisibility(View.GONE); fileSizeV.setVisibility(View.GONE); lastModV.setVisibility(View.GONE); checkBoxV.setVisibility(View.GONE); @@@ -233,7 -230,23 +245,23 @@@ } }); + + mFiles = FileStorageUtils.sortLocalFolder(mFiles); } notifyDataSetChanged(); } + + public void setSortOrder(Integer order, boolean ascending) { + SharedPreferences.Editor editor = mAppPreferences.edit(); + editor.putInt("sortOrder", order); + editor.putBoolean("sortAscending", ascending); + editor.commit(); + + FileStorageUtils.mSortOrder = order; + FileStorageUtils.mSortAscending = ascending; + + mFiles = FileStorageUtils.sortLocalFolder(mFiles); + notifyDataSetChanged(); + + } } diff --combined src/com/owncloud/android/ui/fragment/LocalFileListFragment.java index 5441aead,5d9a7fbc..c5f74a78 --- a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@@ -37,6 -37,7 +37,7 @@@ import android.widget.ListView import com.owncloud.android.R; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.adapter.LocalFileListAdapter; + import com.owncloud.android.utils.FileStorageUtils; /** @@@ -54,6 -55,7 +55,6 @@@ public class LocalFileListFragment exte /** Adapter to connect the data from the directory with the View object */ private LocalFileListAdapter mAdapter = null; - /** * {@inheritDoc} */ @@@ -78,7 -80,6 +79,7 @@@ View v = super.onCreateView(inflater, container, savedInstanceState); setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); setSwipeEnabled(false); // Disable pull-to-refresh + setFabEnabled(false); // Disable FAB setMessageForEmptyList(getString(R.string.local_file_list_empty)); Log_OC.i(TAG, "onCreateView() end"); return v; @@@ -120,9 -121,9 +121,9 @@@ ImageView checkBoxV = (ImageView) v.findViewById(R.id.custom_checkbox); if (checkBoxV != null) { if (((ListView)getListView()).isItemChecked(position)) { - checkBoxV.setImageResource(android.R.drawable.checkbox_on_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_marked); } else { - checkBoxV.setImageResource(android.R.drawable.checkbox_off_background); + checkBoxV.setImageResource(R.drawable.ic_checkbox_blank_outline); } } // notify the change to the container Activity @@@ -228,7 -229,19 +229,19 @@@ return result.toArray(new String[result.size()]); } - + public void sortByName(boolean descending) { + mAdapter.setSortOrder(FileStorageUtils.SORT_NAME, descending); + } + + public void sortByDate(boolean descending) { + mAdapter.setSortOrder(FileStorageUtils.SORT_DATE, descending); + } + + public void sortBySize(boolean descending) { + mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending); + } + + /** * Interface to implement by any Activity that includes some instance of LocalFileListFragment */ diff --combined src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index f10f5b34,caff31cc..42cbf09a --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@@ -27,7 -27,6 +27,7 @@@ import java.util.Set import java.util.Vector; import android.accounts.Account; +import android.graphics.Bitmap; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; @@@ -35,8 -34,6 +35,8 @@@ import android.view.ViewGroup import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.datamodel.ThumbnailsCacheManager; +import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.utils.FileStorageUtils; @@@ -64,8 -61,8 +64,8 @@@ public class PreviewImagePagerAdapter e * @param storageManager Bridge to database. */ public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, - Account account, FileDataStorageManager storageManager /*, - boolean onlyOnDevice*/) { + Account account, FileDataStorageManager storageManager, + boolean onlyOnDevice) { super(fragmentManager); if (fragmentManager == null) { @@@ -80,9 -77,10 +80,9 @@@ mAccount = account; mStorageManager = storageManager; - // TODO Enable when "On Device" is recovered ? - mImageFiles = mStorageManager.getFolderImages(parentFolder/*, false*/); + mImageFiles = mStorageManager.getFolderImages(parentFolder, false); - mImageFiles = FileStorageUtils.sortFolder(mImageFiles); + mImageFiles = FileStorageUtils.sortOcFolder(mImageFiles); mObsoleteFragments = new HashSet(); mObsoletePositions = new HashSet(); @@@ -106,15 -104,17 +106,15 @@@ Fragment fragment = null; if (file.isDown()) { fragment = PreviewImageFragment.newInstance(file, - mObsoletePositions.contains(Integer.valueOf(i))); + mObsoletePositions.contains(Integer.valueOf(i)), false); } else if (mDownloadErrors.contains(Integer.valueOf(i))) { fragment = FileDownloadFragment.newInstance(file, mAccount, true); ((FileDownloadFragment)fragment).setError(true); mDownloadErrors.remove(Integer.valueOf(i)); - } else { - fragment = FileDownloadFragment.newInstance( - file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)) - ); + fragment = PreviewImageFragment.newInstance(file, + mObsoletePositions.contains(Integer.valueOf(i)), true); } mObsoletePositions.remove(Integer.valueOf(i)); return fragment; diff --combined src/com/owncloud/android/utils/FileStorageUtils.java index 39837717,3f854b86..757f896c --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@@ -21,8 -21,11 +21,11 @@@ package com.owncloud.android.utils; import java.io.File; + import java.util.ArrayList; + import java.util.Arrays; import java.util.Collections; import java.util.Comparator; + import java.util.List; import java.util.Vector; import third_parties.daveKoeller.AlphanumComparator; @@@ -46,12 -49,12 +49,12 @@@ import android.webkit.MimeTypeMap * Static methods to help in access to local file system. */ public class FileStorageUtils { - public static Integer mSortOrder; - public static Boolean mSortAscending; public static final Integer SORT_NAME = 0; public static final Integer SORT_DATE = 1; public static final Integer SORT_SIZE = 2; - + public static Integer mSortOrder = SORT_NAME; + public static Boolean mSortAscending = true; + //private static final String LOG_TAG = "FileStorageUtils"; @@@ -155,13 -158,13 +158,13 @@@ /** * Sorts all filenames, regarding last user decision */ - public static Vector sortFolder(Vector files){ + public static Vector sortOcFolder(Vector files){ switch (mSortOrder){ case 0: - files = FileStorageUtils.sortByName(files); + files = FileStorageUtils.sortOCFilesByName(files); break; case 1: - files = FileStorageUtils.sortByDate(files); + files = FileStorageUtils.sortOCFilesByDate(files); break; case 2: // mFiles = FileStorageUtils.sortBySize(mSortAscending); @@@ -170,12 -173,31 +173,31 @@@ return files; } + + /** + * Sorts all filenames, regarding last user decision + */ + public static File[] sortLocalFolder(File[] files){ + switch (mSortOrder){ + case 0: + files = FileStorageUtils.sortLocalFilesByName(files); + break; + case 1: + files = FileStorageUtils.sortLocalFilesByDate(files); + break; + case 2: + // mFiles = FileStorageUtils.sortBySize(mSortAscending); + break; + } + + return files; + } /** * Sorts list by Date * @param files */ - public static Vector sortByDate(Vector files){ + public static Vector sortOCFilesByDate(Vector files){ final Integer val; if (mSortAscending){ val = 1; @@@ -205,6 -227,43 +227,43 @@@ return files; } + /** + * Sorts list by Date + * @param filesArray + */ + public static File[] sortLocalFilesByDate(File[] filesArray){ + final Integer val; + if (mSortAscending){ + val = 1; + } else { + val = -1; + } + + List files = new ArrayList(Arrays.asList(filesArray)); + + Collections.sort(files, new Comparator() { + public int compare(File o1, File o2) { + if (o1.isDirectory() && o2.isDirectory()) { + Long obj1 = o1.lastModified(); + return val * obj1.compareTo(o2.lastModified()); + } + else if (o1.isDirectory()) { + return -1; + } else if (o2.isDirectory()) { + return 1; + } else if (o1.lastModified() == 0 || o2.lastModified() == 0){ + return 0; + } else { + Long obj1 = o1.lastModified(); + return val * obj1.compareTo(o2.lastModified()); + } + } + }); + + File[] returnArray = new File[1]; + return files.toArray(returnArray); + } + // /** // * Sorts list by Size // * @param sortAscending true: ascending, false: descending @@@ -243,7 -302,7 +302,7 @@@ * Sorts list by Name * @param files files to sort */ - public static Vector sortByName(Vector files){ + public static Vector sortOCFilesByName(Vector files){ final Integer val; if (mSortAscending){ val = 1; @@@ -254,7 -313,7 +313,7 @@@ Collections.sort(files, new Comparator() { public int compare(OCFile o1, OCFile o2) { if (o1.isFolder() && o2.isFolder()) { - return val * o1.getRemotePath().toLowerCase().compareTo(o2.getRemotePath().toLowerCase()); + return val * new AlphanumComparator().compare(o1, o2); } else if (o1.isFolder()) { return -1; } else if (o2.isFolder()) { @@@ -266,6 -325,38 +325,38 @@@ return files; } + + /** + * Sorts list by Name + * @param filesArray files to sort + */ + public static File[] sortLocalFilesByName(File[] filesArray){ + final Integer val; + if (mSortAscending){ + val = 1; + } else { + val = -1; + } + + List files = new ArrayList(Arrays.asList(filesArray)); + + Collections.sort(files, new Comparator() { + public int compare(File o1, File o2) { + if (o1.isDirectory() && o2.isDirectory()) { + return val * o1.getPath().toLowerCase().compareTo(o2.getPath().toLowerCase()); + } else if (o1.isDirectory()) { + return -1; + } else if (o2.isDirectory()) { + return 1; + } + return val * new AlphanumComparator().compare(o1.getPath().toLowerCase(), + o2.getPath().toLowerCase()); + } + }); + + File[] returnArray = new File[1]; + return files.toArray(returnArray); + } /** * Local Folder size diff --combined src/third_parties/daveKoeller/AlphanumComparator.java index 47cf1437,d0879576..03244930 --- a/src/third_parties/daveKoeller/AlphanumComparator.java +++ b/src/third_parties/daveKoeller/AlphanumComparator.java @@@ -23,7 -23,7 +23,8 @@@ */ package third_parties.daveKoeller; +import java.text.Collator; + import java.io.File; import java.util.Comparator; import com.owncloud.android.datamodel.OCFile; @@@ -49,12 -49,14 +50,12 @@@ public class AlphanumComparator impleme } /** Length of string is passed in for improved efficiency (only need to calculate it once) **/ - private final String getChunk(String s, int slength, int marker) - { + private final String getChunk(String s, int slength, int marker){ StringBuilder chunk = new StringBuilder(); char c = s.charAt(marker); chunk.append(c); marker++; - if (isDigit(c)) - { + if (isDigit(c)){ while (marker < slength) { c = s.charAt(marker); @@@ -63,7 -65,8 +64,7 @@@ chunk.append(c); marker++; } - } else - { + } else { while (marker < slength) { c = s.charAt(marker); @@@ -77,15 -80,27 +78,26 @@@ } public int compare(OCFile o1, OCFile o2){ - String s1 = (String)o1.getRemotePath().toLowerCase(); - String s2 = (String)o2.getRemotePath().toLowerCase(); + String s1 = o1.getRemotePath().toLowerCase(); + String s2 = o2.getRemotePath().toLowerCase(); + return compare(s1, s2); + } + + public int compare(File f1, File f2){ + String s1 = f1.getPath().toLowerCase(); + String s2 = f2.getPath().toLowerCase(); + + return compare(s1, s2); + } + + public int compare(String s1, String s2) { int thisMarker = 0; int thatMarker = 0; int s1Length = s1.length(); int s2Length = s2.length(); - while (thisMarker < s1Length && thatMarker < s2Length) - { + while (thisMarker < s1Length && thatMarker < s2Length) { String thisChunk = getChunk(s1, s1Length, thisMarker); thisMarker += thisChunk.length(); @@@ -94,23 -109,26 +106,23 @@@ // If both chunks contain numeric characters, sort them numerically int result = 0; - if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) - { + if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) { // Simple chunk comparison by length. int thisChunkLength = thisChunk.length(); result = thisChunkLength - thatChunk.length(); // If equal, the first different number counts - if (result == 0) - { - for (int i = 0; i < thisChunkLength; i++) - { + if (result == 0) { + for (int i = 0; i < thisChunkLength; i++) { result = thisChunk.charAt(i) - thatChunk.charAt(i); - if (result != 0) - { + if (result != 0) { return result; } } } - } else - { - result = thisChunk.compareTo(thatChunk); + } else { + Collator collator = Collator.getInstance(); + collator.setStrength(Collator.PRIMARY); + result = collator.compare(thisChunk, thatChunk); } if (result != 0)