-Subproject commit 815fbba48677e40bff2c3c114c4ce8dd1e35bc17
+Subproject commit 985b005995429f52446dc5bb66abd236595e627e
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_share_file" android:title="@string/action_share_file" android:icon="@android:drawable/ic_menu_share" android:orderInCategory="1" />
- <item android:id="@+id/action_open_file_with" android:title="@string/actionbar_open_with" android:icon="@android:drawable/ic_menu_edit" android:orderInCategory="1" />
+ <item android:id="@+id/action_unshare_file" android:title="@string/action_unshare_file" android:icon="@android:drawable/ic_menu_share" android:orderInCategory="1" />
+ <item android:id="@+id/action_open_file_with" android:title="@string/actionbar_open_with" android:icon="@android:drawable/ic_menu_edit" android:orderInCategory="1" />
<item android:id="@+id/action_download_file" android:title="@string/filedetails_download" android:icon="@drawable/ic_action_download" android:orderInCategory="1" />
<item android:id="@+id/action_sync_file" android:title="@string/filedetails_sync_file" android:icon="@drawable/ic_action_refresh" android:orderInCategory="1" />
<item android:id="@+id/action_cancel_download" android:title="@string/common_cancel_download" android:icon="@android:drawable/ic_menu_close_clear_cancel" android:orderInCategory="1" />
<string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your administrator.</string>
<string name="share_link_file_no_exist">Unable to share this file or folder. Please, make sure it exists</string>
<string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
+ <string name="unshare_link_file_no_exist">Unable to unshare this file or folder. It does not exist.</string>
<string name="unshare_link_file_error">An error occurred while trying to unshare this file or folder</string>
</resources>
}
}
-
-
+
+ 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<OCShare> shares) {
saveShares(shares);
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;
return false;
}
+
+ public void unshareFileWithLink(OCFile file, FileActivity callerActivity) {
+
+ if (isSharedSupported(callerActivity)) {
+ // Unshare the file
+ UnshareLinkOperation unshare = new UnshareLinkOperation(file, callerActivity);
+ 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();
+
+ }
+ }
}
* Updates the OC File after a successful download.
*/
private void saveDownloadedFile() {
- OCFile file = mCurrentDownload.getFile();
+ OCFile file = mStorageManager.getFileById(mCurrentDownload.getFile().getFileId());
long syncDate = System.currentTimeMillis();
file.setLastSyncDateForProperties(syncDate);
file.setLastSyncDateForData(syncDate);
*/
private void saveUploadedFile() {
OCFile file = mCurrentUpload.getFile();
+ if (file.fileExists()) {
+ file = mStorageManager.getFileById(file.getFileId());
+ }
long syncDate = System.currentTimeMillis();
file.setLastSyncDateForData(syncDate);
/* 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,
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.operations;
+
+import android.content.Context;
+
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.network.OwnCloudClient;
+import com.owncloud.android.lib.operations.common.OCShare;
+import com.owncloud.android.lib.operations.common.RemoteOperationResult;
+import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;
+import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
+import com.owncloud.android.operations.common.SyncOperation;
+import com.owncloud.android.utils.Log_OC;
+
+/**
+ * Unshare file/folder
+ * Save the data in Database
+ *
+ * @author masensio
+ */
+public class UnshareLinkOperation extends SyncOperation {
+
+ private static final String TAG = UnshareLinkOperation.class.getSimpleName();
+
+ private OCFile mFile;
+ private Context mContext;
+
+
+ public UnshareLinkOperation(OCFile file, Context context) {
+ mFile = file;
+ mContext = context;
+ }
+
+ @Override
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+
+ // Get Share for a file
+ String path = mFile.getRemotePath();
+ if (mFile.isFolder()) {
+ path = path.substring(0, path.length()-1); // Remove last /
+ }
+ OCShare share = getStorageManager().getShareByPath(path);
+
+ if (share != null) {
+ RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
+ result = operation.execute(client);
+
+ if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
+
+ mFile.setShareByLink(false);
+ mFile.setPublicLink("");
+ getStorageManager().saveFile(mFile);
+ getStorageManager().removeShare(share);
+
+ if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ if (existsFile(client, mFile.getRemotePath())) {
+ result = new RemoteOperationResult(ResultCode.OK);
+ } else {
+ getStorageManager().removeFile(mFile, true, true);
+ }
+ }
+ }
+
+ } else {
+ result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
+ }
+
+ return result;
+ }
+
+ private boolean existsFile(OwnCloudClient client, String remotePath){
+ ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
+ RemoteOperationResult result = existsOperation.execute(client);
+ return result.isSuccess();
+ }
+
+}
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.UnshareLinkOperation;
import com.owncloud.android.ui.dialog.LoadingDialog;
import com.owncloud.android.utils.Log_OC;
Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the FileActivities ");
if (operation instanceof CreateShareOperation) {
onCreateShareOperationFinish((CreateShareOperation) operation, result);
- }
+
+ } else if (operation instanceof UnshareLinkOperation) {
+ onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
+
+ }
}
private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
Intent sendIntent = operation.getSendIntent();
startActivity(sendIntent);
- } else if (result.getCode() == ResultCode.FILE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
+ } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG);
t.show();
} else { // Generic error
}
+ private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+ dismissLoadingDialog();
+
+ if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
+ Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_no_exist), Toast.LENGTH_LONG);
+ t.show();
+ } else if (!result.isSuccess()){ // Generic error
+ // Show a Message, operation finished without success
+ Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG);
+ t.show();
+ }
+
+ }
+
/**
* Show loading dialog
*/
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.fragment.FileFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.preview.PreviewImageActivity;
+import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
import com.owncloud.android.ui.preview.PreviewVideoActivity;
import com.owncloud.android.utils.DisplayUtils;
mRightFragmentContainer = findViewById(R.id.right_fragment_container);
if (savedInstanceState == null) {
createMinFragments();
+ } else {
+ Log_OC.d(TAG, "Init the secondFragment again");
+ if (mDualPane) {
+ initFragmentsWithFile();
+ }
}
// Action bar setup
transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
transaction.commit();
}
-
+
private void initFragmentsWithFile() {
if (getAccount() != null && getFile() != null) {
/// First fragment
} 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 onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
if (result.isSuccess()) {
+ OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
+ if (file != null) {
+ setFile(file);
+ }
+ refreshShowDetails();
refeshListOfFilesFragment();
}
}
+ private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+ if (result.isSuccess()) {
+ OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
+ if (file != null) {
+ setFile(file);
+ }
+ refreshShowDetails();
+ refeshListOfFilesFragment();
+ } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ cleanSecondFragment();
+ refeshListOfFilesFragment();
+ }
+ }
+
+ private void refreshShowDetails() {
+ FileFragment details = getSecondFragment();
+ if (details != null) {
+ OCFile file = details.getFile();
+ if (file != null) {
+ file = getStorageManager().getFileByPath(file.getRemotePath()); {
+ if (!(details instanceof PreviewMediaFragment || details instanceof PreviewImageFragment)) {
+ showDetails(file);
+ } else if (details instanceof PreviewMediaFragment) {
+ startMediaPreview(file, 0, false);
+ }
+ }
+ invalidateOptionsMenu();
+ }
+ }
+ }
+
/**
* Updates the view associated to the activity after the finish of an operation trying to remove a
* file.
super.onActivityCreated(savedInstanceState);
if (mAccount != null) {
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
+ OCFile file = mStorageManager.getFileByPath(getFile().getRemotePath());
+ if (file != null) {
+ setFile(file);
+ }
}
}
toHide.add(R.id.action_remove_file);
}
-
+
+ // Options shareLink
+ if (!file.isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ } else {
+ toShow.add(R.id.action_unshare_file);
+ }
+
MenuItem item = null;
for (int i : toHide) {
item = menu.findItem(i);
activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity);
return true;
}
+ case R.id.action_unshare_file: {
+ FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+ activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
+ return true;
+ }
case R.id.action_open_file_with: {
FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
activity.getFileOperationsHelper().openFile(getFile(), activity);
toHide.add(R.id.action_cancel_upload);
}
}
+
+ // Options shareLink
+ if (!targetFile.isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ }
for (int i : toHide) {
item = menu.findItem(i);
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: {
+ 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(".");
return super.onContextItemSelected(item);
}
}
-
+
/**
* Use this to query the {@link OCFile} that is currently
* @param file
*/
public void onBrowsedDownTo(OCFile folder);
-
+
public void startDownloadForPreview(OCFile file);
public void startMediaPreview(OCFile file, int i, boolean b);
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.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.UnshareLinkOperation;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.PinCodeActivity;
*
* @author David A. Velasco
*/
-public class PreviewImageActivity extends FileActivity implements FileFragment.ContainerActivity, ViewPager.OnPageChangeListener, OnTouchListener {
+public class PreviewImageActivity extends FileActivity implements FileFragment.ContainerActivity, ViewPager.OnPageChangeListener, OnTouchListener , OnRemoteOperationListener{
public static final int DIALOG_SHORT_WAIT = 0;
outState.putBoolean(KEY_WAITING_FOR_BINDER, mRequestWaitingForBinder);
}
-
+ @Override
+ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
+ super.onRemoteOperationFinish(operation, result);
+
+ 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.isSuccess()) {
+ OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
+ if (file != null) {
+ setFile(file);
+ invalidateOptionsMenu();
+ }
+ } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ backToDisplayActivity();
+ }
+
+ }
+
+ private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
+ if (result.isSuccess()) {
+ OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
+ if (file != null) {
+ setFile(file);
+ invalidateOptionsMenu();
+ }
+ }
+ }
+
/** Defines callbacks for service binding, passed to bindService() */
private class PreviewImageServiceConnection implements ServiceConnection {
mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
if (savedInstanceState != null) {
if (!mIgnoreFirstSavedState) {
- setFile((OCFile)savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE));
+ OCFile file = (OCFile)savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE);
mAccount = savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_ACCOUNT);
+
+ // Update the file
+ if (mAccount!= null) {
+ mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
+ OCFile updatedFile = mStorageManager.getFileByPath(file.getRemotePath());
+ if (updatedFile != null) {
+ setFile(updatedFile);
+ } else {
+ setFile(file);
+ }
+ } else {
+ setFile(file);
+ }
+
} else {
mIgnoreFirstSavedState = false;
}
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);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+
+ MenuItem item = menu.findItem(R.id.action_unshare_file);
+ // Options shareLink
+ if (!getFile().isShareByLink()) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ } else {
+ item.setVisible(true);
+ item.setEnabled(true);
+ }
+
+ }
+
+
/**
* {@inheritDoc}
act.getFileOperationsHelper().shareFileWithLink(getFile(), act);
return true;
}
+ case R.id.action_unshare_file: {
+ FileActivity act = (FileActivity)getSherlockActivity();
+ act.getFileOperationsHelper().unshareFileWithLink(getFile(), act);
+ return true;
+ }
case R.id.action_open_file_with: {
openFile();
return true;
}
+
private void seeDetails() {
((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());
}
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) {
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+
+ MenuItem item = menu.findItem(R.id.action_unshare_file);
+ // Options shareLink
+ if (!getFile().isShareByLink()) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ } else {
+ item.setVisible(true);
+ item.setEnabled(true);
+ }
+ }
+
/**
* {@inheritDoc}
shareFileWithLink();
return true;
}
+ case R.id.action_unshare_file: {
+ unshareFileWithLink();
+ return true;
+ }
case R.id.action_open_file_with: {
openFile();
return true;
return false;
}
}
+
+
+ private void unshareFileWithLink() {
+ stopPreview(false);
+ FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity());
+ activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
+ }
private void shareFileWithLink() {
stopPreview(false);