Skip to content

Commit 5cd0091

Browse files
committed
fix unshare
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 2af5b98 commit 5cd0091

4 files changed

Lines changed: 42 additions & 37 deletions

File tree

app/src/main/java/com/owncloud/android/operations/UnshareOperation.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ protected RemoteOperationResult run(OwnCloudClient client) {
113113

114114
RemoveShareRemoteOperation operation = new RemoveShareRemoteOperation(share.getRemoteId());
115115
result = operation.execute(client);
116+
boolean isFileExists = existsFile(client, file.getRemotePath());
117+
boolean isShareExists = getStorageManager().getShareById(shareId) != null;
116118

117119
if (result.isSuccess()) {
118120
// E2E: unlock folder
@@ -140,10 +142,12 @@ protected RemoteOperationResult run(OwnCloudClient client) {
140142

141143
getStorageManager().saveFile(file);
142144
getStorageManager().removeShare(share);
143-
144-
} else if (result.getCode() != ResultCode.MAINTENANCE_MODE && !existsFile(client, file.getRemotePath())) {
145-
// unshare failed because file was deleted before
145+
} else if (result.getCode() != ResultCode.MAINTENANCE_MODE && !isFileExists) {
146+
// UnShare failed because file was deleted before
146147
getStorageManager().removeFile(file, true, true);
148+
} else if (isShareExists && result.getCode() == ResultCode.FILE_NOT_FOUND) {
149+
// UnShare failed because share was deleted before
150+
getStorageManager().removeShare(share);
147151
}
148152

149153
} else {

app/src/main/java/com/owncloud/android/ui/adapter/ShareeListAdapter.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
import com.owncloud.android.utils.theme.ViewThemeUtils;
3434

3535
import java.util.ArrayList;
36+
import java.util.LinkedHashSet;
3637
import java.util.List;
38+
import java.util.Set;
3739

3840
import androidx.annotation.NonNull;
3941
import androidx.recyclerview.widget.RecyclerView;
@@ -169,6 +171,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
169171
return;
170172
}
171173

174+
172175
if (holder instanceof LinkShareViewHolder publicShareViewHolder) {
173176
publicShareViewHolder.bind(share, listener);
174177
} else if (holder instanceof InternalShareViewHolder internalShareViewHolder) {
@@ -204,7 +207,7 @@ public int getItemCount() {
204207

205208
@SuppressLint("NotifyDataSetChanged")
206209
public void toggleShowAll() {
207-
this.showAll = !this.showAll;
210+
showAll = !showAll;
208211
notifyDataSetChanged();
209212
}
210213

@@ -219,6 +222,12 @@ public void addShares(List<OCShare> sharesToAdd) {
219222
notifyDataSetChanged();
220223
}
221224

225+
@SuppressLint("NotifyDataSetChanged")
226+
public void removeAll() {
227+
shares.clear();
228+
notifyDataSetChanged();
229+
}
230+
222231
@Override
223232
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
224233
if (callContext instanceof ImageView iv) {
@@ -273,13 +282,4 @@ protected final void sortShares() {
273282
public List<OCShare> getShares() {
274283
return shares;
275284
}
276-
277-
public void removeNewPublicShare() {
278-
for (OCShare share : shares) {
279-
if (share.getShareType() == ShareType.NEW_PUBLIC_LINK) {
280-
shares.remove(share);
281-
break;
282-
}
283-
}
284-
}
285285
}

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.database.Cursor;
2424
import android.graphics.drawable.Drawable;
2525
import android.net.Uri;
26+
import android.os.Build;
2627
import android.os.Bundle;
2728
import android.provider.ContactsContract;
2829
import android.text.InputType;
@@ -60,7 +61,6 @@
6061
import com.owncloud.android.ui.asynctasks.RetrieveHoverCardAsyncTask;
6162
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
6263
import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
63-
import com.owncloud.android.ui.fragment.util.SharePermissionManager;
6464
import com.owncloud.android.ui.helpers.FileOperationsHelper;
6565
import com.owncloud.android.utils.ClipboardUtil;
6666
import com.owncloud.android.utils.DisplayUtils;
@@ -69,6 +69,8 @@
6969

7070
import java.util.ArrayList;
7171
import java.util.List;
72+
import java.util.stream.Collectors;
73+
import java.util.stream.Stream;
7274

7375
import javax.inject.Inject;
7476

@@ -105,7 +107,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
105107
private ShareeListAdapter internalShareeListAdapter;
106108

107109
private ShareeListAdapter externalShareeListAdapter;
108-
private final SharePermissionManager sharePermissionManager = new SharePermissionManager();
109110

110111
@Inject UserAccountManager accountManager;
111112
@Inject ClientFactory clientFactory;
@@ -220,10 +221,11 @@ public void onAttach(@NonNull Context context) {
220221
if (!(getActivity() instanceof FileActivity)) {
221222
throw new IllegalArgumentException("Calling activity must be of type FileActivity");
222223
}
224+
223225
try {
224226
onEditShareListener = (OnEditShareListener) context;
225-
} catch (Exception ignored) {
226-
throw new IllegalArgumentException("Calling activity must implement the interface", ignored);
227+
} catch (Exception e) {
228+
throw new IllegalArgumentException("Calling activity must implement the interface" + e);
227229
}
228230
}
229231

@@ -523,7 +525,8 @@ public void refreshSharesFromDB() {
523525
DisplayUtils.showSnackMessage(getView(), getString(R.string.could_not_retrieve_shares));
524526
return;
525527
}
526-
internalShareeListAdapter.getShares().clear();
528+
529+
internalShareeListAdapter.removeAll();
527530

528531
// to show share with users/groups info
529532
List<OCShare> shares = fileDataStorageManager.getSharesWithForAFile(file.getRemotePath(),
@@ -550,25 +553,24 @@ public void refreshSharesFromDB() {
550553
}
551554

552555
internalShareeListAdapter.addShares(internalShares);
556+
ViewExtensionsKt.setVisibleIf(binding.sharesListInternalShowAll, internalShareeListAdapter.getShares().size() > 3);
557+
addExternalAndInternalShares(externalShares);
558+
ViewExtensionsKt.setVisibleIf(binding.sharesListExternalShowAll, externalShareeListAdapter.getShares().size() > 3);
559+
}
553560

554-
ViewExtensionsKt.setVisibleIf(binding.sharesListInternalShowAll,
555-
internalShareeListAdapter.getShares().size() > 3
556-
);
557-
558-
externalShareeListAdapter.getShares().clear();
559-
560-
// Get public share
561-
List<OCShare> publicShares = fileDataStorageManager.getSharesByPathAndType(file.getRemotePath(),
562-
ShareType.PUBLIC_LINK,
563-
"");
564-
565-
externalShareeListAdapter.addShares(externalShares);
566-
567-
externalShareeListAdapter.addShares(publicShares);
561+
private void addExternalAndInternalShares(List<OCShare> externalShares) {
562+
List<OCShare> publicShares = fileDataStorageManager.getSharesByPathAndType(file.getRemotePath(), ShareType.PUBLIC_LINK, "");
568563

569-
ViewExtensionsKt.setVisibleIf(binding.sharesListExternalShowAll,
570-
externalShareeListAdapter.getShares().size() > 3
571-
);
564+
externalShareeListAdapter.removeAll();
565+
Stream<OCShare> combinedStream = Stream.concat(externalShares.stream(), publicShares.stream())
566+
.distinct();
567+
List<OCShare> combinedShares;
568+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
569+
combinedShares = combinedStream.toList();
570+
} else {
571+
combinedShares = combinedStream.collect(Collectors.toList());
572+
}
573+
externalShareeListAdapter.addShares(combinedShares);
572574
}
573575

574576
private void checkContactPermission() {
@@ -656,7 +658,6 @@ public void advancedPermissions(OCShare share) {
656658
modifyExistingShare(share, FileDetailsSharingProcessFragment.SCREEN_TYPE_PERMISSION);
657659
}
658660

659-
660661
@Override
661662
public void sendNewEmail(OCShare share) {
662663
modifyExistingShare(share, FileDetailsSharingProcessFragment.SCREEN_TYPE_NOTE);

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ class FileDetailsSharingProcessFragment :
778778
}
779779

780780
// region Helpers
781-
private fun isFolder(): Boolean = file?.isFolder == true || share?.isFolder == true
781+
private fun isFolder(): Boolean = (file?.isFolder == true || share?.isFolder == true)
782782

783783
private fun isPublicShare(): Boolean = (shareType == ShareType.PUBLIC_LINK)
784784
// endregion

0 commit comments

Comments
 (0)