|
33 | 33 | import com.owncloud.android.lib.resources.shares.OCShare; |
34 | 34 | import com.owncloud.android.lib.resources.shares.ShareType; |
35 | 35 |
|
| 36 | +import org.jetbrains.annotations.NotNull; |
| 37 | + |
36 | 38 | import java.util.ArrayList; |
37 | 39 | import java.util.List; |
38 | 40 | import java.util.concurrent.Executors; |
|
45 | 47 | import it.niedermann.owncloud.notes.branding.BrandedSnackbar; |
46 | 48 | import it.niedermann.owncloud.notes.branding.BrandingUtil; |
47 | 49 | import it.niedermann.owncloud.notes.databinding.ActivityNoteShareBinding; |
| 50 | +import it.niedermann.owncloud.notes.main.MainActivity; |
48 | 51 | import it.niedermann.owncloud.notes.persistence.entity.Account; |
49 | 52 | import it.niedermann.owncloud.notes.persistence.entity.Note; |
50 | 53 | import it.niedermann.owncloud.notes.share.adapter.ShareeListAdapter; |
|
57 | 60 | import it.niedermann.owncloud.notes.share.helper.UsersAndGroupsSearchProvider; |
58 | 61 | import it.niedermann.owncloud.notes.share.listener.NoteShareItemAction; |
59 | 62 | import it.niedermann.owncloud.notes.share.listener.ShareeListAdapterListener; |
| 63 | +import it.niedermann.owncloud.notes.share.model.UpdateShareRequest; |
60 | 64 | import it.niedermann.owncloud.notes.share.model.UsersAndGroupsSearchConfig; |
61 | 65 | import it.niedermann.owncloud.notes.share.repository.ShareRepository; |
62 | 66 | import it.niedermann.owncloud.notes.shared.model.Capabilities; |
|
65 | 69 | import it.niedermann.owncloud.notes.shared.util.clipboard.ClipboardUtil; |
66 | 70 | import it.niedermann.owncloud.notes.shared.util.extensions.BundleExtensionsKt; |
67 | 71 |
|
68 | | -public class NoteShareActivity extends BrandedActivity implements ShareeListAdapterListener, NoteShareItemAction, QuickSharingPermissionsBottomSheetDialog.QuickPermissionSharingBottomSheetActions { |
| 72 | +public class NoteShareActivity extends BrandedActivity implements ShareeListAdapterListener, NoteShareItemAction, QuickSharingPermissionsBottomSheetDialog.QuickPermissionSharingBottomSheetActions, SharePasswordDialogFragment.SharePasswordDialogListener { |
69 | 73 |
|
70 | 74 | private static final String TAG = "NoteShareActivity"; |
71 | 75 | public static final String ARG_NOTE = "NOTE"; |
@@ -343,7 +347,7 @@ public void createPublicShareLink() { |
343 | 347 | } |
344 | 348 |
|
345 | 349 | public void requestPasswordForShareViaLink(boolean createShare, boolean askForPassword) { |
346 | | - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(note, createShare, askForPassword); |
| 350 | + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(note, createShare, askForPassword, this); |
347 | 351 | dialog.show(getSupportFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); |
348 | 352 | } |
349 | 353 |
|
@@ -405,7 +409,7 @@ public void showPermissionsDialog(OCShare share) { |
405 | 409 |
|
406 | 410 | @Override |
407 | 411 | public void requestPasswordForShare(OCShare share, boolean askForPassword) { |
408 | | - SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(share, askForPassword); |
| 412 | + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(share, askForPassword, this); |
409 | 413 | dialog.show(getSupportFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); |
410 | 414 | } |
411 | 415 |
|
@@ -688,4 +692,47 @@ protected void onDestroy() { |
688 | 692 | executorService.shutdown(); |
689 | 693 | super.onDestroy(); |
690 | 694 | } |
| 695 | + |
| 696 | + @Override |
| 697 | + public void shareFileViaPublicShare(@Nullable Note note, @Nullable String password) { |
| 698 | + if (note == null || password == null) { |
| 699 | + Log_OC.d(TAG, "note or password is null, cannot create a public share"); |
| 700 | + return; |
| 701 | + } |
| 702 | + |
| 703 | + executorService.submit(() -> { |
| 704 | + final var result = repository.addShare(note, ShareType.PUBLIC_LINK, "", "false", password, 0, ""); |
| 705 | + runOnUiThread(() -> { |
| 706 | + if (result != null) { |
| 707 | + NoteShareActivity.this.recreate(); |
| 708 | + } else { |
| 709 | + final var message = getString(R.string.note_share_activity_you_are_not_allowed_to_share); |
| 710 | + DisplayUtils.showSnackMessage(NoteShareActivity.this, message); |
| 711 | + } |
| 712 | + }); |
| 713 | + }); |
| 714 | + } |
| 715 | + |
| 716 | + @Override |
| 717 | + public void setPasswordToShare(@NotNull OCShare share, @Nullable String password) { |
| 718 | + if (password == null) { |
| 719 | + Log_OC.d(TAG, "password is null, cannot update a public share"); |
| 720 | + return; |
| 721 | + } |
| 722 | + |
| 723 | + executorService.submit(() -> {{ |
| 724 | + final var requestBody = repository.getUpdateShareRequest(false, share,"", password,false,-1,0); |
| 725 | + final var success = repository.updateShare(share.getId(), requestBody); |
| 726 | + |
| 727 | + runOnUiThread(() -> { |
| 728 | + if (success) { |
| 729 | + final var intent = new Intent(NoteShareActivity.this, MainActivity.class); |
| 730 | + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 731 | + NoteShareActivity.this.startActivity(intent); |
| 732 | + } else { |
| 733 | + DisplayUtils.showSnackMessage(NoteShareActivity.this, getString(R.string.note_share_detail_activity_create_share_error)); |
| 734 | + } |
| 735 | + }); |
| 736 | + }}); |
| 737 | + } |
691 | 738 | } |
0 commit comments