From: masensio Date: Wed, 5 Feb 2014 10:25:39 +0000 (+0100) Subject: Merge branch 'share_link__new_share' into share_link__unshare_file X-Git-Tag: oc-android-1.5.5~35^2~28 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e437d8320db116025aab1549ff7bd9ec53aa64d6?ds=inline;hp=-c Merge branch 'share_link__new_share' into share_link__unshare_file --- e437d8320db116025aab1549ff7bd9ec53aa64d6 diff --combined res/values/strings.xml index 2c4dd7ce,1725ae38..0ecaadf4 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -60,7 -60,6 +60,7 @@@ Refresh file File was renamed to %1$s during upload Share link + Unshare link Yes No OK @@@ -188,6 -187,7 +188,7 @@@ Wait a moment "Unexpected problem ; please select the file from a different app" No file was selected + Send link to … Login with oAuth2 Connecting to oAuth2 server… @@@ -248,4 -248,5 +249,5 @@@ Sorry, sharing is not enabled on your server. Please contact your administrator. Unable to share this file or folder. Please, make sure it exists + An error occurred while trying to share this file or folder diff --combined src/com/owncloud/android/datamodel/FileDataStorageManager.java index 7b5380f7,279229af..181a7d49 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@@ -29,6 -29,7 +29,7 @@@ import com.owncloud.android.MainApp import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.lib.operations.common.OCShare; import com.owncloud.android.lib.operations.common.ShareType; + import com.owncloud.android.lib.utils.FileUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@@ -1099,19 -1100,30 +1100,44 @@@ public class FileDataStorageManager } } - - + + public void removeShare(OCShare share){ + Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE; + String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?"; + String [] whereArgs = new String[]{mAccount.name, share.getPath()}; + if (getContentProviderClient() != null) { + try { + getContentProviderClient().delete(share_uri, where, whereArgs); + } catch (RemoteException e) { + e.printStackTrace(); + } + } else { + getContentResolver().delete(share_uri, where, whereArgs); + } + } ++ + public void saveSharesDB(ArrayList shares) { + saveShares(shares); + + ArrayList sharedFiles = new ArrayList(); + + for (OCShare share : shares) { + // Get the path + String path = share.getPath(); + if (share.isDirectory()) { + path = path + FileUtils.PATH_SEPARATOR; + } + + // Update OCFile with data from share: ShareByLink ¿and publicLink? + OCFile file = getFileByPath(path); + if (file != null) { + if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { + file.setShareByLink(true); + sharedFiles.add(file); + } + } + } + + updateSharedFiles(sharedFiles); + } } diff --combined src/com/owncloud/android/files/FileOperationsHelper.java index 00000000,ab8395cd..1c0db87b mode 000000,100644..100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@@ -1,0 -1,143 +1,165 @@@ + /* ownCloud Android client application + * Copyright (C) 2012-2014 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 . + * + */ + + package com.owncloud.android.files; + + import org.apache.http.protocol.HTTP; + + import android.accounts.AccountManager; + import android.content.Intent; + import android.net.Uri; + import android.support.v4.app.DialogFragment; + import android.webkit.MimeTypeMap; + import android.widget.Toast; + + import com.owncloud.android.R; + import com.owncloud.android.datamodel.OCFile; + import com.owncloud.android.lib.accounts.OwnCloudAccount; + import com.owncloud.android.lib.network.webdav.WebdavUtils; + import com.owncloud.android.lib.operations.common.ShareType; + import com.owncloud.android.operations.CreateShareOperation; ++import com.owncloud.android.operations.UnshareLinkOperation; + import com.owncloud.android.ui.activity.FileActivity; + import com.owncloud.android.ui.dialog.ActivityChooserDialog; + import com.owncloud.android.utils.Log_OC; + + /** + * + * @author masensio + * @author David A. Velasco + */ + public class FileOperationsHelper { + + private static final String TAG = FileOperationsHelper.class.getName(); + + private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; + + + public void openFile(OCFile file, FileActivity callerActivity) { + if (file != null) { + String storagePath = file.getStoragePath(); + String encodedStoragePath = WebdavUtils.encodePath(storagePath); + + Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW); + intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype()); + intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + + Intent intentForGuessedMimeType = null; + if (storagePath.lastIndexOf('.') >= 0) { + String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); + if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) { + intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW); + intentForGuessedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), guessedMimeType); + intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + } + } + + Intent chooserIntent = null; + if (intentForGuessedMimeType != null) { + chooserIntent = Intent.createChooser(intentForGuessedMimeType, callerActivity.getString(R.string.actionbar_open_with)); + } else { + chooserIntent = Intent.createChooser(intentForSavedMimeType, callerActivity.getString(R.string.actionbar_open_with)); + } + + callerActivity.startActivity(chooserIntent); + + } else { + Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); + } + } + + + public void shareFileWithLink(OCFile file, FileActivity callerActivity) { + + if (isSharedSupported(callerActivity)) { + if (file != null) { + String link = "https://fake.url"; + Intent intent = createShareWithLinkIntent(link); + String[] packagesToExclude = new String[] { callerActivity.getPackageName() }; + DialogFragment chooserDialog = ActivityChooserDialog.newInstance(intent, packagesToExclude, file); + chooserDialog.show(callerActivity.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); + t.show(); + } + } + + + public void shareFileWithLinkToApp(OCFile file, Intent sendIntent, FileActivity callerActivity) { + + if (file != null) { + callerActivity.showLoadingDialog(); + CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1, sendIntent); + createShare.execute(callerActivity.getStorageManager(), + callerActivity, + callerActivity.getRemoteOperationListener(), + callerActivity.getHandler(), + callerActivity); + + } else { + Log_OC.wtf(TAG, "Trying to open a NULL OCFile"); + } + } + + + private Intent createShareWithLinkIntent(String link) { + Intent intentToShareLink = new Intent(Intent.ACTION_SEND); + intentToShareLink.putExtra(Intent.EXTRA_TEXT, link); + intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE); + return intentToShareLink; + } + + + /** + * @return 'True' if the server supports the Share API + */ + public boolean isSharedSupported(FileActivity callerActivity) { + if (callerActivity.getAccount() != null) { + AccountManager accountManager = AccountManager.get(callerActivity); + return Boolean.parseBoolean(accountManager.getUserData(callerActivity.getAccount(), OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API)); + } + return false; + } + ++ ++ public void unshareFileWithLink(OCFile file, FileActivity callerActivity) { ++ ++ if (isSharedSupported(callerActivity)) { ++ // Unshare the file ++ UnshareLinkOperation unshare = new UnshareLinkOperation(file); ++ unshare.execute(callerActivity.getStorageManager(), ++ callerActivity, ++ callerActivity.getRemoteOperationListener(), ++ callerActivity.getHandler(), ++ callerActivity); ++ ++ callerActivity.showLoadingDialog(); ++ ++ } else { ++ // Show a Message ++ Toast t = Toast.makeText(callerActivity, callerActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); ++ t.show(); ++ ++ } ++ } + } diff --combined src/com/owncloud/android/operations/GetSharesOperation.java index 7129a213,8f7a2ae8..eb221598 --- a/src/com/owncloud/android/operations/GetSharesOperation.java +++ b/src/com/owncloud/android/operations/GetSharesOperation.java @@@ -1,5 -1,5 +1,5 @@@ /* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-2014 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, @@@ -19,13 -19,10 +19,10 @@@ package com.owncloud.android.operations import java.util.ArrayList; - import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.network.OwnCloudClient; import com.owncloud.android.lib.operations.common.RemoteOperationResult; import com.owncloud.android.lib.operations.common.OCShare; - import com.owncloud.android.lib.operations.common.ShareType; import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation; - import com.owncloud.android.lib.utils.FileUtils; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.Log_OC; @@@ -55,36 -52,10 +52,10 @@@ public class GetSharesOperation extend shares.add((OCShare) obj); } - saveSharesDB(shares); + getStorageManager().saveSharesDB(shares); } return result; } - private void saveSharesDB(ArrayList shares) { - // Save share file - getStorageManager().saveShares(shares); - - ArrayList sharedFiles = new ArrayList(); - - for (OCShare share : shares) { - // Get the path - String path = share.getPath(); - if (share.isDirectory()) { - path = path + FileUtils.PATH_SEPARATOR; - } - - // Update OCFile with data from share: ShareByLink ¿and publicLink? - OCFile file = getStorageManager().getFileByPath(path); - if (file != null) { - if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { - file.setShareByLink(true); - sharedFiles.add(file); - } - } - } - - getStorageManager().updateSharedFiles(sharedFiles); - } - } diff --combined src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 02da64ef,a56fe3d9..5691401d --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@@ -38,12 -38,10 +38,10 @@@ import android.content.res.Resources.No import android.database.Cursor; import android.net.Uri; import android.os.Bundle; - import android.os.Handler; import android.os.IBinder; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.support.v4.app.Fragment; - import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.LocalBroadcastManager; import android.util.Log; @@@ -61,7 -59,6 +59,6 @@@ import com.actionbarsherlock.view.MenuI import com.actionbarsherlock.view.Window; import com.owncloud.android.MainApp; import com.owncloud.android.R; - import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileObserverService; @@@ -70,21 -67,18 +67,19 @@@ import com.owncloud.android.files.servi import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.operations.CreateFolderOperation; - import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode; - + import com.owncloud.android.operations.CreateShareOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; +import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.services.OperationsService; import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.ui.dialog.EditNameDialog; import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener; - import com.owncloud.android.ui.dialog.LoadingDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; import com.owncloud.android.ui.fragment.FileDetailFragment; @@@ -105,13 -99,10 +100,10 @@@ import com.owncloud.android.utils.Log_O */ public class FileDisplayActivity extends FileActivity implements - OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, OnRemoteOperationListener, EditNameDialogListener { + OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNavigationListener, OnSslValidatorListener, EditNameDialogListener { private ArrayAdapter mDirectories; - /** Access point to the cached database for the current ownCloud {@link Account} */ - private FileDataStorageManager mStorageManager = null; - private SyncBroadcastReceiver mSyncBroadcastReceiver; private UploadFinishReceiver mUploadFinishReceiver; private DownloadFinishReceiver mDownloadFinishReceiver; @@@ -134,8 -125,6 +126,6 @@@ private static final int DIALOG_SSL_VALIDATOR = 2; private static final int DIALOG_CERT_NOT_SAVED = 3; - private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT"; - public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS"; private static final int ACTION_SELECT_CONTENT_FROM_APPS = 1; @@@ -147,7 -136,6 +137,6 @@@ private static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT"; private OCFile mWaitingToPreview; - private Handler mHandler; private boolean mSyncInProgress = false; private boolean mRefreshSharesInProgress = false; @@@ -159,8 -147,6 +148,6 @@@ super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account is valid - mHandler = new Handler(); - /// bindings to transference services mUploadConnection = new ListServiceConnection(); mDownloadConnection = new ListServiceConnection(); @@@ -231,9 -217,8 +218,8 @@@ */ @Override protected void onAccountSet(boolean stateWasRecovered) { + super.onAccountSet(stateWasRecovered); if (getAccount() != null) { - mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver()); - /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account OCFile file = getFile(); // get parent from path @@@ -243,15 -228,15 +229,15 @@@ // upload in progress - right now, files are not inserted in the local cache until the upload is successful // get parent from path parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName())); - if (mStorageManager.getFileByPath(parentPath) == null) + if (getStorageManager().getFileByPath(parentPath) == null) file = null; // not able to know the directory where the file is uploading } else { - file = mStorageManager.getFileByPath(file.getRemotePath()); // currentDir = null if not in the current Account + file = getStorageManager().getFileByPath(file.getRemotePath()); // currentDir = null if not in the current Account } } if (file == null) { // fall back to root folder - file = mStorageManager.getFileByPath(OCFile.ROOT_PATH); // never returns null + file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null } setFile(file); setNavigationListWithFolder(file); @@@ -267,10 -252,6 +253,6 @@@ updateFragmentsVisibility(!file.isFolder()); updateNavigationElementsInActionBar(file.isFolder() ? null : file); } - - - } else { - Log_OC.wtf(TAG, "onAccountChanged was called with NULL account associated!"); } } @@@ -283,10 -264,9 +265,9 @@@ if (fileIt.isFolder()) { mDirectories.add(fileIt.getFileName()); } - //fileIt = mStorageManager.getFileById(fileIt.getParentId()); // get parent from path parentPath = fileIt.getRemotePath().substring(0, fileIt.getRemotePath().lastIndexOf(fileIt.getFileName())); - fileIt = mStorageManager.getFileByPath(parentPath); + fileIt = getStorageManager().getFileByPath(parentPath); } mDirectories.add(OCFile.PATH_SEPARATOR); } @@@ -448,12 -428,12 +429,12 @@@ boolean detailsFragmentChanged = false; if (waitedPreview) { if (success) { - mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path + mWaitingToPreview = getStorageManager().getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) { startMediaPreview(mWaitingToPreview, 0, true); detailsFragmentChanged = true; } else { - openFile(mWaitingToPreview); + getFileOperationsHelper().openFile(mWaitingToPreview, this); } } mWaitingToPreview = null; @@@ -465,7 -445,6 +446,6 @@@ } } - @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSherlock().getMenuInflater(); @@@ -544,7 -523,7 +524,7 @@@ targetPath = mDirectories.getItem(i) + OCFile.PATH_SEPARATOR + targetPath; } targetPath = OCFile.PATH_SEPARATOR + targetPath; - OCFile targetFolder = mStorageManager.getFileByPath(targetPath); + OCFile targetFolder = getStorageManager().getFileByPath(targetPath); if (targetFolder != null) { browseTo(targetFolder); } @@@ -838,30 -817,6 +818,6 @@@ /** - * Show loading dialog - */ - public void showLoadingDialog() { - // Construct dialog - LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment)); - FragmentManager fm = getSupportFragmentManager(); - FragmentTransaction ft = fm.beginTransaction(); - loading.show(ft, DIALOG_WAIT_TAG); - - } - - /** - * Dismiss loading dialog - */ - public void dismissLoadingDialog(){ - Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG); - if (frag != null) { - LoadingDialog loading = (LoadingDialog) frag; - loading.dismiss(); - } - } - - - /** * Translates a content URI of an image to a physical path * on the disk * @param uri The URI to resolve @@@ -939,14 -894,13 +895,13 @@@ String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME); String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncAdapter.EXTRA_RESULT); - boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && mStorageManager != null); + boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); if (sameAccount) { if (!FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) { - - OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath()); - OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath()); + OCFile currentFile = (getFile() == null) ? null : getStorageManager().getFileByPath(getFile().getRemotePath()); + OCFile currentDir = (getCurrentDir() == null) ? null : getStorageManager().getFileByPath(getCurrentDir().getRemotePath()); if (currentDir == null) { // current folder was removed from the server @@@ -972,13 -926,17 +927,17 @@@ setFile(currentFile); } - mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED.equals(event)); + mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && + !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED.equals(event) && + (synchResult == null || synchResult.isSuccess())) ; if (synchResult != null && synchResult.isSuccess() && (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SYNCED.equals(event) || FileSyncAdapter.EVENT_FOLDER_CONTENTS_SYNCED.equals(event) - ) + ) && + !mRefreshSharesInProgress && + getFileOperationsHelper().isSharedSupported(FileDisplayActivity.this) ) { startGetShares(); } @@@ -1073,7 -1031,7 +1032,7 @@@ Account account = intent.getParcelableExtra(OperationsService.EXTRA_ACCOUNT); RemoteOperationResult getSharesResult = (RemoteOperationResult)intent.getSerializableExtra(OperationsService.EXTRA_RESULT); if (getAccount() != null && account.name.equals(getAccount().name) - && mStorageManager != null + && getStorageManager() != null ) { refeshListOfFilesFragment(); } @@@ -1090,23 -1048,13 +1049,13 @@@ } - - /** - * {@inheritDoc} - */ - @Override - public FileDataStorageManager getStorageManager() { - return mStorageManager; - } - - public void browseToRoot() { OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { // should never be null, indeed while (mDirectories.getCount() > 1) { popDirname(); } - OCFile root = mStorageManager.getFileByPath(OCFile.ROOT_PATH); + OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); listOfFiles.listDirectory(root); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root); @@@ -1342,6 -1290,8 +1291,8 @@@ */ @Override public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { + super.onRemoteOperationFinish(operation, result); + if (operation instanceof RemoveFileOperation) { onRemoveFileOperationFinish((RemoveFileOperation)operation, result); @@@ -1353,25 -1303,21 +1304,36 @@@ } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - + + } else if (operation instanceof CreateShareOperation) { + onCreateShareOperationFinish((CreateShareOperation) operation, result); - } ++ + } else if (operation instanceof UnshareLinkOperation) { + onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); - } ++ ++ } + } - + private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { + if (result.getCode() == ResultCode.FILE_NOT_FOUND) { + // Show a Message + Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG); + t.show(); + } + + refeshListOfFilesFragment(); + + dismissLoadingDialog(); + } + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { + refeshListOfFilesFragment(); + } + } + + /** * Updates the view associated to the activity after the finish of an operation trying to remove a * file. @@@ -1390,7 -1336,7 +1352,7 @@@ if (second != null && removedFile.equals(second.getFile())) { cleanSecondFragment(); } - if (mStorageManager.getFileById(removedFile.getParentId()).equals(getCurrentDir())) { + if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) { refeshListOfFilesFragment(); } @@@ -1449,7 -1395,7 +1411,7 @@@ ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount()); } } - if (mStorageManager.getFileById(renamedFile.getParentId()).equals(getCurrentDir())) { + if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())) { refeshListOfFilesFragment(); } @@@ -1525,11 -1471,11 +1487,11 @@@ // Create directory path += newDirectoryName + OCFile.PATH_SEPARATOR; - RemoteOperation operation = new CreateFolderOperation(path, false, mStorageManager); + RemoteOperation operation = new CreateFolderOperation(path, false, getStorageManager()); operation.execute( getAccount(), FileDisplayActivity.this, FileDisplayActivity.this, - mHandler, + getHandler(), FileDisplayActivity.this); showLoadingDialog(); @@@ -1554,9 -1500,9 +1516,9 @@@ if (file != null) { if (file.isFolder()) { return file; - } else if (mStorageManager != null) { + } else if (getStorageManager() != null) { String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName())); - return mStorageManager.getFileByPath(parentPath); + return getStorageManager().getFileByPath(parentPath); } } return null; @@@ -1589,23 -1535,5 +1551,8 @@@ mRefreshSharesInProgress = true; } + + - public void unshareFileWithLink(OCFile file) { - - if (isSharedSupported()) { - // Unshare the file - UnshareLinkOperation unshare = new UnshareLinkOperation(file); - unshare.execute(getStorageManager(), this, this, mHandler, this); - - showLoadingDialog(); - - } else { - // Show a Message - Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); - t.show(); - - } - } ++ } diff --combined src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 09d31c43,216cceec..8f6a232a --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@@ -310,12 -310,7 +310,12 @@@ public class FileDetailFragment extend toHide.add(R.id.action_remove_file); } - + + // Options shareLink + if (!file.isShareByLink()) { + toHide.add(R.id.action_unshare_file); + } + MenuItem item = null; for (int i : toHide) { item = menu.findItem(i); @@@ -340,8 -335,14 +340,14 @@@ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_share_file: { + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity); + return true; + } case R.id.action_open_file_with: { - mContainerActivity.openFile(getFile()); + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().openFile(getFile(), activity); return true; } case R.id.action_remove_file: { @@@ -363,7 -364,7 +369,7 @@@ return false; } } - + @Override public void onClick(View v) { switch (v.getId()) { @@@ -404,7 -405,6 +410,6 @@@ } } - private void removeFile() { OCFile file = getFile(); ConfirmationDialogFragment confDialog = ConfirmationDialogFragment.newInstance( diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index a1ff5d4e,96aa2dc2..810602a8 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -25,7 -25,6 +25,6 @@@ import com.owncloud.android.R import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; - import com.owncloud.android.files.FileHandler; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.lib.operations.common.OnRemoteOperationListener; @@@ -183,8 -182,8 +182,8 @@@ public class OCFileListFragment extend // media preview mContainerActivity.startMediaPreview(file, 0, true); } else { - // open with - mContainerActivity.openFile(file); + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().openFile(file, activity); } } else { @@@ -283,11 -282,12 +282,17 @@@ public boolean onContextItemSelected (MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); mTargetFile = (OCFile) mAdapter.getItem(info.position); -- switch (item.getItemId()) { ++ switch (item.getItemId()) { + case R.id.action_share_file: { + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().shareFileWithLink(mTargetFile, activity); + return true; + } + case R.id.action_unshare_file: { - mContainerActivity.unshareFileWithLink(mTargetFile); ++ FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); ++ activity.getFileOperationsHelper().unshareFileWithLink(mTargetFile, activity); + return true; + } case R.id.action_rename_file: { String fileName = mTargetFile.getFileName(); int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf("."); @@@ -353,7 -353,7 +358,7 @@@ return super.onContextItemSelected(item); } } - + /** * Use this to query the {@link OCFile} that is currently @@@ -414,7 -414,7 +419,7 @@@ * * @author David A. Velasco */ - public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener, FileHandler { + public interface ContainerActivity extends TransferServiceGetter, OnRemoteOperationListener { /** * Callback method invoked when a the user browsed into a different folder through the list of files @@@ -422,9 -422,7 +427,7 @@@ * @param file */ public void onBrowsedDownTo(OCFile folder); -- - public void unshareFileWithLink(OCFile mTargetFile); + public void startDownloadForPreview(OCFile file); public void startMediaPreview(OCFile file, int i, boolean b); diff --combined src/com/owncloud/android/ui/preview/PreviewImageFragment.java index c6d9825d,a2d05370..69fc1f85 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -57,6 -57,7 +57,7 @@@ import com.owncloud.android.lib.operati import com.owncloud.android.lib.operations.common.RemoteOperation; import com.owncloud.android.lib.operations.common.RemoteOperationResult; import com.owncloud.android.operations.RemoveFileOperation; + import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.fragment.ConfirmationDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.utils.Log_OC; @@@ -229,11 -230,6 +230,11 @@@ public class PreviewImageFragment exten toHide.add(R.id.action_cancel_upload); toHide.add(R.id.action_download_file); toHide.add(R.id.action_rename_file); // by now + + // Options shareLink + if (!getFile().isShareByLink()) { + toHide.add(R.id.action_unshare_file); + } for (int i : toHide) { item = menu.findItem(i); @@@ -252,6 -248,11 +253,11 @@@ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_share_file: { + FileActivity act = (FileActivity)getSherlockActivity(); + act.getFileOperationsHelper().shareFileWithLink(getFile(), act); + return true; + } case R.id.action_open_file_with: { openFile(); return true; @@@ -271,15 -272,6 +277,15 @@@ } + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + } + + private void seeDetails() { ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile()); } diff --combined src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index d68332e1,ee4a7b00..9215f7dd --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -289,12 -289,7 +289,12 @@@ public class PreviewMediaFragment exten toHide.add(R.id.action_download_file); toHide.add(R.id.action_sync_file); toHide.add(R.id.action_rename_file); // by now - + + // Options shareLink + if (!getFile().isShareByLink()) { + toHide.add(R.id.action_unshare_file); + } + for (int i : toHide) { item = menu.findItem(i); if (item != null) { @@@ -312,6 -307,10 +312,10 @@@ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.action_share_file: { + shareFileWithLink(); + return true; + } case R.id.action_open_file_with: { openFile(); return true; @@@ -329,16 -328,16 +333,24 @@@ return false; } } + + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + } + private void shareFileWithLink() { + stopPreview(false); + FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity()); + activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity); + + } + + private void seeDetails() { stopPreview(false); ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());