import org.apache.http.protocol.HTTP;
+import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Intent;
import android.net.Uri;
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;
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);
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");
} 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");
/**
* @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
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();
+ }
+
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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 ComponentsGetter {
+
+ /**
+ * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
+ *
+ * @return Directory to list firstly. Can be NULL.
+ */
+ public FileDownloaderBinder getFileDownloaderBinder();
+
+
+ /**
+ * Callback method invoked when the parent activity is fully created to get a reference to the FileUploader service API.
+ *
+ * @return Directory to list firstly. Can be NULL.
+ */
+ public FileUploaderBinder getFileUploaderBinder();
+
+
+
+ public FileDataStorageManager getStorageManager();
+
+ public FileOperationsHelper getFileOperationsHelper();
+
+}
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;
*
* @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";
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
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);
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);
+ }
+
}
unbindService(mOperationsServiceConnection);
mOperationsServiceBinder = null;
}
+ if (mDownloadServiceConnection != null) {
+ unbindService(mDownloadServiceConnection);
+ mDownloadServiceConnection = null;
+ }
+ if (mUploadServiceConnection != null) {
+ unbindService(mUploadServiceConnection);
+ mUploadServiceConnection = null;
+ }
}
public OperationsServiceBinder getOperationsServiceBinder() {
return mOperationsServiceBinder;
}
-
+
+ protected ServiceConnection newTransferenceServiceConnection() {
+ return null;
+ }
+
/**
* Helper class handling a callback from the {@link AccountManager} after the creation of
// TODO whatever could be waiting for the service is unbound
}
}
+ }
+
+
+ @Override
+ public FileDownloaderBinder getFileDownloaderBinder() {
+ return mDownloaderBinder;
+ }
+
+
+ @Override
+ public FileUploaderBinder getFileUploaderBinder() {
+ return mUploaderBinder;
};
+
}
*/
public class FileDisplayActivity extends HookActivity implements
-OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener, EditNameDialogListener {
+FileFragment.ContainerActivity, OnNavigationListener,
+OnSslUntrustedCertListener, EditNameDialogListener {
private ArrayAdapter<String> mDirectories;
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;
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();
@Override
protected void onDestroy() {
super.onDestroy();
- if (mDownloadConnection != null)
- unbindService(mDownloadConnection);
- if (mUploadConnection != null)
- unbindService(mUploadConnection);
}
/**
startMediaPreview(mWaitingToPreview, 0, true);
detailsFragmentChanged = true;
} else {
- getFileOperationsHelper().openFile(mWaitingToPreview, this);
+ getFileOperationsHelper().openFile(mWaitingToPreview);
}
}
mWaitingToPreview = null;
}
/**
- * 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.
*
}
- /**
- * {@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 {
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();
}
}
}
-
+
+
/**
* Updates the view associated to the activity after the finish of an operation trying create a new folder
*
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())) {
/*
}
}
-
private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
dismissLoadingDialog();
OCFile syncedFile = operation.getLocalFile();
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();
}
}
-
+
/**
* {@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);
}
}
}
RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
currentSyncTime,
false,
- getFileOperationsHelper().isSharedSupported(this),
+ getFileOperationsHelper().isSharedSupported(),
getStorageManager(),
getAccount(),
getApplicationContext()
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
*
* @param file {@link OCFile} to download and preview.
*/
- @Override
public void startDownloadForSending(OCFile file) {
mWaitingToSend = file;
requestForDownload(mWaitingToSend);
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;
- }
-
}
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012 Bartek Przybylski
- * Copyright (C) 2012-2013 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui.activity;
-
-import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
-import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-
-public interface TransferServiceGetter {
-
- /**
- * Callback method invoked when the parent activity is fully created to get a reference to the FileDownloader service API.
- *
- * @return Directory to list firstly. Can be NULL.
- */
- public FileDownloaderBinder getFileDownloaderBinder();
-
-
- /**
- * Callback method invoked when the parent activity is fully created to get a reference to the FileUploader service API.
- *
- * @return Directory to list firstly. Can be NULL.
- */
- public FileUploaderBinder getFileUploaderBinder();
-
-
-}
import com.owncloud.android.datamodel.OCFile;\r
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
-import com.owncloud.android.ui.activity.TransferServiceGetter;\r
+import com.owncloud.android.ui.activity.ComponentsGetter;\r
import com.owncloud.android.utils.DisplayUtils;\r
import com.owncloud.android.utils.Log_OC;\r
\r
private Context mContext;\r
private FileDataStorageManager mStorageManager;\r
private Account mAccount;\r
- private TransferServiceGetter mTransferServiceGetter;\r
+ private ComponentsGetter mTransferServiceGetter;\r
\r
\r
- public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {\r
+ public FileListListAdapter(Context context, ComponentsGetter componentsGetter) {\r
super(context, null, FLAG_AUTO_REQUERY);\r
mContext = context;\r
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
- mTransferServiceGetter = transferServiceGetter;\r
+ mTransferServiceGetter = componentsGetter;\r
}\r
\r
public void setStorageManager(FileDataStorageManager storageManager) {\r
} 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);
}
}
})
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;
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;
*/
public class FileDetailFragment extends FileFragment implements
OnClickListener,
- ConfirmationDialogFragment.ConfirmationDialogFragmentListener, OnRemoteOperationListener, EditNameDialogListener {
+ ConfirmationDialogFragment.ConfirmationDialogFragmentListener, EditNameDialogListener {
private FileFragment.ContainerActivity mContainerActivity;
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";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mHandler = new Handler();
setHasOptionsMenu(true);
}
}
View view = null;
- //view = inflater.inflate(mLayout, container, false);
view = inflater.inflate(mLayout, null);
mView = 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}
- */
- @Override
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);
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;
}
break;
}
case R.id.fdCancelBtn: {
- synchronizeFile();
+ ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile());
break;
}
default:
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
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,
}
- private void renameFile() {
+ private void showDialogToRenameFile() {
OCFile file = getFile();
String fileName = file.getFileName();
int extensionStart = file.isFolder() ? -1 : fileName.lastIndexOf(".");
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);
}
}
}
@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);
*/
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);
}
* 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()));
}
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))) {
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();
// Force the preview if the file is an image
if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
- ((FileDisplayActivity) mContainerActivity).startImagePreview(getFile());
+ ((FileDisplayActivity)mContainerActivity).startImagePreview(getFile());
}
}
}
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) {
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;
/**
public class FileFragment extends SherlockFragment {
private OCFile mFile;
+
+ protected ContainerActivity mContainerActivity;
/**
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.
*/
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);
-
+
}
-
+
}
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;
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;
/**
* 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,
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
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}
registerForContextMenu(getListView());
getListView().setOnCreateContextMenuListener(this);
- mHandler = new Handler();
-
-
}
/**
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) {
if (mFile != null) {
listDirectory(mFile);
- mContainerActivity.startSyncFolderOperation(mFile);
+ ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
// restore index and top position
restoreIndexAndTopPosition();
@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()) {
} 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);
}
}
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>();
@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: {
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: {
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;
}
* @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
}
- /**
- * 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);
}
}
@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);
}
@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 {
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) {
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;
}
- /**
- * {@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);
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;
*
* @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;
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;
@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
} else if (operation instanceof UnshareLinkOperation) {
onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
+ } else if (operation instanceof RemoveFileOperation) {
+ finish();
}
}
invalidateOptionsMenu();
}
}
-
+
+ @Override
+ protected ServiceConnection newTransferenceServiceConnection() {
+ return new PreviewImageServiceConnection();
+ }
+
/** Defines callbacks for service binding, passed to bindService() */
private class PreviewImageServiceConnection implements ServiceConnection {
@Override
public void onStop() {
super.onStop();
- if (mDownloadConnection != null) {
- unbindService(mDownloadConnection);
- mDownloadConnection = null;
- }
- if (mUploadConnection != null) {
- unbindService(mUploadConnection);
- mUploadConnection = null;
- }
}
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);
}
}
+ @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!
+ }
+
+
}
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;
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;
*
* @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";
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.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mHandler = new Handler();
setHasOptionsMenu(true);
}
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);
@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());
+ }
}
// 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 {
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 {
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: {
return true;
}
case R.id.action_send_file: {
- FileActivity act = (FileActivity)getSherlockActivity();
- act.getFileOperationsHelper().sendDownloadedFile(getFile(), act);
+ mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
return true;
}
private void seeDetails() {
- ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());
+ mContainerActivity.showDetails(getFile());
}
/**
* 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();
}
*/
@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);
}
}
@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();
}
/**
- * {@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
*/
private void finish() {
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;
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;
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;
*/
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";
private VideoView mVideoPreview;
private int mSavedPlaybackPosition;
- private Handler mHandler;
- private RemoteOperation mLastRemoteOperation;
-
private MediaServiceBinder mMediaServiceBinder = null;
private MediaControlView mMediaController = null;
private MediaServiceConnection mMediaServiceConnection = null;
private boolean mAutoplay;
public boolean mPrepared;
+ private FileFragment.ContainerActivity mContainerActivity;
+
private static final String TAG = PreviewMediaFragment.class.getSimpleName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mHandler = new Handler();
setHasOptionsMenu(true);
}
* {@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}
- */
- @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log_OC.e(TAG, "onActivityCreated");
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());
}
/**
* 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();
}
@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);
}
}
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();
}
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();