Переглянути джерело

Refactoring relationship between FileActivities and FileFragments (WIP)

David A. Velasco 11 роки тому
батько
коміт
bea36f23b0

+ 91 - 30
src/com/owncloud/android/files/FileOperationsHelper.java

@@ -19,6 +19,7 @@ package com.owncloud.android.files;
 
 import org.apache.http.protocol.HTTP;
 
+import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.content.Intent;
 import android.net.Uri;
@@ -31,7 +32,11 @@ import com.owncloud.android.datamodel.OCFile;
 
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
 import com.owncloud.android.lib.common.network.WebdavUtils;
+import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
+import com.owncloud.android.operations.RemoveFileOperation;
+import com.owncloud.android.operations.RenameFileOperation;
+import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.ShareLinkToDialog;
@@ -48,8 +53,14 @@ public class FileOperationsHelper {
     
     private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; 
 
+    protected FileActivity mFileActivity = null;
     
-    public void openFile(OCFile file, FileActivity callerActivity) {
+    public FileOperationsHelper(FileActivity fileActivity) {
+        mFileActivity = fileActivity;
+    }
+
+
+    public void openFile(OCFile file) {
         if (file != null) {
             String storagePath = file.getStoragePath();
             String encodedStoragePath = WebdavUtils.encodePath(storagePath);
@@ -70,28 +81,28 @@ public class FileOperationsHelper {
             
             Intent chooserIntent = null;
             if (intentForGuessedMimeType != null) {
-                chooserIntent = Intent.createChooser(intentForGuessedMimeType, callerActivity.getString(R.string.actionbar_open_with));
+                chooserIntent = Intent.createChooser(intentForGuessedMimeType, mFileActivity.getString(R.string.actionbar_open_with));
             } else {
-                chooserIntent = Intent.createChooser(intentForSavedMimeType, callerActivity.getString(R.string.actionbar_open_with));
+                chooserIntent = Intent.createChooser(intentForSavedMimeType, mFileActivity.getString(R.string.actionbar_open_with));
             }
             
-            callerActivity.startActivity(chooserIntent);
+            mFileActivity.startActivity(chooserIntent);
             
         } else {
             Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
         }
     }
     
-
-    public void shareFileWithLink(OCFile file, FileActivity callerActivity) {
+    
+    public void shareFileWithLink(OCFile file) {
         
-        if (isSharedSupported(callerActivity)) {
+        if (isSharedSupported()) {
             if (file != null) {
                 String link = "https://fake.url";
                 Intent intent = createShareWithLinkIntent(link);
-                String[] packagesToExclude = new String[] { callerActivity.getPackageName() };
+                String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
                 DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intent, packagesToExclude, file);
-                chooserDialog.show(callerActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
+                chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
                 
             } else {
                 Log_OC.wtf(TAG, "Trying to share a NULL OCFile");
@@ -99,23 +110,23 @@ public class FileOperationsHelper {
             
         } else {
             // Show a Message
-            Toast t = Toast.makeText(callerActivity, callerActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
+            Toast t = Toast.makeText(mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
             t.show();
         }
     }
     
     
-    public void shareFileWithLinkToApp(OCFile file, Intent sendIntent, FileActivity callerActivity) {
+    public void shareFileWithLinkToApp(OCFile file, Intent sendIntent) {
         
         if (file != null) {
-            callerActivity.showLoadingDialog();
+            mFileActivity.showLoadingDialog();
             
-            Intent service = new Intent(callerActivity, OperationsService.class);
+            Intent service = new Intent(mFileActivity, OperationsService.class);
             service.setAction(OperationsService.ACTION_CREATE_SHARE);
-            service.putExtra(OperationsService.EXTRA_ACCOUNT, callerActivity.getAccount());
+            service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
             service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
             service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent);
-            callerActivity.getOperationsServiceBinder().newOperation(service);
+            mFileActivity.getOperationsServiceBinder().newOperation(service);
             
         } else {
             Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
@@ -134,39 +145,38 @@ public class FileOperationsHelper {
     /**
      *  @return 'True' if the server supports the Share API
      */
-    public boolean isSharedSupported(FileActivity callerActivity) {
-        if (callerActivity.getAccount() != null) {
-            AccountManager accountManager = AccountManager.get(callerActivity);
+    public boolean isSharedSupported() {
+        if (mFileActivity.getAccount() != null) {
+            AccountManager accountManager = AccountManager.get(mFileActivity);
 
-            String version = accountManager.getUserData(callerActivity.getAccount(), Constants.KEY_OC_VERSION);
+            String version = accountManager.getUserData(mFileActivity.getAccount(), Constants.KEY_OC_VERSION);
             return (new OwnCloudVersion(version)).isSharedSupported();
-            //return Boolean.parseBoolean(accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));
         }
         return false;
     }
     
     
-    public void unshareFileWithLink(OCFile file, FileActivity callerActivity) {
+    public void unshareFileWithLink(OCFile file) {
         
-        if (isSharedSupported(callerActivity)) {
+        if (isSharedSupported()) {
             // Unshare the file
-            Intent service = new Intent(callerActivity, OperationsService.class);
+            Intent service = new Intent(mFileActivity, OperationsService.class);
             service.setAction(OperationsService.ACTION_UNSHARE);
-            service.putExtra(OperationsService.EXTRA_ACCOUNT, callerActivity.getAccount());
+            service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
             service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
-            callerActivity.getOperationsServiceBinder().newOperation(service);
+            mFileActivity.getOperationsServiceBinder().newOperation(service);
             
-            callerActivity.showLoadingDialog();
+            mFileActivity.showLoadingDialog();
             
         } else {
             // Show a Message
-            Toast t = Toast.makeText(callerActivity, callerActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
+            Toast t = Toast.makeText(mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
             t.show();
             
         }
     }
     
-    public void sendDownloadedFile(OCFile file, FileActivity callerActivity) {
+    public void sendDownloadedFile(OCFile file) {
         if (file != null) {
             Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
             // set MimeType
@@ -175,13 +185,64 @@ public class FileOperationsHelper {
             sendIntent.putExtra(Intent.ACTION_SEND, true);      // Send Action
             
             // Show dialog, without the own app
-            String[] packagesToExclude = new String[] { callerActivity.getPackageName() };
+            String[] packagesToExclude = new String[] { mFileActivity.getPackageName() };
             DialogFragment chooserDialog = ShareLinkToDialog.newInstance(sendIntent, packagesToExclude, file);
-            chooserDialog.show(callerActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
+            chooserDialog.show(mFileActivity.getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
 
         } else {
             Log_OC.wtf(TAG, "Trying to send a NULL OCFile");
         }
     }
+    
+    
+    public void syncFile(OCFile file) {
+        Account account = mFileActivity.getAccount();
+        RemoteOperation operation = new SynchronizeFileOperation(
+                file, 
+                null, 
+                mFileActivity.getStorageManager(), 
+                account, 
+                true, 
+                mFileActivity);
+        operation.execute(account, mFileActivity, mFileActivity, mFileActivity.getHandler(), mFileActivity);
+        mFileActivity.showLoadingDialog();
+    }
+    
+    
+    public void renameFile(OCFile file, String newFilename) {
+        Account account = mFileActivity.getAccount();
+        RemoteOperation operation = new RenameFileOperation(
+                        file, 
+                        account, 
+                        newFilename, 
+                        mFileActivity.getStorageManager());
+        
+        operation.execute(
+                account, 
+                mFileActivity, 
+                mFileActivity, 
+                mFileActivity.getHandler(), 
+                mFileActivity);
+        
+        mFileActivity.showLoadingDialog();
+    }
+
 
+    public void removeFile(OCFile file, boolean removeLocalCopy) {
+        Account account = mFileActivity.getAccount();
+        RemoteOperation operation = new RemoveFileOperation( 
+                file, 
+                removeLocalCopy, 
+                mFileActivity.getStorageManager());
+        
+        operation.execute(
+                account, 
+                mFileActivity, 
+                mFileActivity, 
+                mFileActivity.getHandler(), 
+                mFileActivity);
+        
+        mFileActivity.showLoadingDialog();
+    }
+    
 }

+ 8 - 1
src/com/owncloud/android/ui/activity/TransferServiceGetter.java → src/com/owncloud/android/ui/activity/ComponentsGetter.java

@@ -18,10 +18,12 @@
 
 package com.owncloud.android.ui.activity;
 
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.files.FileOperationsHelper;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 
-public interface TransferServiceGetter {
+public interface ComponentsGetter {
 
     /**
      * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
@@ -38,5 +40,10 @@ public interface TransferServiceGetter {
      */
     public FileUploaderBinder getFileUploaderBinder();
 
+    
+    
+    public FileDataStorageManager getStorageManager();
+    
+    public FileOperationsHelper getFileOperationsHelper();
 
 }

+ 48 - 4
src/com/owncloud/android/ui/activity/FileActivity.java

@@ -42,6 +42,10 @@ import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.FileOperationsHelper;
+import com.owncloud.android.files.services.FileDownloader;
+import com.owncloud.android.files.services.FileUploader;
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -60,7 +64,8 @@ import com.owncloud.android.utils.Log_OC;
  * 
  * @author David A. Velasco
  */
-public class FileActivity extends SherlockFragmentActivity implements OnRemoteOperationListener {
+public class FileActivity extends SherlockFragmentActivity 
+implements OnRemoteOperationListener, ComponentsGetter {
 
     public static final String EXTRA_FILE = "com.owncloud.android.ui.activity.FILE";
     public static final String EXTRA_ACCOUNT = "com.owncloud.android.ui.activity.ACCOUNT";
@@ -101,7 +106,11 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     private ServiceConnection mOperationsServiceConnection = null;
     
     private OperationsServiceBinder mOperationsServiceBinder = null;
-
+    
+    protected FileDownloaderBinder mDownloaderBinder = null;
+    protected FileUploaderBinder mUploaderBinder = null;
+    private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
+    
     
     /**
      * Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of 
@@ -114,7 +123,7 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mHandler = new Handler();
-        mFileOperationsHelper = new FileOperationsHelper();
+        mFileOperationsHelper = new FileOperationsHelper(this);
         Account account;
         if(savedInstanceState != null) {
             account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
@@ -130,6 +139,16 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
         
         mOperationsServiceConnection = new OperationsServiceConnection();
         bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);
+        
+        mDownloadServiceConnection = newTransferenceServiceConnection();
+        if (mDownloadServiceConnection != null) {
+            bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection, Context.BIND_AUTO_CREATE);
+        }
+        mUploadServiceConnection = newTransferenceServiceConnection();
+        if (mUploadServiceConnection != null) {
+            bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
+        }
+        
     }
 
     
@@ -179,6 +198,14 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
             unbindService(mOperationsServiceConnection);
             mOperationsServiceBinder = null;
         }
+        if (mDownloadServiceConnection != null) {
+            unbindService(mDownloadServiceConnection);
+            mDownloadServiceConnection = null;
+        }
+        if (mUploadServiceConnection != null) {
+            unbindService(mUploadServiceConnection);
+            mUploadServiceConnection = null;
+        }
     }
     
     
@@ -308,7 +335,11 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
     public OperationsServiceBinder getOperationsServiceBinder() {
         return mOperationsServiceBinder;
     }
-
+    
+    protected ServiceConnection newTransferenceServiceConnection() {
+        return null;
+    }
+    
 
     /**
      * Helper class handling a callback from the {@link AccountManager} after the creation of
@@ -500,6 +531,19 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp
                 // TODO whatever could be waiting for the service is unbound
             }
         }
+    }
+
+
+    @Override
+    public FileDownloaderBinder getFileDownloaderBinder() {
+        return mDownloaderBinder;
+    }
+
+
+    @Override
+    public FileUploaderBinder getFileUploaderBinder() {
+        return mUploaderBinder;
     };    
     
+    
 }

+ 94 - 110
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -102,7 +102,8 @@ import com.owncloud.android.utils.Log_OC;
  */
 
 public class FileDisplayActivity extends HookActivity implements
-OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener, EditNameDialogListener {
+FileFragment.ContainerActivity, OnNavigationListener, 
+OnSslUntrustedCertListener, EditNameDialogListener {
 
     private ArrayAdapter<String> mDirectories;
 
@@ -110,9 +111,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private UploadFinishReceiver mUploadFinishReceiver;
     private DownloadFinishReceiver mDownloadFinishReceiver;
     //private OperationsServiceReceiver mOperationsServiceReceiver;
-    private FileDownloaderBinder mDownloaderBinder = null;
-    private FileUploaderBinder mUploaderBinder = null;
-    private ServiceConnection mDownloadConnection = null, mUploadConnection = null;
     private RemoteOperationResult mLastSslUntrustedServerResult = null;
 
     private boolean mDualPane;
@@ -155,12 +153,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
         super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid
 
-        /// bindings to transference services
-        mUploadConnection = new ListServiceConnection(); 
-        mDownloadConnection = new ListServiceConnection();
-        bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
-        bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
-
         // PIN CODE request ;  best location is to decide, let's try this first
         if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN) && savedInstanceState == null) {
             requestPinCode();
@@ -223,10 +215,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if (mDownloadConnection != null)
-            unbindService(mDownloadConnection);
-        if (mUploadConnection != null)
-            unbindService(mUploadConnection);
     }
 
     /**
@@ -452,7 +440,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                             startMediaPreview(mWaitingToPreview, 0, true);
                             detailsFragmentChanged = true;
                         } else {
-                            getFileOperationsHelper().openFile(mWaitingToPreview, this);
+                            getFileOperationsHelper().openFile(mWaitingToPreview);
                         }
                     }
                     mWaitingToPreview = null;
@@ -1143,54 +1131,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         
     }
 
-    /**
-     * Opens the image gallery showing the image {@link OCFile} received as parameter.
-     * 
-     * @param file                      Image {@link OCFile} to show.
-     */
-    @Override
-    public void startImagePreview(OCFile file) {
-        Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
-        showDetailsIntent.putExtra(EXTRA_FILE, file);
-        showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
-        startActivity(showDetailsIntent);
-    }
-
-    /**
-     * Stars the preview of an already down media {@link OCFile}.
-     * 
-     * @param file                      Media {@link OCFile} to preview.
-     * @param startPlaybackPosition     Media position where the playback will be started, in milliseconds.
-     * @param autoplay                  When 'true', the playback will start without user interactions.
-     */
-    @Override
-    public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
-        Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
-        setSecondFragment(mediaFragment);
-        updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
-        setFile(file);
-    }
-
-    /**
-     * Requests the download of the received {@link OCFile} , updates the UI
-     * to monitor the download progress and prepares the activity to preview
-     * or open the file when the download finishes.
-     * 
-     * @param file          {@link OCFile} to download and preview.
-     */
-    @Override
-    public void startDownloadForPreview(OCFile file) {
-        Fragment detailFragment = new FileDetailFragment(file, getAccount());
-        setSecondFragment(detailFragment);
-        mWaitingToPreview = file;
-        requestForDownload();
-        updateFragmentsVisibility(true);
-        updateNavigationElementsInActionBar(file);
-        setFile(file);
-    }
-
-
     /**
      * Shows the information of the {@link OCFile} received as a 
      * parameter in the second fragment.
@@ -1246,24 +1186,11 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     }
 
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public FileDownloaderBinder getFileDownloaderBinder() {
-        return mDownloaderBinder;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public FileUploaderBinder getFileUploaderBinder() {
-        return mUploaderBinder;
+    protected ServiceConnection newTransferenceServiceConnection() {
+        return new ListServiceConnection();
     }
 
-
     /** Defines callbacks for service binding, passed to bindService() */
     private class ListServiceConnection implements ServiceConnection {
 
@@ -1428,7 +1355,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             Toast msg = Toast.makeText(this, R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
             OCFile removedFile = operation.getFile();
-            getSecondFragment();
             FileFragment second = getSecondFragment();
             if (second != null && removedFile.equals(second.getFile())) {
                 cleanSecondFragment();
@@ -1448,7 +1374,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             }
         }
     }
-
+    
+    
     /**
      * Updates the view associated to the activity after the finish of an operation trying create a new folder
      * 
@@ -1490,11 +1417,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         dismissLoadingDialog();
         OCFile renamedFile = operation.getFile();
         if (result.isSuccess()) {
-            if (mDualPane) {
-                FileFragment details = getSecondFragment();
-                if (details != null && details instanceof FileDetailFragment && renamedFile.equals(details.getFile()) ) {
-                    ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
-                }
+            FileFragment details = getSecondFragment();
+            if (details != null && details instanceof FileDetailFragment && renamedFile.equals(details.getFile()) ) {
+                ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
             }
             if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())) {
                 /*
@@ -1521,7 +1446,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         }
     }
 
-
     private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
         dismissLoadingDialog();
         OCFile syncedFile = operation.getLocalFile();
@@ -1533,14 +1457,14 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 startActivity(i);
 
             } 
-
+            
         } else {
             if (operation.transferWasRequested()) {
                 /*
                 refeshListOfFilesFragment();
                 */
                 onTransferStateChanged(syncedFile, true, true);
-
+                
             } else {
                 Toast msg = Toast.makeText(this, R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); 
                 msg.show();
@@ -1548,20 +1472,18 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         }
     }
 
-
+    
     /**
      * {@inheritDoc}
      */
     @Override
     public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
-        if (mDualPane) {
-            FileFragment details = getSecondFragment();
-            if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) {
-                if (downloading || uploading) {
-                    ((FileDetailFragment)details).updateFileDetails(file, getAccount());
-                } else {
-                    ((FileDetailFragment)details).updateFileDetails(false, true);
-                }
+        FileFragment details = getSecondFragment();
+        if (details != null && details instanceof FileDetailFragment && file.equals(details.getFile()) ) {
+            if (downloading || uploading) {
+                ((FileDetailFragment)details).updateFileDetails(file, getAccount());
+            } else {
+                ((FileDetailFragment)details).updateFileDetails(false, true);
             }
         }
     }
@@ -1622,7 +1544,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,  
                                                                         currentSyncTime, 
                                                                         false,
-                                                                        getFileOperationsHelper().isSharedSupported(this),
+                                                                        getFileOperationsHelper().isSharedSupported(),
                                                                         getStorageManager(), 
                                                                         getAccount(), 
                                                                         getApplicationContext()
@@ -1654,6 +1576,22 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         dialog.show(ft, DIALOG_UNTRUSTED_CERT);
     }
     
+    private void requestForDownload(OCFile file) {
+        Account account = getAccount();
+        if (!mDownloaderBinder.isDownloading(account, file)) {
+            Intent i = new Intent(this, FileDownloader.class);
+            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
+            i.putExtra(FileDownloader.EXTRA_FILE, file);
+            startService(i);
+        }
+    }
+    
+    private void sendDownloadedFile(){
+        getFileOperationsHelper().sendDownloadedFile(mWaitingToSend);
+        mWaitingToSend = null;
+    }
+
+    
     /**
      * Requests the download of the received {@link OCFile} , updates the UI
      * to monitor the download progress and prepares the activity to send the file
@@ -1661,7 +1599,6 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
      * 
      * @param file          {@link OCFile} to download and preview.
      */
-    @Override
     public void startDownloadForSending(OCFile file) {
         mWaitingToSend = file;
         requestForDownload(mWaitingToSend);
@@ -1669,19 +1606,66 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         updateFragmentsVisibility(hasSecondFragment);
     }
     
-    private void requestForDownload(OCFile file) {
+    /**
+     * Opens the image gallery showing the image {@link OCFile} received as parameter.
+     * 
+     * @param file                      Image {@link OCFile} to show.
+     */
+    public void startImagePreview(OCFile file) {
+        Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
+        showDetailsIntent.putExtra(EXTRA_FILE, file);
+        showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
+        startActivity(showDetailsIntent);
+    }
+
+    /**
+     * Stars the preview of an already down media {@link OCFile}.
+     * 
+     * @param file                      Media {@link OCFile} to preview.
+     * @param startPlaybackPosition     Media position where the playback will be started, in milliseconds.
+     * @param autoplay                  When 'true', the playback will start without user interactions.
+     */
+    public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay) {
+        Fragment mediaFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);
+        setSecondFragment(mediaFragment);
+        updateFragmentsVisibility(true);
+        updateNavigationElementsInActionBar(file);
+        setFile(file);
+    }
+
+    /**
+     * Requests the download of the received {@link OCFile} , updates the UI
+     * to monitor the download progress and prepares the activity to preview
+     * or open the file when the download finishes.
+     * 
+     * @param file          {@link OCFile} to download and preview.
+     */
+    public void startDownloadForPreview(OCFile file) {
+        Fragment detailFragment = new FileDetailFragment(file, getAccount());
+        setSecondFragment(detailFragment);
+        mWaitingToPreview = file;
+        requestForDownload();
+        updateFragmentsVisibility(true);
+        updateNavigationElementsInActionBar(file);
+        setFile(file);
+    }
+
+
+    public void cancelTransference(OCFile file) {
         Account account = getAccount();
-        if (!mDownloaderBinder.isDownloading(account, file)) {
-            Intent i = new Intent(this, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
-            i.putExtra(FileDownloader.EXTRA_FILE, file);
-            startService(i);
+        if (mDownloaderBinder != null && mDownloaderBinder.isDownloading(account, file)) {
+            mDownloaderBinder.cancel(account, file);
+            onTransferStateChanged(file, false, false);
+
+        } else if (mUploaderBinder != null && mUploaderBinder.isUploading(account, file)) {
+            mUploaderBinder.cancel(account, file);
+            if (!file.fileExists()) {
+                cleanSecondFragment();
+                
+            } else {
+                onTransferStateChanged(file, false, false);
+            }
         }
     }
     
-    private void sendDownloadedFile(){
-        getFileOperationsHelper().sendDownloadedFile(mWaitingToSend, this);
-        mWaitingToSend = null;
-    }
-    
 }

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

@@ -36,7 +36,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.ui.activity.TransferServiceGetter;
+import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.Log_OC;
 
@@ -55,14 +55,14 @@ public class FileListListAdapter extends CursorAdapter implements ListAdapter {
     private Context mContext;
     private FileDataStorageManager mStorageManager;
     private Account mAccount;
-    private TransferServiceGetter mTransferServiceGetter;
+    private ComponentsGetter mTransferServiceGetter;
     
 
-    public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {
+    public FileListListAdapter(Context context, ComponentsGetter componentsGetter) {
         super(context, null, FLAG_AUTO_REQUERY);
         mContext = context;
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
-        mTransferServiceGetter = transferServiceGetter;
+        mTransferServiceGetter = componentsGetter;
     }
 
     public void setStorageManager(FileDataStorageManager storageManager) {

+ 3 - 2
src/com/owncloud/android/ui/dialog/ShareLinkToDialog.java

@@ -143,8 +143,9 @@ public class ShareLinkToDialog  extends SherlockDialogFragment {
 
                             } else {
                                 // Create a new share resource
-                                FileOperationsHelper foh = new FileOperationsHelper();
-                                foh.shareFileWithLinkToApp(mFile, mIntent, (FileActivity)getSherlockActivity());
+                                FileOperationsHelper foh = 
+                                        new FileOperationsHelper((FileActivity)getSherlockActivity());
+                                foh.shareFileWithLinkToApp(mFile, mIntent);
                             }
                         }
         })

+ 29 - 222
src/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -23,13 +23,11 @@ import java.util.ArrayList;
 import java.util.List;
 
 import android.accounts.Account;
-import android.app.Activity;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.Bundle;
-import android.os.Handler;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -51,14 +49,6 @@ import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
-import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
-import com.owncloud.android.operations.RemoveFileOperation;
-import com.owncloud.android.operations.RenameFileOperation;
-import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
@@ -77,7 +67,7 @@ import com.owncloud.android.utils.Log_OC;
  */
 public class FileDetailFragment extends FileFragment implements
         OnClickListener, 
-        ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {
+        ConfirmationDialogFragment.ConfirmationDialogFragmentListener, EditNameDialogListener {
 
     private FileFragment.ContainerActivity mContainerActivity;
     
@@ -88,9 +78,6 @@ public class FileDetailFragment extends FileFragment implements
     private UploadFinishReceiver mUploadFinishReceiver;
     public ProgressListener mProgressListener;
     
-    private Handler mHandler;
-    private RemoteOperation mLastRemoteOperation;
-    
     private static final String TAG = FileDetailFragment.class.getSimpleName();
     public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
     
@@ -126,7 +113,6 @@ public class FileDetailFragment extends FileFragment implements
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        mHandler = new Handler();
         setHasOptionsMenu(true);
     }
     
@@ -146,7 +132,6 @@ public class FileDetailFragment extends FileFragment implements
         }
         
         View view = null;
-        //view = inflater.inflate(mLayout, container, false);
         view = inflater.inflate(mLayout, null);
         mView = view;
         
@@ -161,21 +146,6 @@ public class FileDetailFragment extends FileFragment implements
         return view;
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onAttach(Activity activity) {
-        super.onAttach(activity);
-        try {
-            mContainerActivity = (ContainerActivity) activity;
-            
-        } catch (ClassCastException e) {
-            throw new ClassCastException(activity.toString() + " must implement " + FileDetailFragment.ContainerActivity.class.getSimpleName());
-        }
-    }
-    
-    
     /**
      * {@inheritDoc}
      */
@@ -183,7 +153,7 @@ public class FileDetailFragment extends FileFragment implements
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         if (mAccount != null) {
-            OCFile file = ((FileActivity)getActivity()).getStorageManager().
+            OCFile file = mContainerActivity.getStorageManager().
                     getFileByPath(getFile().getRemotePath());
             if (file != null) {
                 setFile(file);
@@ -359,44 +329,43 @@ public class FileDetailFragment extends FileFragment implements
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_share_file: {
-                FileActivity activity = (FileActivity) getSherlockActivity();
-                activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity);
+                mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
                 return true;
             }
             case R.id.action_unshare_file: {
-                FileActivity activity = (FileActivity) getSherlockActivity();
-                activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
+                mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
                 return true;
             }
             case R.id.action_open_file_with: {
-                FileActivity activity = (FileActivity) getSherlockActivity();
-                activity.getFileOperationsHelper().openFile(getFile(), activity);
+                mContainerActivity.getFileOperationsHelper().openFile(getFile());
                 return true;
             }
             case R.id.action_remove_file: {
-                removeFile();
+                showDialogToRemoveFile();
                 return true;
             }
             case R.id.action_rename_file: {
-                renameFile();
+                showDialogToRenameFile();
                 return true;
             }
-            case R.id.action_download_file: 
             case R.id.action_cancel_download:
-            case R.id.action_cancel_upload:
+            case R.id.action_cancel_upload: {
+                ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile());
+                return true;
+            }
+            case R.id.action_download_file: 
             case R.id.action_sync_file: {
-                synchronizeFile();
+                mContainerActivity.getFileOperationsHelper().syncFile(getFile());
                 return true;
             }
             case R.id.action_send_file: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
                 // Obtain the file
                 if (!getFile().isDown()) {  // Download the file                    
                     Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded");
-                    activity.startDownloadForSending(getFile());
+                    ((FileDisplayActivity)mContainerActivity).startDownloadForSending(getFile());
                     
                 } else {
-                    activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity);
+                    ((FileDisplayActivity)mContainerActivity).getFileOperationsHelper().sendDownloadedFile(getFile());
                 }
                 return true;
             }
@@ -413,7 +382,7 @@ public class FileDetailFragment extends FileFragment implements
                 break;
             }
             case R.id.fdCancelBtn: {
-                synchronizeFile();
+                ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile());
                 break;
             }
             default:
@@ -426,7 +395,7 @@ public class FileDetailFragment extends FileFragment implements
         CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
         OCFile file = getFile();
         file.setKeepInSync(cb.isChecked());
-        ((FileActivity)getActivity()).getStorageManager().saveFile(file);
+        mContainerActivity.getStorageManager().saveFile(file);
         
         /// register the OCFile instance in the observer service to monitor local updates;
         /// if necessary, the file is download 
@@ -441,11 +410,11 @@ public class FileDetailFragment extends FileFragment implements
         getActivity().startService(intent);
         
         if (file.keepInSync()) {
-            synchronizeFile();   // force an immediate synchronization
+            mContainerActivity.getFileOperationsHelper().syncFile(getFile());
         }
     }
 
-    private void removeFile() {
+    private void showDialogToRemoveFile() {
         OCFile file = getFile();
         ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance(
                 R.string.confirmation_remove_alert,
@@ -458,7 +427,7 @@ public class FileDetailFragment extends FileFragment implements
     }
 
 
-    private void renameFile() {
+    private void showDialogToRenameFile() {
         OCFile file = getFile();
         String fileName = file.getFileName();
         int extensionStart = file.isFolder() ? -1 : fileName.lastIndexOf(".");
@@ -467,59 +436,13 @@ public class FileDetailFragment extends FileFragment implements
         dialog.show(getFragmentManager(), "nameeditdialog");
     }
 
-    private void synchronizeFile() {
-        OCFile file = getFile();
-        FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
-        FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
-            downloaderBinder.cancel(mAccount, file);
-            if (file.isDown()) {
-                setButtonsForDown();
-            } else {
-                setButtonsForRemote();
-            }
-
-        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
-            uploaderBinder.cancel(mAccount, file);
-            if (!file.fileExists()) {
-                // TODO make something better
-                ((FileDisplayActivity)getActivity()).cleanSecondFragment();
-                
-            } else if (file.isDown()) {
-                setButtonsForDown();
-            } else {
-                setButtonsForRemote();
-            }
-            
-        } else {
-            mLastRemoteOperation = new SynchronizeFileOperation(
-                    file, 
-                    null, 
-                    ((FileActivity)getActivity()).getStorageManager(), 
-                    mAccount, 
-                    true, 
-                    getActivity());
-            mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            
-            // update ui 
-            ((FileActivity) getActivity()).showLoadingDialog();
-            
-        }
-    }
-
+    
     @Override
     public void onConfirmation(String callerTag) {
         OCFile file = getFile();
         if (callerTag.equals(FTAG_CONFIRMATION)) {
-            FileDataStorageManager storageManager =
-                    ((FileActivity)getActivity()).getStorageManager();
-            if (storageManager.getFileById(file.getFileId()) != null) {
-                mLastRemoteOperation = new RemoveFileOperation( file, 
-                                                                true, 
-                                                                storageManager);
-                mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-                                
-                ((FileActivity) getActivity()).showLoadingDialog();
+            if (mContainerActivity.getStorageManager().getFileById(file.getFileId()) != null) {
+                mContainerActivity.getFileOperationsHelper().removeFile(file, true);
             }
         }
     }
@@ -527,7 +450,7 @@ public class FileDetailFragment extends FileFragment implements
     @Override
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
-        ((FileActivity)getActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
+        mContainerActivity.getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         if (file.getStoragePath() != null) {
             file.setStoragePath(null);
             updateFileDetails(file, mAccount);
@@ -557,13 +480,6 @@ public class FileDetailFragment extends FileFragment implements
      */
     public void updateFileDetails(OCFile file, Account ocAccount) {
         setFile(file);
-        FileDataStorageManager storageManager = ((FileActivity)getActivity()).getStorageManager();
-        if (ocAccount != null && ( 
-                storageManager == null || 
-                (mAccount != null && !mAccount.equals(ocAccount))
-           )) {
-            storageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
-        }
         mAccount = ocAccount;
         updateFileDetails(false, false);
     }
@@ -579,13 +495,12 @@ public class FileDetailFragment extends FileFragment implements
      *                          although {@link FileDownloaderBinder#isDownloading(Account, OCFile)}  and 
      *                          {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
      *                          
-     * @param refresh           If 'true', try to refresh the hold file from the database
+     * @param refresh           If 'true', try to refresh the whole file from the database
      */
     public void updateFileDetails(boolean transferring, boolean refresh) {
 
         if (readyToShow()) {
-            FileDataStorageManager storageManager = 
-                    ((FileActivity)getActivity()).getStorageManager();
+            FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
             if (refresh && storageManager != null) {
                 setFile(storageManager.getFileByPath(getFile().getRemotePath()));
             }
@@ -605,7 +520,6 @@ public class FileDetailFragment extends FileFragment implements
             cb.setChecked(file.keepInSync());
 
             // configure UI for depending upon local state of the file
-            //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
             if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
@@ -787,7 +701,7 @@ public class FileDetailFragment extends FileFragment implements
                 if (getFile().getRemotePath().equals(uploadRemotePath) ||
                     renamedInUpload) {
                     if (uploadWasFine) {
-                        setFile(((FileActivity)getActivity()).getStorageManager().getFileByPath(uploadRemotePath));
+                        setFile(mContainerActivity.getStorageManager().getFileByPath(uploadRemotePath));
                     }
                     if (renamedInUpload) {
                         String newName = (new File(uploadRemotePath)).getName();
@@ -800,7 +714,7 @@ public class FileDetailFragment extends FileFragment implements
                    
                     // Force the preview if the file is an image
                     if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
-                        ((FileDisplayActivity) mContainerActivity).startImagePreview(getFile());
+                        ((FileDisplayActivity)mContainerActivity).startImagePreview(getFile());
                     } 
                 }
             }
@@ -812,118 +726,11 @@ public class FileDetailFragment extends FileFragment implements
         if (dialog.getResult()) {
             String newFilename = dialog.getNewFilename();
             Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
-            mLastRemoteOperation = new RenameFileOperation( getFile(), 
-                                                            mAccount, 
-                                                            newFilename, 
-                                                            new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
-            mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            ((FileActivity) getActivity()).showLoadingDialog();
+            mContainerActivity.getFileOperationsHelper().renameFile(getFile(), newFilename);
         }
     }
     
     
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
-        if (operation.equals(mLastRemoteOperation)) {
-            if (operation instanceof RemoveFileOperation) {
-                onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
-                
-            } else if (operation instanceof RenameFileOperation) {
-                onRenameFileOperationFinish((RenameFileOperation)operation, result);
-                
-            } else if (operation instanceof SynchronizeFileOperation) {
-                onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result);
-            }
-        }
-    }
-    
-    
-    private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((FileActivity) getActivity()).dismissLoadingDialog();
-        if (result.isSuccess()) {
-            Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
-            msg.show();
-            ((FileDisplayActivity)getActivity()).cleanSecondFragment();
-
-        } else {
-            Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
-            msg.show();
-            if (result.isSslRecoverableException()) {
-                // TODO show the SSL warning dialog
-            }
-        }
-    }
-    
-    private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
-        ((FileActivity) getActivity()).dismissLoadingDialog();
-        
-        if (result.isSuccess()) {
-            updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
-            /* TODO WIP COMMENT 
-            mContainerActivity.onFileStateChanged();
-            */
-            
-        } else {
-            if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
-                Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); 
-                msg.show();
-                // TODO throw again the new rename dialog
-            } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
-                Toast msg = Toast.makeText(getActivity(), R.string.filename_forbidden_characters, Toast.LENGTH_LONG);
-                msg.show();
-            } else {
-                Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); 
-                msg.show();
-                if (result.isSslRecoverableException()) {
-                    // TODO show the SSL warning dialog
-                }
-            }
-        }
-    }
-    
-    private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
-        ((FileActivity) getActivity()).dismissLoadingDialog();
-        OCFile file = getFile();
-        if (!result.isSuccess()) {
-            if (result.getCode() == ResultCode.SYNC_CONFLICT) {
-                Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
-                i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
-                i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
-                startActivity(i);
-                
-            } 
-            
-            if (file.isDown()) {
-                setButtonsForDown();
-                
-            } else {
-                setButtonsForRemote();
-            }
-            
-        } else {
-            if (operation.transferWasRequested()) {
-                setButtonsForTransferring();
-                /* TODO WIP COMMENT 
-                mContainerActivity.onFileStateChanged();    // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so 
-                                                            // checking the service to see if the file is downloading results in FALSE
-                 */
-            } else {
-                Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); 
-                msg.show();
-                if (file.isDown()) {
-                    setButtonsForDown();
-                    
-                } else {
-                    setButtonsForRemote();
-                }
-            }
-        }
-    }
-    
-
     public void listenForTransferProgress() {
         if (mProgressListener != null) {
             if (mContainerActivity.getFileDownloaderBinder() != null) {

+ 72 - 11
src/com/owncloud/android/ui/fragment/FileFragment.java

@@ -17,11 +17,15 @@
 
 package com.owncloud.android.ui.fragment;
 
+import android.accounts.Account;
+import android.app.Activity;
 import android.support.v4.app.Fragment;
 
 import com.actionbarsherlock.app.SherlockFragment;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.ui.activity.TransferServiceGetter;
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
+import com.owncloud.android.ui.activity.ComponentsGetter;
 
 
 /**
@@ -33,6 +37,8 @@ import com.owncloud.android.ui.activity.TransferServiceGetter;
 public class FileFragment extends SherlockFragment {
     
     private OCFile mFile;
+    
+    protected ContainerActivity mContainerActivity;
 
 
     /**
@@ -66,14 +72,75 @@ public class FileFragment extends SherlockFragment {
     protected void setFile(OCFile file) {
         mFile = file;
     }
-
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onAttach(Activity activity) {
+        super.onAttach(activity);
+        try {
+            mContainerActivity = (ContainerActivity) activity;
+            
+        } catch (ClassCastException e) {
+            throw new ClassCastException(activity.toString() + " must implement " + ContainerActivity.class.getSimpleName());
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onDetach() {
+        mContainerActivity = null;
+        super.onDetach();
+    }    
+    
+    
     /**
+     * Interface to implement by any Activity that includes some instance of FileListFragment
      * Interface to implement by any Activity that includes some instance of FileFragment
      * 
      * @author David A. Velasco
      */
-    public interface ContainerActivity extends TransferServiceGetter {
+    public interface ContainerActivity extends ComponentsGetter {
+
+        /**
+         * Request the parent activity to show the details of an {@link OCFile}.
+         * 
+         * @param file      File to show details
+         */
+        public void showDetails(OCFile file);
 
+        
+        ///// TO UNIFY IN A SINGLE CALLBACK METHOD - EVENT NOTIFICATIONs  -> something happened inside the fragment, MAYBE activity is interested --> unify in notification method
+        /**
+         * Callback method invoked when a the user browsed into a different folder through the list of files
+         *  
+         * @param file
+         */
+        public void onBrowsedDownTo(OCFile folder);                 
+
+        /**
+         * Callback method invoked when a the 'transfer state' of a file changes.
+         * 
+         * This happens when a download or upload is started or ended for a file.
+         * 
+         * This method is necessary by now to update the user interface of the double-pane layout in tablets
+         * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
+         * won't provide the needed response before the method where this is called finishes. 
+         * 
+         * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
+         * 
+         * @param file          OCFile which state changed.
+         * @param downloading   Flag signaling if the file is now downloading.
+         * @param uploading     Flag signaling if the file is now uploading.
+         */
+        public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading); 
+
+        
         /**
          * Callback method invoked when the detail fragment wants to notice its container 
          * activity about a relevant state the file shown by the fragment.
@@ -88,13 +155,7 @@ public class FileFragment extends SherlockFragment {
          */
         public void onFileStateChanged();
 
-        /**
-         * Request the parent activity to show the details of an {@link OCFile}.
-         * 
-         * @param file      File to show details
-         */
-        public void showDetails(OCFile file);
-
+        
     }
-    
+
 }

+ 39 - 111
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -29,15 +29,9 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.operations.RemoveFileOperation;
-import com.owncloud.android.operations.RenameFileOperation;
-import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.ExtendedListView;
-import com.owncloud.android.ui.activity.TransferServiceGetter;
 import com.owncloud.android.ui.adapter.FileListListAdapter;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
@@ -51,7 +45,6 @@ import android.app.Activity;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.Handler;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
@@ -65,8 +58,11 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
 /**
  * A Fragment that lists all files and folders in a given path.
  * 
- * @author Bartek Przybylski
+ * TODO refactorize to get rid of direct dependency on FileDisplayActivity
  * 
+ * @author Bartek Przybylski
+ * @author masensio
+ * @author David A. Velasco
  */
 public class OCFileListFragment extends ExtendedListFragment 
         implements EditNameDialogListener, ConfirmationDialogFragmentListener, 
@@ -84,14 +80,13 @@ public class OCFileListFragment extends ExtendedListFragment
     
     private static final int LOADER_ID = 0;
     
-    private OCFileListFragment.ContainerActivity mContainerActivity;
+    private FileFragment.ContainerActivity mContainerActivity;
     
     private OCFile mFile = null;
     private FileListListAdapter mAdapter;
     private LoaderManager mLoaderManager;
     private FileListCursorLoader  mCursorLoader;
     
-    private Handler mHandler;
     private OCFile mTargetFile;
 
     // Save the state of the scroll in browsing
@@ -109,12 +104,19 @@ public class OCFileListFragment extends ExtendedListFragment
         super.onAttach(activity);
         Log_OC.e(TAG, "onAttach");
         try {
-            mContainerActivity = (ContainerActivity) activity;
+            mContainerActivity = (FileFragment.ContainerActivity) activity;
         } catch (ClassCastException e) {
-            throw new ClassCastException(activity.toString() + " must implement " + OCFileListFragment.ContainerActivity.class.getSimpleName());
+            throw new ClassCastException(activity.toString() + " must implement " + 
+                    FileFragment.ContainerActivity.class.getSimpleName());
         }
     }
 
+    
+    @Override
+    public void onDetach() {
+        mContainerActivity = null;
+        super.onDetach();
+    }
 
     /**
      * {@inheritDoc}
@@ -150,9 +152,6 @@ public class OCFileListFragment extends ExtendedListFragment
         registerForContextMenu(getListView());
         getListView().setOnCreateContextMenuListener(this);
         
-        mHandler = new Handler();
-        
-
     }
     
     /**
@@ -181,8 +180,7 @@ public class OCFileListFragment extends ExtendedListFragment
         int moveCount = 0;
         
         if(mFile != null){
-            FileDataStorageManager storageManager = 
-                    ((FileActivity)getSherlockActivity()).getStorageManager();
+            FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
             
             String parentPath = null;
             if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
@@ -205,7 +203,7 @@ public class OCFileListFragment extends ExtendedListFragment
         if (mFile != null) {
             listDirectory(mFile);
 
-            mContainerActivity.startSyncFolderOperation(mFile);
+            ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
             
             // restore index and top position
             restoreIndexAndTopPosition();
@@ -272,7 +270,7 @@ public class OCFileListFragment extends ExtendedListFragment
     
     @Override
     public void onItemClick(AdapterView<?> l, View v, int position, long id) {
-        OCFile file = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+        OCFile file = mContainerActivity.getStorageManager().createFileInstance(
                 (Cursor) mAdapter.getItem(position));
         if (file != null) {
             if (file.isFolder()) { 
@@ -286,20 +284,19 @@ public class OCFileListFragment extends ExtendedListFragment
             } else { /// Click on a file
                 if (PreviewImageFragment.canBePreviewed(file)) {
                     // preview image - it handles the download, if needed
-                    mContainerActivity.startImagePreview(file);
+                    ((FileDisplayActivity)mContainerActivity).startImagePreview(file);
                     
                 } else if (file.isDown()) {
                     if (PreviewMediaFragment.canBePreviewed(file)) {
                         // media preview
-                        mContainerActivity.startMediaPreview(file, 0, true);
+                        ((FileDisplayActivity)mContainerActivity).startMediaPreview(file, 0, true);
                     } else {
-                        FileActivity activity = (FileActivity) getSherlockActivity();
-                        activity.getFileOperationsHelper().openFile(file, activity);
+                        ((FileDisplayActivity)mContainerActivity).getFileOperationsHelper().openFile(file);
                     }
                     
                 } else {
                     // automatic download, preview on finish
-                    mContainerActivity.startDownloadForPreview(file);
+                    ((FileDisplayActivity)mContainerActivity).startDownloadForPreview(file);
                 }
                     
             }
@@ -319,7 +316,7 @@ public class OCFileListFragment extends ExtendedListFragment
         MenuInflater inflater = getSherlockActivity().getMenuInflater();
         inflater.inflate(R.menu.file_actions_menu, menu);
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
-        OCFile targetFile = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+        OCFile targetFile = mContainerActivity.getStorageManager().createFileInstance(
                 (Cursor) mAdapter.getItem(info.position));
         List<Integer> toHide = new ArrayList<Integer>();    
         List<Integer> toDisable = new ArrayList<Integer>();  
@@ -405,17 +402,15 @@ public class OCFileListFragment extends ExtendedListFragment
     @Override
     public boolean onContextItemSelected (MenuItem item) {
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();        
-        mTargetFile = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+        mTargetFile = mContainerActivity.getStorageManager().createFileInstance(
                 (Cursor) mAdapter.getItem(info.position));
         switch (item.getItemId()) {                
             case R.id.action_share_file: {
-                FileActivity activity = (FileActivity) getSherlockActivity();
-                activity.getFileOperationsHelper().shareFileWithLink(mTargetFile, activity);
+                mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile);
                 return true;
             }
             case R.id.action_unshare_file: {
-                FileActivity activity = (FileActivity) getSherlockActivity();
-                activity.getFileOperationsHelper().unshareFileWithLink(mTargetFile, activity);
+                mContainerActivity.getFileOperationsHelper().unshareFileWithLink(mTargetFile);
                 return true;
             }
             case R.id.action_rename_file: {
@@ -449,16 +444,7 @@ public class OCFileListFragment extends ExtendedListFragment
                 return true;
             }
             case R.id.action_sync_file: {
-                Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
-                RemoteOperation operation = new SynchronizeFileOperation(
-                        mTargetFile, 
-                        null, 
-                        ((FileActivity)getSherlockActivity()).getStorageManager(), 
-                        account, 
-                        true, 
-                        getSherlockActivity());
-                operation.execute(account, getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-                ((FileActivity) getSherlockActivity()).showLoadingDialog();
+                mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile);
                 return true;
             }
             case R.id.action_cancel_download: {
@@ -482,19 +468,17 @@ public class OCFileListFragment extends ExtendedListFragment
                 return true;
             }
             case R.id.action_see_details: {
-                ((FileFragment.ContainerActivity)getSherlockActivity()).showDetails(mTargetFile);
+                mContainerActivity.showDetails(mTargetFile);
                 return true;
             }
             case R.id.action_send_file: {
                 // Obtain the file
                 if (!mTargetFile.isDown()) {  // Download the file
                     Log_OC.d(TAG, mTargetFile.getRemotePath() + " : File must be downloaded");
-                    mContainerActivity.startDownloadForSending(mTargetFile);
+                    ((FileDisplayActivity)mContainerActivity).startDownloadForSending(mTargetFile);
                     
                 } else {
-                
-                    FileActivity activity = (FileActivity) getSherlockActivity();
-                    activity.getFileOperationsHelper().sendDownloadedFile(mTargetFile, activity);
+                    ((FileDisplayActivity)mContainerActivity).getFileOperationsHelper().sendDownloadedFile(mTargetFile);
                 }
                 return true;
             }
@@ -528,7 +512,7 @@ public class OCFileListFragment extends ExtendedListFragment
      * @param directory File to be listed
      */
     public void listDirectory(OCFile directory) {
-        FileDataStorageManager storageManager = ((FileActivity)getSherlockActivity()).getStorageManager();
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
         if (storageManager != null) {
 
             // Check input parameters for null
@@ -588,63 +572,12 @@ public class OCFileListFragment extends ExtendedListFragment
     }
     
     
-    /**
-     * Interface to implement by any Activity that includes some instance of FileListFragment
-     * 
-     * @author David A. Velasco
-     */
-    public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener {
-
-        /**
-         * Callback method invoked when a the user browsed into a different folder through the list of files
-         *  
-         * @param file
-         */
-        public void onBrowsedDownTo(OCFile folder);
-
-        public void startDownloadForPreview(OCFile file);
-
-        public void startMediaPreview(OCFile file, int i, boolean b);
-
-        public void startImagePreview(OCFile file);
-        
-        public void startSyncFolderOperation(OCFile folder);
-
-        /**
-         * Callback method invoked when a the 'transfer state' of a file changes.
-         * 
-         * This happens when a download or upload is started or ended for a file.
-         * 
-         * This method is necessary by now to update the user interface of the double-pane layout in tablets
-         * because methods {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link FileUploaderBinder#isUploading(Account, OCFile)}
-         * won't provide the needed response before the method where this is called finishes. 
-         * 
-         * TODO Remove this when the transfer state of a file is kept in the database (other thing TODO)
-         * 
-         * @param file          OCFile which state changed.
-         * @param downloading   Flag signaling if the file is now downloading.
-         * @param uploading     Flag signaling if the file is now uploading.
-         */
-        public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
-
-        public void startDownloadForSending(OCFile file);
-        
-    }
-    
-    
     @Override
     public void onDismiss(EditNameDialog dialog) {
         if (dialog.getResult()) {
             String newFilename = dialog.getNewFilename();
             Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
-            RemoteOperation operation = 
-                    new RenameFileOperation(
-                            mTargetFile, 
-                            AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), 
-                            newFilename, 
-                            ((FileActivity)getSherlockActivity()).getStorageManager());
-            operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-            ((FileActivity) getSherlockActivity()).showLoadingDialog();
+            mContainerActivity.getFileOperationsHelper().renameFile(mTargetFile, newFilename);
         }
     }
 
@@ -652,22 +585,16 @@ public class OCFileListFragment extends ExtendedListFragment
     @Override
     public void onConfirmation(String callerTag) {
         if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
-            FileDataStorageManager storageManager = 
-                    ((FileActivity)getSherlockActivity()).getStorageManager();
+            FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
             if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
-                RemoteOperation operation = new RemoveFileOperation( mTargetFile, 
-                                                                    true, 
-                                                                    storageManager);
-                operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-                
-                ((FileActivity) getSherlockActivity()).showLoadingDialog();
+                mContainerActivity.getFileOperationsHelper().removeFile(mTargetFile, true);
             }
         }
     }
     
     @Override
     public void onNeutral(String callerTag) {
-        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(mTargetFile, false, true);    // TODO perform in background task / new thread
+        mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true);    // TODO perform in background task / new thread
         listDirectory();
         mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
     }
@@ -687,8 +614,9 @@ public class OCFileListFragment extends ExtendedListFragment
     @Override
     public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
         Log_OC.d(TAG, "onCreateLoader start");
-        mCursorLoader = new FileListCursorLoader((FileActivity)getSherlockActivity(), 
-                ((FileActivity)getSherlockActivity()).getStorageManager());
+        mCursorLoader = new FileListCursorLoader(
+                getSherlockActivity(), 
+                mContainerActivity.getStorageManager());
         if (mFile != null) {
             mCursorLoader.setParentId(mFile.getFileId());
         } else {
@@ -706,7 +634,7 @@ public class OCFileListFragment extends ExtendedListFragment
     public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
         Log_OC.d(TAG, "onLoadFinished start");
         
-        FileDataStorageManager storageManager = ((FileActivity)getSherlockActivity()).getStorageManager();
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
         if (storageManager != null)  {
             mCursorLoader.setStorageManager(storageManager);
             if (mFile != null) {

+ 0 - 16
src/com/owncloud/android/ui/preview/FileDownloadFragment.java

@@ -26,7 +26,6 @@ import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.Log_OC;
 
 import android.accounts.Account;
-import android.app.Activity;
 import android.os.Bundle;
 import android.support.v4.app.FragmentStatePagerAdapter;
 import android.view.LayoutInflater;
@@ -139,21 +138,6 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
     }
     
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onAttach(Activity activity) {
-        super.onAttach(activity);
-        try {
-            mContainerActivity = (ContainerActivity) activity;
-            
-        } catch (ClassCastException e) {
-            throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName());
-        }
-    }
-    
-    
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);

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

@@ -47,6 +47,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.operations.CreateShareOperation;
+import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
@@ -61,7 +62,9 @@ import com.owncloud.android.utils.Log_OC;
  *  
  *  @author David A. Velasco
  */
-public class PreviewImageActivity extends FileActivity implements FileFragment.ContainerActivity, ViewPager.OnPageChangeListener, OnTouchListener , OnRemoteOperationListener{
+public class PreviewImageActivity extends FileActivity implements 
+FileFragment.ContainerActivity, OnTouchListener,  
+ViewPager.OnPageChangeListener, OnRemoteOperationListener {
     
     public static final int DIALOG_SHORT_WAIT = 0;
 
@@ -73,10 +76,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     private ViewPager mViewPager; 
     private PreviewImagePagerAdapter mPreviewImagePagerAdapter;    
     
-    private FileDownloaderBinder mDownloaderBinder = null;
-    private ServiceConnection mDownloadConnection, mUploadConnection = null;
-    private FileUploaderBinder mUploaderBinder = null;
-
     private boolean mRequestWaitingForBinder;
     
     private DownloadFinishReceiver mDownloadFinishReceiver;
@@ -135,10 +134,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     @Override
     public void onStart() {
         super.onStart();
-        mDownloadConnection = new PreviewImageServiceConnection();
-        bindService(new Intent(this, FileDownloader.class), mDownloadConnection, Context.BIND_AUTO_CREATE);
-        mUploadConnection = new PreviewImageServiceConnection();
-        bindService(new Intent(this, FileUploader.class), mUploadConnection, Context.BIND_AUTO_CREATE);
     }
     
     @Override
@@ -157,6 +152,8 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         } else if (operation instanceof UnshareLinkOperation) {
             onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
             
+        } else if (operation instanceof RemoveFileOperation) {
+            finish();
         }
     }
     
@@ -183,7 +180,12 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
             invalidateOptionsMenu();
         }
     }
-    
+
+    @Override
+    protected ServiceConnection newTransferenceServiceConnection() {
+        return new PreviewImageServiceConnection();
+    }
+
     /** Defines callbacks for service binding, passed to bindService() */
     private class PreviewImageServiceConnection implements ServiceConnection {
 
@@ -223,14 +225,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     @Override
     public void onStop() {
         super.onStop();
-        if (mDownloadConnection != null) {
-            unbindService(mDownloadConnection);
-            mDownloadConnection = null;
-        }
-        if (mUploadConnection != null) {
-            unbindService(mUploadConnection);
-            mUploadConnection = null;
-        }
     }
     
     
@@ -285,30 +279,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         finish();
     }
     
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onFileStateChanged() {
-        // nothing to do here!
-    }
-
-    
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public FileDownloaderBinder getFileDownloaderBinder() {
-        return mDownloaderBinder;
-    }
-
-
-    @Override
-    public FileUploaderBinder getFileUploaderBinder() {
-        return mUploaderBinder;
-    }
-
-
     @Override
     public void showDetails(OCFile file) {
         Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
@@ -487,4 +457,25 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
         }
     }
 
+    @Override
+    public void onBrowsedDownTo(OCFile folder) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void onFileStateChanged() {
+        // nothing to do here!
+    }
+
+    
 }

+ 19 - 116
src/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -24,27 +24,21 @@ import java.util.List;
 import android.accounts.Account;
 import android.annotation.SuppressLint;
 import android.app.Activity;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.BitmapFactory.Options;
 import android.graphics.Point;
-import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
-import android.os.Handler;
 import android.support.v4.app.FragmentStatePagerAdapter;
 import android.view.Display;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnTouchListener;
 import android.view.ViewGroup;
-import android.webkit.MimeTypeMap;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
@@ -52,12 +46,6 @@ import com.actionbarsherlock.view.MenuItem;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.common.network.WebdavUtils;
-import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.RemoveFileOperation;
-import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.Log_OC;
@@ -72,8 +60,8 @@ import com.owncloud.android.utils.Log_OC;
  * 
  * @author David A. Velasco
  */
-public class PreviewImageFragment extends FileFragment implements   OnRemoteOperationListener, 
-                                                                        ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
+public class PreviewImageFragment extends FileFragment implements 
+ConfirmationDialogFragment.ConfirmationDialogFragmentListener {
     public static final String EXTRA_FILE = "FILE";
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
 
@@ -85,13 +73,12 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
 
     public Bitmap mBitmap = null;
     
-    private Handler mHandler;
-    private RemoteOperation mLastRemoteOperation;
-    
     private static final String TAG = PreviewImageFragment.class.getSimpleName();
 
     private boolean mIgnoreFirstSavedState;
 
+    private FileFragment.ContainerActivity mContainerActivity;
+
     
     /**
      * Creates a fragment to preview an image.
@@ -129,7 +116,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        mHandler = new Handler();
         setHasOptionsMenu(true);
     }
     
@@ -144,7 +130,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
         mView = inflater.inflate(R.layout.preview_image_fragment, container, false);
         mImageView = (ImageView)mView.findViewById(R.id.image);
         mImageView.setVisibility(View.GONE);
-        mView.setOnTouchListener((OnTouchListener)getActivity());   // WATCH OUT THAT CAST
+        mView.setOnTouchListener((OnTouchListener)getActivity());
         mMessageView = (TextView)mView.findViewById(R.id.message);
         mMessageView.setVisibility(View.GONE);
         mProgressWheel = (ProgressBar)mView.findViewById(R.id.progressWheel);
@@ -159,8 +145,10 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public void onAttach(Activity activity) {
         super.onAttach(activity);
-        if (!(activity instanceof FileFragment.ContainerActivity))
-            throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName());
+        if (!(activity instanceof OnTouchListener)) {
+            throw new ClassCastException(activity.toString() + 
+                    " must implement " + OnTouchListener.class.getSimpleName());
+        }
     }
     
     
@@ -177,8 +165,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                 
                 // Update the file
                 if (mAccount!= null) {
-                    OCFile updatedFile = ((FileActivity)getSherlockActivity()).
-                            getStorageManager().getFileByPath(file.getRemotePath());
+                    OCFile updatedFile = mContainerActivity.getStorageManager().getFileByPath(file.getRemotePath());
                     if (updatedFile != null) {
                         setFile(updatedFile);
                     } else {
@@ -271,8 +258,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
         
         MenuItem item = menu.findItem(R.id.action_unshare_file);
         // Options shareLink
-        OCFile file = ((FileActivity) getSherlockActivity()).getFile();
-        if (!file.isShareByLink()) {
+        if (!getFile().isShareByLink()) {
             item.setVisible(false);
             item.setEnabled(false);
         } else {
@@ -291,13 +277,11 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_share_file: {
-                FileActivity act = (FileActivity)getSherlockActivity();
-                act.getFileOperationsHelper().shareFileWithLink(getFile(), act);
+                mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
                 return true;
             }
             case R.id.action_unshare_file: {
-                FileActivity act = (FileActivity)getSherlockActivity();
-                act.getFileOperationsHelper().unshareFileWithLink(getFile(), act);
+                mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
                 return true;
             }
             case R.id.action_open_file_with: {
@@ -313,8 +297,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                 return true;
             }
             case R.id.action_send_file: {
-                FileActivity act = (FileActivity)getSherlockActivity();
-                act.getFileOperationsHelper().sendDownloadedFile(getFile(), act);
+                mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
                 return true;
             }
             
@@ -325,7 +308,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     
 
     private void seeDetails() {
-        ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());        
+        mContainerActivity.showDetails(getFile());        
     }
 
 
@@ -352,56 +335,9 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     
     /**
      * Opens the previewed image with an external application.
-     * 
-     * TODO - improve this; instead of prioritize the actions available for the MIME type in the server, 
-     * we should get a list of available apps for MIME tpye in the server and join it with the list of 
-     * available apps for the MIME type known from the file extension, to let the user choose
      */
     private void openFile() {
-        OCFile file = getFile();
-        String storagePath = file.getStoragePath();
-        String encodedStoragePath = WebdavUtils.encodePath(storagePath);
-        try {
-            Intent i = new Intent(Intent.ACTION_VIEW);
-            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
-            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-            startActivity(i);
-            
-        } catch (Throwable t) {
-            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
-            boolean toastIt = true; 
-            String mimeType = "";
-            try {
-                Intent i = new Intent(Intent.ACTION_VIEW);
-                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                if (mimeType == null || !mimeType.equals(file.getMimetype())) {
-                    if (mimeType != null) {
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
-                    } else {
-                        // desperate try
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*-/*");
-                    }
-                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                    startActivity(i);
-                    toastIt = false;
-                }
-                
-            } catch (IndexOutOfBoundsException e) {
-                Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
-                
-            } catch (ActivityNotFoundException e) {
-                Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
-                
-            } catch (Throwable th) {
-                Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
-                
-            } finally {
-                if (toastIt) {
-                    Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
-                }
-            }
-            
-        }
+        mContainerActivity.getFileOperationsHelper().openFile(getFile());
         finish();
     }
     
@@ -429,15 +365,9 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
      */
     @Override
     public void onConfirmation(String callerTag) {
-        FileDataStorageManager storageManager = 
-                ((FileActivity)getSherlockActivity()).getStorageManager();
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
         if (storageManager.getFileById(getFile().getFileId()) != null) {   // check that the file is still there;
-            mLastRemoteOperation = new RemoveFileOperation( getFile(),      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
-                                                            true, 
-                                                            storageManager);
-            mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            
-            ((FileActivity) getActivity()).showLoadingDialog();
+            mContainerActivity.getFileOperationsHelper().removeFile(getFile(), true);
         }
     }
     
@@ -448,7 +378,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
-        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
+        mContainerActivity.getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         finish();
     }
     
@@ -644,33 +574,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     }
 
     
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
-        if (operation.equals(mLastRemoteOperation) && operation instanceof RemoveFileOperation) {
-            onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
-        }
-    }
-    
-    private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((FileActivity) getActivity()).dismissLoadingDialog();
-        
-        if (result.isSuccess()) {
-            Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
-            msg.show();
-            finish();
-                
-        } else {
-            Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
-            msg.show();
-            if (result.isSslRecoverableException()) {
-                // TODO show the SSL warning dialog
-            }
-        }
-    }
-
     /**
      * Finishes the preview
      */

+ 11 - 118
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -22,7 +22,6 @@ import java.util.List;
 import android.accounts.Account;
 import android.app.Activity;
 import android.app.AlertDialog;
-import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -33,17 +32,14 @@ import android.media.MediaPlayer;
 import android.media.MediaPlayer.OnCompletionListener;
 import android.media.MediaPlayer.OnErrorListener;
 import android.media.MediaPlayer.OnPreparedListener;
-import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Handler;
 import android.os.IBinder;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.View.OnTouchListener;
 import android.view.ViewGroup;
-import android.webkit.MimeTypeMap;
 import android.widget.ImageView;
 import android.widget.Toast;
 import android.widget.VideoView;
@@ -57,11 +53,6 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.media.MediaControlView;
 import com.owncloud.android.media.MediaService;
 import com.owncloud.android.media.MediaServiceBinder;
-import com.owncloud.android.lib.common.network.WebdavUtils;
-import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
@@ -79,7 +70,7 @@ import com.owncloud.android.utils.Log_OC;
  */
 public class PreviewMediaFragment extends FileFragment implements
         OnTouchListener,  
-        ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener  {
+        ConfirmationDialogFragment.ConfirmationDialogFragmentListener  {
 
     public static final String EXTRA_FILE = "FILE";
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
@@ -92,9 +83,6 @@ public class PreviewMediaFragment extends FileFragment implements
     private VideoView mVideoPreview;
     private int mSavedPlaybackPosition;
     
-    private Handler mHandler;
-    private RemoteOperation mLastRemoteOperation;
-    
     private MediaServiceBinder mMediaServiceBinder = null;
     private MediaControlView mMediaController = null;
     private MediaServiceConnection mMediaServiceConnection = null;
@@ -102,6 +90,8 @@ public class PreviewMediaFragment extends FileFragment implements
     private boolean mAutoplay;
     public boolean mPrepared;
     
+    private FileFragment.ContainerActivity mContainerActivity;
+
     private static final String TAG = PreviewMediaFragment.class.getSimpleName();
 
     
@@ -142,7 +132,6 @@ public class PreviewMediaFragment extends FileFragment implements
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        mHandler = new Handler();
         setHasOptionsMenu(true);
     }
     
@@ -169,19 +158,6 @@ public class PreviewMediaFragment extends FileFragment implements
     }
     
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onAttach(Activity activity) {
-        super.onAttach(activity);
-        Log_OC.e(TAG, "onAttach");
-        
-        if (!(activity instanceof FileFragment.ContainerActivity))
-            throw new ClassCastException(activity.toString() + " must implement " + FileFragment.ContainerActivity.class.getSimpleName());
-    }
-    
-    
     /**
      * {@inheritDoc}
      */
@@ -373,27 +349,24 @@ public class PreviewMediaFragment extends FileFragment implements
     
     private void unshareFileWithLink() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)getSherlockActivity();
-        activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
+        mContainerActivity.getFileOperationsHelper().unshareFileWithLink(getFile());
     }
     
     private void shareFileWithLink() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)getSherlockActivity();
-        activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity);
+        mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
         
     }
 
     private void sendFile() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)getSherlockActivity();
-        activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity);
+        mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
         
     }
 
     private void seeDetails() {
         stopPreview(false);
-        ((FileFragment.ContainerActivity)getSherlockActivity()).showDetails(getFile());        
+        mContainerActivity.showDetails(getFile());        
     }
 
 
@@ -643,57 +616,10 @@ public class PreviewMediaFragment extends FileFragment implements
 
     /**
      * Opens the previewed file with an external application.
-     * 
-     * TODO - improve this; instead of prioritize the actions available for the MIME type in the server, 
-     * we should get a list of available apps for MIME tpye in the server and join it with the list of 
-     * available apps for the MIME type known from the file extension, to let the user choose
      */
     private void openFile() {
-        OCFile file = getFile();
         stopPreview(true);
-        String storagePath = file.getStoragePath();
-        String encodedStoragePath = WebdavUtils.encodePath(storagePath);
-        try {
-            Intent i = new Intent(Intent.ACTION_VIEW);
-            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype());
-            i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-            startActivity(i);
-            
-        } catch (Throwable t) {
-            Log_OC.e(TAG, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file.getMimetype());
-            boolean toastIt = true; 
-            String mimeType = "";
-            try {
-                Intent i = new Intent(Intent.ACTION_VIEW);
-                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
-                if (mimeType == null || !mimeType.equals(file.getMimetype())) {
-                    if (mimeType != null) {
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);
-                    } else {
-                        // desperate try
-                        i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*-/*");
-                    }
-                    i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-                    startActivity(i);
-                    toastIt = false;
-                }
-                
-            } catch (IndexOutOfBoundsException e) {
-                Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + storagePath);
-                
-            } catch (ActivityNotFoundException e) {
-                Log_OC.e(TAG, "No activity found to handle: " + storagePath + " with MIME type " + mimeType + " obtained from extension");
-                
-            } catch (Throwable th) {
-                Log_OC.e(TAG, "Unexpected problem when opening: " + storagePath, th);
-                
-            } finally {
-                if (toastIt) {
-                    Toast.makeText(getSherlockActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
-                }
-            }
-            
-        }
+        mContainerActivity.getFileOperationsHelper().openFile(getFile());
         finish();
     }
     
@@ -721,16 +647,10 @@ public class PreviewMediaFragment extends FileFragment implements
     @Override
     public void onConfirmation(String callerTag) {
         OCFile file = getFile();
-        FileDataStorageManager storageManager = 
-                ((FileActivity)getSherlockActivity()).getStorageManager();
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
         if (storageManager.getFileById(file.getFileId()) != null) {   // check that the file is still there;
             stopPreview(true);
-            mLastRemoteOperation = new RemoveFileOperation( file,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
-                                                            true, 
-                                                            storageManager);
-            mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            
-            ((FileActivity) getSherlockActivity()).showLoadingDialog();
+            mContainerActivity.getFileOperationsHelper().removeFile(file, true);
         }
     }
     
@@ -742,7 +662,7 @@ public class PreviewMediaFragment extends FileFragment implements
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
         stopPreview(true);
-        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
+        mContainerActivity.getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         finish();
     }
     
@@ -764,34 +684,7 @@ public class PreviewMediaFragment extends FileFragment implements
     public static boolean canBePreviewed(OCFile file) {
         return (file != null && (file.isAudio() || file.isVideo()));
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
-        if (operation.equals(mLastRemoteOperation)) {
-            if (operation instanceof RemoveFileOperation) {
-                onRemoveFileOperationFinish((RemoveFileOperation)operation, result);
-            }
-        }
-    }
     
-    private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((FileActivity) getSherlockActivity()).dismissLoadingDialog();
-        if (result.isSuccess()) {
-            Toast msg = Toast.makeText(getSherlockActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
-            msg.show();
-            finish();
-                
-        } else {
-            Toast msg = Toast.makeText(getSherlockActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
-            msg.show();
-            if (result.isSslRecoverableException()) {
-                // TODO show the SSL warning dialog
-            }
-        }
-    }
 
     private void stopPreview(boolean stopAudio) {
         OCFile file = getFile();