Skip to content

Commit

Permalink
implement share link creation via bottom sheet for files in OCFileList
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyScherzinger committed Jun 27, 2018
1 parent 913f650 commit 6cd1eaa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 6cd1eaa

Please sign in to comment.