Browse Source

Removed call to methods to check transfer state of files through binders and replaced with methods on OCFile

David A. Velasco 10 năm trước cách đây
mục cha
commit
49849786e5

+ 14 - 0
src/com/owncloud/android/datamodel/OCFile.java

@@ -562,4 +562,18 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         this.mRemoteId = remoteId;
     }
 
+    public boolean isSynchronizing() {
+        // TODO real implementation
+        return false;
+    }
+
+    public boolean isDownloading() {
+        // TODO real implementation
+        return false;
+    }
+
+    public boolean isUploading() {
+        // TODO real implementation
+        return false;
+    }
 }

+ 4 - 14
src/com/owncloud/android/files/FileMenuFilter.java

@@ -43,7 +43,6 @@ import com.owncloud.android.ui.activity.ComponentsGetter;
 public class FileMenuFilter {
 
     private OCFile mFile;
-    private ComponentsGetter mComponentsGetter;
     private Account mAccount;
     private Context mContext;
     
@@ -52,14 +51,11 @@ public class FileMenuFilter {
      * 
      * @param targetFile        {@link OCFile} target of the action to filter in the {@link Menu}.
      * @param account           ownCloud {@link Account} holding targetFile.
-     * @param cg                Accessor to app components, needed to get access the 
-     *                          {@link FileUploader} and {@link FileDownloader} services.
      * @param context           Android {@link Context}, needed to access build setup resources.
      */
-    public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context) {
+    public FileMenuFilter(OCFile targetFile, Account account, Context context) {
         mFile = targetFile;
         mAccount = account;
-        mComponentsGetter = cg;
         mContext = context;
     }
     
@@ -139,15 +135,9 @@ public class FileMenuFilter {
     private void filter(List<Integer> toShow, List <Integer> toHide) {
         boolean downloading = false;
         boolean uploading = false;
-        if (mComponentsGetter != null && mFile != null && mAccount != null) {
-            FileDownloaderBinder downloaderBinder = mComponentsGetter.getFileDownloaderBinder();
-            downloading = downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile);
-            OperationsServiceBinder opsBinder = mComponentsGetter.getOperationsServiceBinder();
-            downloading |= (
-                    mFile.isFolder() && opsBinder != null && opsBinder.isSynchronizing(mAccount, mFile.getRemotePath())
-            );
-            FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
-            uploading = uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile);
+        if (mFile != null && mAccount != null) {
+            downloading = mFile.isDownloading() || mFile.isSynchronizing();
+            uploading = mFile.isUploading();
         }
         
         /// decision is taken for each possible action on a file in the menu

+ 2 - 2
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -287,7 +287,7 @@ public class FileOperationsHelper {
         if (!file.isFolder()) {
             FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
-            if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
+            if (downloaderBinder != null && file.isDownloading()) {
                 // Remove etag for parent, if file is a keep_in_sync
                 if (file.keepInSync()) {
                     OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
@@ -297,7 +297,7 @@ public class FileOperationsHelper {
 
                 downloaderBinder.cancel(account, file);
 
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
+            } else if (uploaderBinder != null && file.isUploading()) {
                 uploaderBinder.cancel(account, file);
             }
         } else {

+ 2 - 0
src/com/owncloud/android/files/services/FileDownloader.java

@@ -253,6 +253,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
          * @param account       Owncloud account where the remote file is stored.
          * @param file          A file that could be in the queue of downloads.
          */
+        /*
         public boolean isDownloading(Account account, OCFile file) {
             if (account == null || file == null) return false;
             String targetKey = buildRemoteName(account, file);
@@ -270,6 +271,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
                 }
             }
         }
+        */
 
         
         /**

+ 5 - 3
src/com/owncloud/android/files/services/FileUploader.java

@@ -199,7 +199,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         if (uploadType == UPLOAD_SINGLE_FILE) {
 
             if (intent.hasExtra(KEY_FILE)) {
-                files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) };
+                files = new OCFile[] { (OCFile) intent.getParcelableExtra(KEY_FILE) };
 
             } else {
                 localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) };
@@ -375,6 +375,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
          * @param account Owncloud account where the remote file will be stored.
          * @param file A file that could be in the queue of pending uploads
          */
+        /*
         public boolean isUploading(Account account, OCFile file) {
             if (account == null || file == null)
                 return false;
@@ -393,6 +394,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
                 }
             }
         }
+        */
 
 
         /**
@@ -400,7 +402,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
          * 
          * @param listener      Object to notify about progress of transfer.    
          * @param account       ownCloud account holding the file of interest.
-         * @param file          {@link OCfile} of interest for listener. 
+         * @param file          {@link OCFile} of interest for listener.
          */
         public void addDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
             if (account == null || file == null || listener == null) return;
@@ -415,7 +417,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
          * 
          * @param listener      Object to notify about progress of transfer.    
          * @param account       ownCloud account holding the file of interest.
-         * @param file          {@link OCfile} of interest for listener. 
+         * @param file          {@link OCFile} of interest for listener.
          */
         public void removeDatatransferProgressListener (OnDatatransferProgressListener listener, Account account, OCFile file) {
             if (account == null || file == null || listener == null) return;

+ 2 - 0
src/com/owncloud/android/services/OperationsService.java

@@ -379,9 +379,11 @@ public class OperationsService extends Service {
          * @param account       ownCloud account where the remote file is stored.
          * @param file          A file that could be affected 
          */
+        /*
         public boolean isSynchronizing(Account account, String remotePath) {
             return mSyncFolderHandler.isSynchronizing(account, remotePath);
         }
+        */
 
     }
 

+ 3 - 4
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1725,7 +1725,7 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
 
     private void requestForDownload() {
         Account account = getAccount();
-        if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
+        if (mWaitingToPreview.isDownloading()) {
             Intent i = new Intent(this, FileDownloader.class);
             i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
             i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
@@ -1781,10 +1781,9 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
     }
     
     private void requestForDownload(OCFile file) {
-        Account account = getAccount();
-        if (!mDownloaderBinder.isDownloading(account, file)) {
+        if (file.isDownloading()) {
             Intent i = new Intent(this, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
+            i.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
             i.putExtra(FileDownloader.EXTRA_FILE, file);
             startService(i);
         }

+ 4 - 20
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -19,11 +19,8 @@ package com.owncloud.android.ui.adapter;
 
 
 import java.io.File;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.Vector;
 
-import third_parties.daveKoeller.AlphanumComparator;
 import android.accounts.Account;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -44,10 +41,6 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
-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;
 
@@ -70,22 +63,18 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
 
     private FileDataStorageManager mStorageManager;
     private Account mAccount;
-    private ComponentsGetter mTransferServiceGetter;
-    
+
     private SharedPreferences mAppPreferences;
     
     public FileListListAdapter(
             boolean justFolders, 
-            Context context, 
-            ComponentsGetter transferServiceGetter
+            Context context
             ) {
 
         mJustFolders = justFolders;
         mContext = context;
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
 
-        mTransferServiceGetter = transferServiceGetter;
-        
         mAppPreferences = PreferenceManager
                 .getDefaultSharedPreferences(mContext);
         
@@ -156,15 +145,10 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
 
             ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
             localStateView.bringToFront();
-            FileDownloaderBinder downloaderBinder = 
-                    mTransferServiceGetter.getFileDownloaderBinder();
-            FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
-            OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder();
-            if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) ||
-                 (file.isFolder() && opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath()))) {
+            if (file.isSynchronizing() || file.isDownloading()) {
                 localStateView.setImageResource(R.drawable.downloading_file_indicator);
                 localStateView.setVisibility(View.VISIBLE);
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
+            } else if (file.isUploading()) {
                 localStateView.setImageResource(R.drawable.uploading_file_indicator);
                 localStateView.setVisibility(View.VISIBLE);
             } else if (file.isDown()) {

+ 3 - 6
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -179,7 +179,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             FileMenuFilter mf = new FileMenuFilter(
                 getFile(),
                 mContainerActivity.getStorageManager().getAccount(),
-                mContainerActivity,
                 getSherlockActivity()
             );
             mf.filter(menu);
@@ -348,7 +347,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             // configure UI for depending upon local state of the file
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-            if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
+            if (transferring || file.isDownloading() || file.isUploading()) {
                 setButtonsForTransferring();
                 
             } else if (file.isDown()) {
@@ -447,11 +446,9 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
             TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
             progressText.setVisibility(View.VISIBLE);
-            FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
-            FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
+            if (getFile().isDownloading()) {
                 progressText.setText(R.string.downloader_download_in_progress_ticker);
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
+            } else if (getFile().isUploading()) {
                 progressText.setText(R.string.uploader_upload_in_progress_ticker);
             }
         }

+ 1 - 3
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -131,8 +131,7 @@ public class OCFileListFragment extends ExtendedListFragment {
         boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false); 
         mAdapter = new FileListListAdapter(
                 justFolders,
-                getSherlockActivity(), 
-                mContainerActivity
+                getSherlockActivity()
                 );
         setListAdapter(mAdapter);
 
@@ -253,7 +252,6 @@ public class OCFileListFragment extends ExtendedListFragment {
                 FileMenuFilter mf = new FileMenuFilter(
                     targetFile,
                     mContainerActivity.getStorageManager().getAccount(),
-                    mContainerActivity,
                     getSherlockActivity()
                 );
                 mf.filter(menu);

+ 4 - 3
src/com/owncloud/android/ui/preview/FileDownloadFragment.java

@@ -211,10 +211,11 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
      * @param   transferring    When true, the view must be updated assuming that the holded file is 
      *                          downloading, no matter what the downloaderBinder says.
      */
+    /*
     public void updateView(boolean transferring) {
         // configure UI for depending upon local state of the file
-        FileDownloaderBinder downloaderBinder = (mContainerActivity == null) ? null : mContainerActivity.getFileDownloaderBinder();
-        if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile()))) {
+        // TODO remove
+        if (transferring || getFile().isDownloading()) {
             setButtonsForTransferring();
             
         } else if (getFile().isDown()) {
@@ -227,7 +228,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
         getView().invalidate();
         
     }
-
+    */
 
     /**
      * Enables or disables buttons for a file being downloaded

+ 1 - 1
src/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -365,7 +365,7 @@ ViewPager.OnPageChangeListener, OnRemoteOperationListener {
         if (mDownloaderBinder == null) {
             Log_OC.d(TAG, "requestForDownload called without binder to download service");
             
-        } else if (!mDownloaderBinder.isDownloading(getAccount(), file)) {
+        } else if (!file.isDownloading()) {
             Intent i = new Intent(this, FileDownloader.class);
             i.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
             i.putExtra(FileDownloader.EXTRA_FILE, file);

+ 0 - 1
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -232,7 +232,6 @@ public class PreviewImageFragment extends FileFragment {
             FileMenuFilter mf = new FileMenuFilter(
                 getFile(),
                 mContainerActivity.getStorageManager().getAccount(),
-                mContainerActivity,
                 getSherlockActivity()
             );
             mf.filter(menu);

+ 0 - 1
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -277,7 +277,6 @@ public class PreviewMediaFragment extends FileFragment implements
             FileMenuFilter mf = new FileMenuFilter(
                 getFile(),
                 mContainerActivity.getStorageManager().getAccount(),
-                mContainerActivity,
                 getSherlockActivity()
             );
             mf.filter(menu);