From: David A. Velasco Date: Tue, 24 Nov 2015 17:27:03 +0000 (+0100) Subject: Grant that ShareActivity is correctly refreshed if public share was removed in the... X-Git-Tag: oc-android-1.9^2~10^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/5c24e55421b146931b4e32489d337f620cbb45e2?ds=inline;hp=-c Grant that ShareActivity is correctly refreshed if public share was removed in the server Updated library reference after merge in master --- 5c24e55421b146931b4e32489d337f620cbb45e2 diff --git a/owncloud-android-library b/owncloud-android-library index 9cf96a10..9e5c44dd 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 9cf96a10ce8b3c79c5f386c258da80119ca81b7b +Subproject commit 9e5c44ddb58970f1bbdf6723145a47379bdbccba diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 6c88116f..af912365 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1427,6 +1427,30 @@ public class FileDataStorageManager { // updateSharedFiles(sharedFiles); } + public void removeSharesForFile(String remotePath) { + resetShareFlagInAFile(remotePath); + ArrayList operations = new ArrayList(); + operations = prepareRemoveSharesInFile(remotePath, operations); + // apply operations in batch + if (operations.size() > 0) { + Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider"); + try { + if (getContentResolver() != null) { + getContentResolver().applyBatch(MainApp.getAuthority(), operations); + + } else { + getContentProviderClient().applyBatch(operations); + } + + } catch (OperationApplicationException e) { + Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); + + } catch (RemoteException e) { + Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage()); + } + } + } + public void saveSharesInFolder(ArrayList shares, OCFile folder) { resetShareFlagsInFolder(folder); diff --git a/src/com/owncloud/android/operations/GetSharesForFileOperation.java b/src/com/owncloud/android/operations/GetSharesForFileOperation.java index 62c3be18..a04d4159 100644 --- a/src/com/owncloud/android/operations/GetSharesForFileOperation.java +++ b/src/com/owncloud/android/operations/GetSharesForFileOperation.java @@ -72,6 +72,11 @@ public class GetSharesForFileOperation extends SyncOperation { } getStorageManager().saveSharesDB(shares); + + } else if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) { + // no share on the file - remove local shares + getStorageManager().removeSharesForFile(mPath); + } return result; diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 086f390d..99e4c91f 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -762,10 +762,10 @@ public class FileActivity extends AppCompatActivity onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result); } else if (operation instanceof GetSharesForFileOperation) { - if (result.isSuccess()) { + if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) { updateFileFromDB(); - } else if (result.getCode() != ResultCode.SHARE_NOT_FOUND) { + } else { Toast t = Toast.makeText(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Toast.LENGTH_LONG); diff --git a/src/com/owncloud/android/ui/activity/ShareActivity.java b/src/com/owncloud/android/ui/activity/ShareActivity.java index 7bfc4c52..bf6e37a6 100644 --- a/src/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/com/owncloud/android/ui/activity/ShareActivity.java @@ -32,6 +32,7 @@ import android.support.v4.app.FragmentTransaction; import com.owncloud.android.R; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.GetSharesForFileOperation; import com.owncloud.android.providers.UsersAndGroupsSearchProvider; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -160,23 +161,28 @@ public class ShareActivity extends FileActivity public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { super.onRemoteOperationFinish(operation, result); - if (result.isSuccess()) { - Log_OC.d(TAG, "Refreshing view on successful operation"); + if (result.isSuccess() || + (operation instanceof GetSharesForFileOperation && + result.getCode() == RemoteOperationResult.ResultCode.SHARE_NOT_FOUND + ) + ) { + Log_OC.d(TAG, "Refreshing view on successful operation or finished refresh"); refreshSharesFromStorageManager(); + } - if (operation instanceof CreateShareViaLinkOperation) { - // Send link to the app - String link = ((OCShare) (result.getData().get(0))).getShareLink(); - Log_OC.d(TAG, "Share link = " + link); - - Intent intentToShareLink = new Intent(Intent.ACTION_SEND); - intentToShareLink.putExtra(Intent.EXTRA_TEXT, link); - intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE); - String[] packagesToExclude = new String[]{getPackageName()}; - DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude); - chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); - } + if (operation instanceof CreateShareViaLinkOperation) { + // Send link to the app + String link = ((OCShare) (result.getData().get(0))).getShareLink(); + Log_OC.d(TAG, "Share link = " + link); + + Intent intentToShareLink = new Intent(Intent.ACTION_SEND); + intentToShareLink.putExtra(Intent.EXTRA_TEXT, link); + intentToShareLink.setType(HTTP.PLAIN_TEXT_TYPE); + String[] packagesToExclude = new String[]{getPackageName()}; + DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude); + chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); } + }