From 0745348ce0a6da6534f4b6968d6a35ef2168f577 Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Thu, 21 Jun 2018 19:15:15 +0200 Subject: [PATCH] implement share link creation via bottom sheet for files in OCFileList --- .../ui/activity/FileDisplayActivity.java | 10 +++++-- .../android/ui/dialog/SendShareDialog.java | 30 +++++++++++++++++-- .../ui/helpers/FileOperationsHelper.java | 10 ++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index f60d6385af39..c9544e97cab7 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1940,8 +1940,10 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude); chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG); - fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB(); - fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile()); + if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) { + fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB(); + fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile()); + } refreshListOfFilesFragment(false); } else { // Detect Failure (403) --> maybe needs password @@ -1959,7 +1961,9 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope } } else { - fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB(); + if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) { + fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB(); + } Snackbar.make( findViewById(android.R.id.content), ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), diff --git a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java index 4577881b58ee..c312e34ffcde 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java @@ -22,6 +22,7 @@ import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.adapter.SendButtonAdapter; import com.owncloud.android.ui.components.SendButtonData; @@ -57,6 +58,7 @@ public class SendShareDialog extends BottomSheetDialogFragment { private static final String KEY_OCFILE = "KEY_OCFILE"; + private static final String KEY_SHARING_PUBLIC_PASSWORD_ENFORCED = "KEY_SHARING_PUBLIC_PASSWORD_ENFORCED"; private static final String KEY_HIDE_NCSHARING_OPTIONS = "KEY_HIDE_NCSHARING_OPTIONS"; private static final String TAG = SendShareDialog.class.getSimpleName(); public static final String PACKAGE_NAME = "PACKAGE_NAME"; @@ -65,15 +67,17 @@ public class SendShareDialog extends BottomSheetDialogFragment { private View view; private OCFile file; private boolean hideNcSharingOptions; + private boolean sharingPublicPasswordEnforced; private FileOperationsHelper fileOperationsHelper; - public static SendShareDialog newInstance(OCFile file, boolean hideNcSharingOptions) { + public static SendShareDialog newInstance(OCFile file, boolean hideNcSharingOptions, boolean sharingPublicPasswordEnforced) { SendShareDialog dialogFragment = new SendShareDialog(); Bundle args = new Bundle(); args.putParcelable(KEY_OCFILE, file); args.putBoolean(KEY_HIDE_NCSHARING_OPTIONS, hideNcSharingOptions); + args.putBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, sharingPublicPasswordEnforced); dialogFragment.setArguments(args); return dialogFragment; @@ -89,6 +93,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { file = getArguments().getParcelable(KEY_OCFILE); hideNcSharingOptions = getArguments().getBoolean(KEY_HIDE_NCSHARING_OPTIONS, false); + sharingPublicPasswordEnforced = getArguments().getBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, false); } @Nullable @@ -110,11 +115,11 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, // Share via link button TextView shareLinkText = view.findViewById(R.id.share_link_button); - shareLinkText.setOnClickListener(v -> shareFile(file)); + shareLinkText.setOnClickListener(v -> shareByLink()); ImageView shareLinkImageView = view.findViewById(R.id.share_link_icon); themeShareButtonImage(shareLinkImageView); - shareLinkImageView.setOnClickListener(v -> shareFile(file)); + shareLinkImageView.setOnClickListener(v -> shareByLink()); if (hideNcSharingOptions) { sendShareButtons.setVisibility(View.GONE); @@ -159,6 +164,25 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, return view; } + private void shareByLink() { + if (file.isSharedViaLink()) { + ((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file); + } else if (sharingPublicPasswordEnforced) { + // password enforced by server, request to the user before trying to create + requestPasswordForShareViaLink(); + } else { + // create without password if not enforced by server or we don't know if enforced; + ((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(file, null); + } + + this.dismiss(); + } + + private void requestPasswordForShareViaLink() { + SharePasswordDialogFragment dialog = SharePasswordDialogFragment.newInstance(file, true); + dialog.show(getFragmentManager(), SharePasswordDialogFragment.PASSWORD_FRAGMENT); + } + private void themeShareButtonImage(ImageView shareImageView) { shareImageView.getBackground().setColorFilter(ThemeUtils.elementColor(getContext()), PorterDuff.Mode.SRC_IN); shareImageView.getDrawable().mutate().setColorFilter(ThemeUtils.fontColor(getContext()), diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 04e0ef23a8c9..db11347db055 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -56,6 +56,7 @@ import com.owncloud.android.lib.resources.files.FileVersion; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.services.OperationsService; @@ -689,7 +690,14 @@ public void sendShareFile(OCFile file, boolean hideNcSharingOptions) { FragmentTransaction ft = fm.beginTransaction(); ft.addToBackStack(null); - SendShareDialog mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions); + OCCapability capability = mFileActivity.getStorageManager().getCapability(mFileActivity.getAccount().name); + SendShareDialog mSendShareDialog; + if (capability != null) { + mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions, + capability.getFilesSharingPublicPasswordEnforced().isTrue()); + } else { + mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions, false); + } mSendShareDialog.setFileOperationsHelper(this); mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG"); }