37
37
import com .nextcloud .client .network .ClientFactory ;
38
38
import com .nextcloud .utils .extensions .BundleExtensionsKt ;
39
39
import com .nextcloud .utils .extensions .FileExtensionsKt ;
40
+ import com .nextcloud .utils .extensions .ViewExtensionsKt ;
40
41
import com .nextcloud .utils .mdm .MDMConfig ;
41
42
import com .owncloud .android .R ;
42
43
import com .owncloud .android .databinding .FileDetailsSharingFragmentBinding ;
43
44
import com .owncloud .android .datamodel .FileDataStorageManager ;
44
45
import com .owncloud .android .datamodel .OCFile ;
46
+ import com .owncloud .android .datamodel .SharesType ;
45
47
import com .owncloud .android .lib .common .OwnCloudAccount ;
46
48
import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
47
49
import com .owncloud .android .lib .common .utils .Log_OC ;
77
79
import androidx .appcompat .widget .SearchView ;
78
80
import androidx .fragment .app .Fragment ;
79
81
import androidx .recyclerview .widget .LinearLayoutManager ;
82
+ import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
80
83
81
84
public class FileDetailSharingFragment extends Fragment implements ShareeListAdapterListener ,
82
85
DisplayUtils .AvatarGenerationListener ,
@@ -97,6 +100,10 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
97
100
private FileDetailsSharingFragmentBinding binding ;
98
101
99
102
private OnEditShareListener onEditShareListener ;
103
+
104
+ private ShareeListAdapter internalShareeListAdapter ;
105
+
106
+ private ShareeListAdapter externalShareeListAdapter ;
100
107
101
108
@ Inject UserAccountManager accountManager ;
102
109
@ Inject ClientFactory clientFactory ;
@@ -162,15 +169,31 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
162
169
String userId = accountManager .getUserData (user .toPlatformAccount (),
163
170
com .owncloud .android .lib .common .accounts .AccountUtils .Constants .KEY_USER_ID );
164
171
165
- binding .sharesList .setAdapter (new ShareeListAdapter (fileActivity ,
166
- new ArrayList <>(),
167
- this ,
168
- userId ,
169
- user ,
170
- viewThemeUtils ,
171
- file .isEncrypted ()));
172
+ internalShareeListAdapter = new ShareeListAdapter (fileActivity ,
173
+ new ArrayList <>(),
174
+ this ,
175
+ userId ,
176
+ user ,
177
+ viewThemeUtils ,
178
+ file .isEncrypted (),
179
+ SharesType .INTERNAL );
172
180
173
- binding .sharesList .setLayoutManager (new LinearLayoutManager (requireContext ()));
181
+ binding .sharesListInternal .setAdapter (internalShareeListAdapter );
182
+
183
+ binding .sharesListInternal .setLayoutManager (new LinearLayoutManager (requireContext ()));
184
+
185
+ externalShareeListAdapter = new ShareeListAdapter (fileActivity ,
186
+ new ArrayList <>(),
187
+ this ,
188
+ userId ,
189
+ user ,
190
+ viewThemeUtils ,
191
+ file .isEncrypted (),
192
+ SharesType .EXTERNAL );
193
+
194
+ binding .sharesListExternal .setAdapter (externalShareeListAdapter );
195
+
196
+ binding .sharesListExternal .setLayoutManager (new LinearLayoutManager (requireContext ()));
174
197
175
198
binding .pickContactEmailBtn .setOnClickListener (v -> checkContactPermission ());
176
199
@@ -221,13 +244,36 @@ private void setupView() {
221
244
fileActivity .getComponentName ());
222
245
viewThemeUtils .androidx .themeToolbarSearchView (binding .searchView );
223
246
247
+ viewThemeUtils .material .colorMaterialTextButton (binding .sharesListInternalShowAll );
248
+ binding .sharesListInternalShowAll .setOnClickListener (view -> {
249
+ internalShareeListAdapter .toggleShowAll ();
250
+
251
+ if (internalShareeListAdapter .isShowAll ()) {
252
+ binding .sharesListInternalShowAll .setText (R .string .show_less );
253
+ } else {
254
+ binding .sharesListInternalShowAll .setText (R .string .show_all );
255
+ }
256
+ });
257
+
258
+ viewThemeUtils .material .colorMaterialTextButton (binding .sharesListExternalShowAll );
259
+ binding .sharesListExternalShowAll .setOnClickListener (view -> {
260
+ externalShareeListAdapter .toggleShowAll ();
224
261
225
- if (file .canReshare ()) {
262
+ if (internalShareeListAdapter .isShowAll ()) {
263
+ binding .sharesListExternalShowAll .setText (R .string .show_less );
264
+ } else {
265
+ binding .sharesListExternalShowAll .setText (R .string .show_all );
266
+ }
267
+ });
268
+
269
+ if (file .canReshare () && !FileDetailSharingFragmentHelper .isPublicShareDisabled (capabilities )) {
226
270
if (file .isEncrypted () || (parentFile != null && parentFile .isEncrypted ())) {
227
271
if (file .getE2eCounter () == -1 ) {
228
272
// V1 cannot share
229
273
binding .searchContainer .setVisibility (View .GONE );
274
+ binding .createLink .setVisibility (View .GONE );
230
275
} else {
276
+ binding .createLink .setText (R .string .add_new_secure_file_drop );
231
277
binding .searchView .setQueryHint (getResources ().getString (R .string .secure_share_search ));
232
278
233
279
if (file .isSharedViaLink ()) {
@@ -237,13 +283,20 @@ private void setupView() {
237
283
}
238
284
}
239
285
} else {
240
- binding .searchView .setQueryHint (getResources ().getString (R .string .share_search ));
286
+ binding .createLink .setText (R .string .create_link );
287
+ binding .searchView .setQueryHint (getResources ().getString (R .string .share_search_internal ));
241
288
}
289
+
290
+ binding .createLink .setOnClickListener (v -> createPublicShareLink ());
291
+
242
292
} else {
243
293
binding .searchView .setQueryHint (getResources ().getString (R .string .resharing_is_not_allowed ));
294
+ binding .createLink .setVisibility (View .GONE );
295
+ binding .externalSharesHeadline .setVisibility (View .GONE );
244
296
binding .searchView .setInputType (InputType .TYPE_NULL );
245
297
binding .pickContactEmailBtn .setVisibility (View .GONE );
246
298
disableSearchView (binding .searchView );
299
+ binding .createLink .setOnClickListener (null );
247
300
}
248
301
249
302
checkShareViaUser ();
@@ -453,45 +506,63 @@ public void refreshCapabilitiesFromDB() {
453
506
* Get public link from the DB to fill in the "Share link" section in the UI. Takes into account server capabilities
454
507
* before reading database.
455
508
*/
509
+ @ SuppressFBWarnings ("PSC" )
456
510
public void refreshSharesFromDB () {
457
511
OCFile newFile = fileDataStorageManager .getFileById (file .getFileId ());
458
512
if (newFile != null ) {
459
513
file = newFile ;
460
514
}
461
515
462
- ShareeListAdapter adapter = (ShareeListAdapter ) binding .sharesList .getAdapter ();
463
-
464
- if (adapter == null ) {
516
+ if (internalShareeListAdapter == null ) {
465
517
DisplayUtils .showSnackMessage (getView (), getString (R .string .could_not_retrieve_shares ));
466
518
return ;
467
519
}
468
- adapter .getShares ().clear ();
520
+ internalShareeListAdapter .getShares ().clear ();
469
521
470
522
// to show share with users/groups info
471
523
List <OCShare > shares = fileDataStorageManager .getSharesWithForAFile (file .getRemotePath (),
472
524
user .getAccountName ());
473
525
474
- adapter .addShares (shares );
526
+ List <OCShare > internalShares = new ArrayList <>();
527
+ List <OCShare > externalShares = new ArrayList <>();
475
528
476
- if (FileDetailSharingFragmentHelper .isPublicShareDisabled (capabilities ) || !file .canReshare ()) {
477
- return ;
529
+ for (OCShare share : shares ) {
530
+ if (share .getShareType () != null ) {
531
+ switch (share .getShareType ()) {
532
+ case PUBLIC_LINK :
533
+ case FEDERATED_GROUP :
534
+ case FEDERATED :
535
+ case EMAIL :
536
+ externalShares .add (share );
537
+ break ;
538
+
539
+ default :
540
+ internalShares .add (share );
541
+ break ;
542
+ }
543
+ }
478
544
}
545
+
546
+ internalShareeListAdapter .addShares (internalShares );
547
+
548
+ ViewExtensionsKt .setVisibleIf (binding .sharesListInternalShowAll ,
549
+ internalShareeListAdapter .getShares ().size () > 3
550
+ );
551
+
552
+ externalShareeListAdapter .getShares ().clear ();
479
553
480
554
// Get public share
481
555
List <OCShare > publicShares = fileDataStorageManager .getSharesByPathAndType (file .getRemotePath (),
482
556
ShareType .PUBLIC_LINK ,
483
557
"" );
484
558
485
- if (publicShares .isEmpty () && containsNoNewPublicShare (adapter .getShares ()) &&
486
- (!file .isEncrypted () || capabilities .getEndToEndEncryption ().isTrue ())) {
487
- final OCShare ocShare = new OCShare ();
488
- ocShare .setShareType (ShareType .NEW_PUBLIC_LINK );
489
- publicShares .add (ocShare );
490
- } else {
491
- adapter .removeNewPublicShare ();
492
- }
559
+ externalShareeListAdapter .addShares (externalShares );
493
560
494
- adapter .addShares (publicShares );
561
+ externalShareeListAdapter .addShares (publicShares );
562
+
563
+ ViewExtensionsKt .setVisibleIf (binding .sharesListExternalShowAll ,
564
+ externalShareeListAdapter .getShares ().size () > 3
565
+ );
495
566
}
496
567
497
568
private void checkContactPermission () {
@@ -545,16 +616,6 @@ private void handleContactResult(@NonNull Uri contactUri) {
545
616
}
546
617
}
547
618
548
- private boolean containsNoNewPublicShare (List <OCShare > shares ) {
549
- for (OCShare share : shares ) {
550
- if (share .getShareType () == ShareType .NEW_PUBLIC_LINK ) {
551
- return false ;
552
- }
553
- }
554
-
555
- return true ;
556
- }
557
-
558
619
@ Override
559
620
public void onSaveInstanceState (@ NonNull Bundle outState ) {
560
621
super .onSaveInstanceState (outState );
@@ -598,7 +659,7 @@ public void sendNewEmail(OCShare share) {
598
659
@ Override
599
660
public void unShare (OCShare share ) {
600
661
unshareWith (share );
601
- ShareeListAdapter adapter = (ShareeListAdapter ) binding .sharesList .getAdapter ();
662
+ ShareeListAdapter adapter = (ShareeListAdapter ) binding .sharesListInternal .getAdapter ();
602
663
if (adapter == null ) {
603
664
DisplayUtils .showSnackMessage (getView (), getString (R .string .failed_update_ui ));
604
665
return ;
0 commit comments