2323import android .database .Cursor ;
2424import android .graphics .drawable .Drawable ;
2525import android .net .Uri ;
26+ import android .os .Build ;
2627import android .os .Bundle ;
2728import android .provider .ContactsContract ;
2829import android .text .InputType ;
6061import com .owncloud .android .ui .asynctasks .RetrieveHoverCardAsyncTask ;
6162import com .owncloud .android .ui .dialog .SharePasswordDialogFragment ;
6263import com .owncloud .android .ui .fragment .util .FileDetailSharingFragmentHelper ;
63- import com .owncloud .android .ui .fragment .util .SharePermissionManager ;
6464import com .owncloud .android .ui .helpers .FileOperationsHelper ;
6565import com .owncloud .android .utils .ClipboardUtil ;
6666import com .owncloud .android .utils .DisplayUtils ;
6969
7070import java .util .ArrayList ;
7171import java .util .List ;
72+ import java .util .stream .Collectors ;
73+ import java .util .stream .Stream ;
7274
7375import 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 );
0 commit comments