implement share link creation via bottom sheet for files in OCFileList

This commit is contained in:
AndyScherzinger 2018-06-21 19:15:15 +02:00
parent 5c203f3f49
commit 0745348ce0
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 43 additions and 7 deletions

View file

@ -1940,8 +1940,10 @@ public class FileDisplayActivity extends HookActivity
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 @@ public class FileDisplayActivity extends HookActivity
}
} 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()),

View file

@ -22,6 +22,7 @@ import android.widget.TextView;
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 @@ import java.util.List;
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 class SendShareDialog extends BottomSheetDialogFragment {
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 class SendShareDialog extends BottomSheetDialogFragment {
// 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 class SendShareDialog extends BottomSheetDialogFragment {
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()),

View file

@ -56,6 +56,7 @@ import com.owncloud.android.lib.resources.files.CheckEtagOperation;
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 class FileOperationsHelper {
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");
}