From: jabarros Date: Mon, 19 Jan 2015 11:49:28 +0000 (+0100) Subject: Merge branch 'develop' into download_folder X-Git-Tag: oc-android-1.7.0_signed~23^2~11 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e98fc8b141fed66cbdd265aaebd2cfa3affb68ac?hp=-c Merge branch 'develop' into download_folder --- e98fc8b141fed66cbdd265aaebd2cfa3affb68ac diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 059cb2b4,3bec9167..398a833d --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -92,7 -92,7 +92,7 @@@ import com.owncloud.android.operations. import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; -import com.owncloud.android.operations.SynchronizeFolderOperation; +import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; @@@ -109,6 -109,7 +109,7 @@@ import com.owncloud.android.ui.preview. import com.owncloud.android.ui.preview.PreviewVideoActivity; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; + import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.UriUtils; @@@ -519,7 -520,7 +520,7 @@@ OnSslUntrustedCertListener, OnEnforceab // Read sorting order, default to sort by name ascending Integer sortOrder = appPreferences - .getInt("sortOrder", FileListListAdapter.SORT_NAME); + .getInt("sortOrder", FileStorageUtils.SORT_NAME); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.actionbar_sort_title) @@@ -809,8 -810,8 +810,8 @@@ IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START); syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END); syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED); - syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); - syncIntentFilter.addAction(SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); + syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED); + syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED); mSyncBroadcastReceiver = new SyncBroadcastReceiver(); registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver, syncIntentFilter); @@@ -1098,9 -1099,9 +1099,9 @@@ setFile(currentFile); } - mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event)); + mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event)); - if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. + if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. equals(event) && /// TODO refactor and make common synchResult != null && !synchResult.isSuccess() && @@@ -1752,7 -1753,7 +1753,7 @@@ mSyncInProgress = true; // perform folder synchronization - RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder, + RemoteOperation synchFolderOp = new RefreshFolderOperation( folder, currentSyncTime, false, getFileOperationsHelper().isSharedSupported(), diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 850d03b8,9c8c8e1f..0e3e0377 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -17,7 -17,7 +17,7 @@@ */ package com.owncloud.android.ui.adapter; - + import java.io.File; import java.util.Collections; import java.util.Comparator; @@@ -44,14 -44,12 +44,13 @@@ import com.owncloud.android.authenticat import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.ThumbnailsCacheManager; - import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; +import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; - + /** * This Adapter populates a ListView with all files and folders in an ownCloud @@@ -61,7 -59,7 +60,7 @@@ * @author Tobias Kaminsky * @author David A. Velasco */ - public class FileListListAdapter extends BaseAdapter implements ListAdapter { + public class FileListListAdapter extends BaseAdapter implements ListAdapter { private final static String PERMISSION_SHARED_WITH_ME = "S"; private Context mContext; @@@ -69,14 -67,10 +68,10 @@@ private Vector mFiles = null; private boolean mJustFolders; - private FileDataStorageManager mStorageManager; - private Account mAccount; + private FileDataStorageManager mStorageManager; + private Account mAccount; private ComponentsGetter mTransferServiceGetter; - private Integer mSortOrder; - public static final Integer SORT_NAME = 0; - public static final Integer SORT_DATE = 1; - public static final Integer SORT_SIZE = 2; - private Boolean mSortAscending; + private SharedPreferences mAppPreferences; public FileListListAdapter( @@@ -88,22 -82,22 +83,22 @@@ mJustFolders = justFolders; mContext = context; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); - - mTransferServiceGetter = transferServiceGetter; + + mTransferServiceGetter = transferServiceGetter; mAppPreferences = PreferenceManager .getDefaultSharedPreferences(mContext); // Read sorting order, default to sort by name ascending - mSortOrder = mAppPreferences - .getInt("sortOrder", 0); - mSortAscending = mAppPreferences.getBoolean("sortAscending", true); + FileStorageUtils.mSortOrder = mAppPreferences.getInt("sortOrder", 0); + FileStorageUtils.mSortAscending = mAppPreferences.getBoolean("sortAscending", true); + // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); } - + @Override public boolean areAllItemsEnabled() { return true; @@@ -164,9 -158,7 +159,9 @@@ FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); - if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) { + OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder(); + if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || + (file.isFolder() && opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()))) { localStateView.setImageResource(R.drawable.downloading_file_indicator); localStateView.setVisibility(View.VISIBLE); } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) { @@@ -217,16 -209,18 +212,18 @@@ if (thumbnail != null && !file.needsUpdateThumbnail()){ fileIcon.setImageBitmap(thumbnail); } else { + // generate new Thumbnail if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) { - final ThumbnailsCacheManager.ThumbnailGenerationTask task = + final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask( fileIcon, mStorageManager, mAccount ); if (thumbnail == null) { thumbnail = ThumbnailsCacheManager.mDefaultImg; } - final AsyncDrawable asyncDrawable = new AsyncDrawable( + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( mContext.getResources(), thumbnail, task @@@ -236,11 -230,9 +233,9 @@@ } } } else { - fileIcon.setImageResource( - DisplayUtils.getResourceId(file.getMimetype(), file.getFileName()) - ); + fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName())); } - + if (checkIfFileIsSharedWithMe(file)) { sharedWithMeIconV.setVisibility(View.VISIBLE); } @@@ -253,7 -245,7 +248,7 @@@ // } else { fileSizeV.setVisibility(View.INVISIBLE); // } - + lastModV.setVisibility(View.VISIBLE); lastModV.setText(showRelativeTimestamp(file)); checkBoxV.setVisibility(View.GONE); @@@ -264,7 -256,7 +259,7 @@@ sharedWithMeIconV.setVisibility(View.VISIBLE); } else { fileIcon.setImageResource( - DisplayUtils.getResourceId(file.getMimetype(), file.getFileName()) + DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()) ); } @@@ -284,7 -276,7 +279,7 @@@ return view; } - + /** * Local Folder size in human readable format * @@@ -297,7 -289,7 +292,7 @@@ File dir = new File(path); if (dir.exists()) { - long bytes = getFolderSize(dir); + long bytes = FileStorageUtils.getFolderSize(dir); return DisplayUtils.bytesToHumanReadable(bytes); } @@@ -323,8 -315,8 +318,8 @@@ return result; } return 0; - } - + } + @Override public int getViewTypeCount() { return 1; @@@ -362,29 -354,11 +357,11 @@@ mFiles = null; } - sortDirectory(); - } - - /** - * Sorts all filenames, regarding last user decision - */ - private void sortDirectory(){ - switch (mSortOrder){ - case 0: - sortByName(mSortAscending); - break; - case 1: - sortByDate(mSortAscending); - break; - case 2: - sortBySize(mSortAscending); - break; - } - + mFiles = FileStorageUtils.sortFolder(mFiles); notifyDataSetChanged(); } - + /** * Filter for getting only the folders * @param files @@@ -417,110 -391,23 +394,23 @@@ && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME)); } - /** - * Sorts list by Date - * @param sortAscending true: ascending, false: descending - */ - private void sortByDate(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - Long obj1 = o1.getModificationTimestamp(); - return val * obj1.compareTo(o2.getModificationTimestamp()); - } - else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } else if (o1.getModificationTimestamp() == 0 || o2.getModificationTimestamp() == 0){ - return 0; - } else { - Long obj1 = o1.getModificationTimestamp(); - return val * obj1.compareTo(o2.getModificationTimestamp()); - } - } - }); - } - - /** - * Sorts list by Size - * @param sortAscending true: ascending, false: descending - */ - private void sortBySize(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - Long obj1 = getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o1))); - return val * obj1.compareTo(getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o2)))); - } - else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } else if (o1.getFileLength() == 0 || o2.getFileLength() == 0){ - return 0; - } else { - Long obj1 = o1.getFileLength(); - return val * obj1.compareTo(o2.getFileLength()); - } - } - }); - } - - /** - * Sorts list by Name - * @param sortAscending true: ascending, false: descending - */ - private void sortByName(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - return val * o1.getRemotePath().toLowerCase().compareTo(o2.getRemotePath().toLowerCase()); - } else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } - return val * new AlphanumComparator().compare(o1, o2); - } - }); - } - public void setSortOrder(Integer order, boolean ascending) { SharedPreferences.Editor editor = mAppPreferences.edit(); editor.putInt("sortOrder", order); editor.putBoolean("sortAscending", ascending); editor.commit(); - mSortOrder = order; - mSortAscending = ascending; + FileStorageUtils.mSortOrder = order; + FileStorageUtils.mSortAscending = ascending; - sortDirectory(); + + mFiles = FileStorageUtils.sortFolder(mFiles); + notifyDataSetChanged(); + } private CharSequence showRelativeTimestamp(OCFile file){ return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); - } + } }