4848import it .niedermann .owncloud .notes .branding .BrandingUtil ;
4949import it .niedermann .owncloud .notes .databinding .ActivityNoteShareBinding ;
5050import it .niedermann .owncloud .notes .main .MainActivity ;
51+ import it .niedermann .owncloud .notes .persistence .ApiResult ;
52+ import it .niedermann .owncloud .notes .persistence .ApiResultKt ;
5153import it .niedermann .owncloud .notes .persistence .entity .Account ;
5254import it .niedermann .owncloud .notes .persistence .entity .Note ;
5355import it .niedermann .owncloud .notes .share .adapter .ShareeListAdapter ;
6062import it .niedermann .owncloud .notes .share .helper .UsersAndGroupsSearchProvider ;
6163import it .niedermann .owncloud .notes .share .listener .NoteShareItemAction ;
6264import it .niedermann .owncloud .notes .share .listener .ShareeListAdapterListener ;
65+ import it .niedermann .owncloud .notes .share .model .CreateShareResponse ;
6366import it .niedermann .owncloud .notes .share .model .UsersAndGroupsSearchConfig ;
6467import it .niedermann .owncloud .notes .share .repository .ShareRepository ;
6568import it .niedermann .owncloud .notes .shared .model .Capabilities ;
69+ import it .niedermann .owncloud .notes .shared .model .OcsResponse ;
6670import it .niedermann .owncloud .notes .shared .util .DisplayUtils ;
6771import it .niedermann .owncloud .notes .shared .util .ShareUtil ;
6872import it .niedermann .owncloud .notes .shared .util .clipboard .ClipboardUtil ;
@@ -331,16 +335,17 @@ public void createPublicShareLink() {
331335 } else {
332336 executorService .submit (() -> {
333337 final var result = repository .addShare (note , ShareType .PUBLIC_LINK , "" , "false" , "" , 0 , "" );
334- if ( result != null ) {
335- final var message = result . getSecond ();
336- DisplayUtils .showSnackMessage (NoteShareActivity .this , message );
338+ runOnUiThread (() -> {
339+ if ( result instanceof ApiResult . Success < OcsResponse < CreateShareResponse >> successResponse ) {
340+ DisplayUtils .showSnackMessage (NoteShareActivity .this , successResponse . getMessage () );
337341
338- if (result .getFirst ()) {
339342 note .setIsShared (true );
340343 repository .updateNote (note );
341- runOnUiThread (this ::recreate );
344+ runOnUiThread (NoteShareActivity .this ::recreate );
345+ } else if (result instanceof ApiResult .Error errorResponse ) {
346+ DisplayUtils .showSnackMessage (NoteShareActivity .this , errorResponse .getMessage ());
342347 }
343- }
348+ });
344349 });
345350 }
346351 }
@@ -363,14 +368,14 @@ private void showShareLinkDialog(String link) {
363368 intentToShareLink .setType ("text/plain" );
364369 intentToShareLink .putExtra (Intent .EXTRA_SUBJECT , getString (R .string .note_share_activity_subject_shared_with_you , note .getTitle ()));
365370
366- String [] packagesToExclude = new String [] { this .getPackageName () };
371+ String [] packagesToExclude = new String []{ this .getPackageName ()};
367372 DialogFragment chooserDialog = ShareLinkToDialog .newInstance (intentToShareLink , packagesToExclude );
368373 chooserDialog .show (getSupportFragmentManager (), FTAG_CHOOSER_DIALOG );
369374 }
370375
371376 private String createInternalLink () {
372377 Uri baseUri = Uri .parse (account .getUrl ());
373- return baseUri + "/index.php/f/" + note .getRemoteId ();
378+ return baseUri + "/index.php/f/" + note .getRemoteId ();
374379 }
375380
376381 @ Override
@@ -642,7 +647,15 @@ private boolean getExpDateShown() {
642647
643648 @ Override
644649 public void onQuickPermissionChanged (OCShare share , int permission ) {
645- repository .updateSharePermission (share .getId (), permission );
650+ executorService .submit (() -> {
651+ final var result = repository .updateSharePermission (share .getId (), permission );
652+
653+ runOnUiThread (() -> {
654+ if (result instanceof ApiResult .Error error ) {
655+ DisplayUtils .showSnackMessage (NoteShareActivity .this , error .getMessage ());
656+ }
657+ });
658+ });
646659 }
647660
648661 private final ActivityResultLauncher <String > requestContactPermissionLauncher =
@@ -711,13 +724,11 @@ public void shareFileViaPublicShare(@Nullable Note note, @Nullable String passwo
711724 );
712725
713726 runOnUiThread (() -> {
714- if (result != null ) {
715- final var message = result .getSecond ();
716- DisplayUtils .showSnackMessage (NoteShareActivity .this , message );
717-
718- if (result .getFirst ()) {
719- NoteShareActivity .this .recreate ();
720- }
727+ if (ApiResultKt .isSuccess (result )) {
728+ NoteShareActivity .this .recreate ();
729+ } else if (ApiResultKt .isError (result )) {
730+ ApiResult .Error error = (ApiResult .Error ) result ;
731+ DisplayUtils .showSnackMessage (NoteShareActivity .this , error .getMessage ());
721732 }
722733 });
723734 });
@@ -730,26 +741,29 @@ public void setPasswordToShare(@NotNull OCShare share, @Nullable String password
730741 return ;
731742 }
732743
733- executorService .submit (() -> {{
734- final var requestBody = repository .getUpdateShareRequest (false ,
735- share ,
736- "" ,
737- password ,
738- false ,
739- -1 ,
740- repository .getCapabilities ().getDefaultPermission ()
741- );
742- final var success = repository .updateShare (share .getId (), requestBody );
744+ executorService .submit (() -> {
745+ {
746+ final var requestBody = repository .getUpdateShareRequest (false ,
747+ share ,
748+ "" ,
749+ password ,
750+ false ,
751+ -1 ,
752+ repository .getCapabilities ().getDefaultPermission ()
753+ );
754+ final var result = repository .updateShare (share .getId (), requestBody );
743755
744- runOnUiThread (() -> {
745- if (success ) {
746- final var intent = new Intent (NoteShareActivity .this , MainActivity .class );
747- intent .setFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
748- NoteShareActivity .this .startActivity (intent );
749- } else {
750- DisplayUtils .showSnackMessage (NoteShareActivity .this , getString (R .string .note_share_detail_activity_create_share_error ));
751- }
752- });
753- }});
756+ runOnUiThread (() -> {
757+ if (ApiResultKt .isSuccess (result )) {
758+ final var intent = new Intent (NoteShareActivity .this , MainActivity .class );
759+ intent .setFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
760+ NoteShareActivity .this .startActivity (intent );
761+ } else if (ApiResultKt .isError (result )) {
762+ ApiResult .Error error = (ApiResult .Error ) result ;
763+ DisplayUtils .showSnackMessage (NoteShareActivity .this , error .getMessage ());
764+ }
765+ });
766+ }
767+ });
754768 }
755769}
0 commit comments