mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
implement share link creation via bottom sheet for files in OCFileList
This commit is contained in:
parent
5c203f3f49
commit
0745348ce0
3 changed files with 43 additions and 7 deletions
|
@ -1940,8 +1940,10 @@ public class FileDisplayActivity extends HookActivity
|
||||||
DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude);
|
DialogFragment chooserDialog = ShareLinkToDialog.newInstance(intentToShareLink, packagesToExclude);
|
||||||
chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
|
chooserDialog.show(getSupportFragmentManager(), FTAG_CHOOSER_DIALOG);
|
||||||
|
|
||||||
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) {
|
||||||
fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile());
|
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
||||||
|
fileDetailFragment.getFileDetailSharingFragment().onUpdateShareInformation(result, getFile());
|
||||||
|
}
|
||||||
refreshListOfFilesFragment(false);
|
refreshListOfFilesFragment(false);
|
||||||
} else {
|
} else {
|
||||||
// Detect Failure (403) --> maybe needs password
|
// Detect Failure (403) --> maybe needs password
|
||||||
|
@ -1959,7 +1961,9 @@ public class FileDisplayActivity extends HookActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) {
|
||||||
|
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();
|
||||||
|
}
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
findViewById(android.R.id.content),
|
findViewById(android.R.id.content),
|
||||||
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.widget.TextView;
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
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.activity.FileDisplayActivity;
|
||||||
import com.owncloud.android.ui.adapter.SendButtonAdapter;
|
import com.owncloud.android.ui.adapter.SendButtonAdapter;
|
||||||
import com.owncloud.android.ui.components.SendButtonData;
|
import com.owncloud.android.ui.components.SendButtonData;
|
||||||
|
@ -57,6 +58,7 @@ import java.util.List;
|
||||||
public class SendShareDialog extends BottomSheetDialogFragment {
|
public class SendShareDialog extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
private static final String KEY_OCFILE = "KEY_OCFILE";
|
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 KEY_HIDE_NCSHARING_OPTIONS = "KEY_HIDE_NCSHARING_OPTIONS";
|
||||||
private static final String TAG = SendShareDialog.class.getSimpleName();
|
private static final String TAG = SendShareDialog.class.getSimpleName();
|
||||||
public static final String PACKAGE_NAME = "PACKAGE_NAME";
|
public static final String PACKAGE_NAME = "PACKAGE_NAME";
|
||||||
|
@ -65,15 +67,17 @@ public class SendShareDialog extends BottomSheetDialogFragment {
|
||||||
private View view;
|
private View view;
|
||||||
private OCFile file;
|
private OCFile file;
|
||||||
private boolean hideNcSharingOptions;
|
private boolean hideNcSharingOptions;
|
||||||
|
private boolean sharingPublicPasswordEnforced;
|
||||||
private FileOperationsHelper fileOperationsHelper;
|
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();
|
SendShareDialog dialogFragment = new SendShareDialog();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putParcelable(KEY_OCFILE, file);
|
args.putParcelable(KEY_OCFILE, file);
|
||||||
args.putBoolean(KEY_HIDE_NCSHARING_OPTIONS, hideNcSharingOptions);
|
args.putBoolean(KEY_HIDE_NCSHARING_OPTIONS, hideNcSharingOptions);
|
||||||
|
args.putBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, sharingPublicPasswordEnforced);
|
||||||
dialogFragment.setArguments(args);
|
dialogFragment.setArguments(args);
|
||||||
|
|
||||||
return dialogFragment;
|
return dialogFragment;
|
||||||
|
@ -89,6 +93,7 @@ public class SendShareDialog extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
file = getArguments().getParcelable(KEY_OCFILE);
|
file = getArguments().getParcelable(KEY_OCFILE);
|
||||||
hideNcSharingOptions = getArguments().getBoolean(KEY_HIDE_NCSHARING_OPTIONS, false);
|
hideNcSharingOptions = getArguments().getBoolean(KEY_HIDE_NCSHARING_OPTIONS, false);
|
||||||
|
sharingPublicPasswordEnforced = getArguments().getBoolean(KEY_SHARING_PUBLIC_PASSWORD_ENFORCED, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -110,11 +115,11 @@ public class SendShareDialog extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
// Share via link button
|
// Share via link button
|
||||||
TextView shareLinkText = view.findViewById(R.id.share_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);
|
ImageView shareLinkImageView = view.findViewById(R.id.share_link_icon);
|
||||||
themeShareButtonImage(shareLinkImageView);
|
themeShareButtonImage(shareLinkImageView);
|
||||||
shareLinkImageView.setOnClickListener(v -> shareFile(file));
|
shareLinkImageView.setOnClickListener(v -> shareByLink());
|
||||||
|
|
||||||
if (hideNcSharingOptions) {
|
if (hideNcSharingOptions) {
|
||||||
sendShareButtons.setVisibility(View.GONE);
|
sendShareButtons.setVisibility(View.GONE);
|
||||||
|
@ -159,6 +164,25 @@ public class SendShareDialog extends BottomSheetDialogFragment {
|
||||||
return view;
|
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) {
|
private void themeShareButtonImage(ImageView shareImageView) {
|
||||||
shareImageView.getBackground().setColorFilter(ThemeUtils.elementColor(getContext()), PorterDuff.Mode.SRC_IN);
|
shareImageView.getBackground().setColorFilter(ThemeUtils.elementColor(getContext()), PorterDuff.Mode.SRC_IN);
|
||||||
shareImageView.getDrawable().mutate().setColorFilter(ThemeUtils.fontColor(getContext()),
|
shareImageView.getDrawable().mutate().setColorFilter(ThemeUtils.fontColor(getContext()),
|
||||||
|
|
|
@ -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.files.FileVersion;
|
||||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
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.lib.resources.status.OwnCloudVersion;
|
||||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||||
import com.owncloud.android.services.OperationsService;
|
import com.owncloud.android.services.OperationsService;
|
||||||
|
@ -689,7 +690,14 @@ public class FileOperationsHelper {
|
||||||
FragmentTransaction ft = fm.beginTransaction();
|
FragmentTransaction ft = fm.beginTransaction();
|
||||||
ft.addToBackStack(null);
|
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.setFileOperationsHelper(this);
|
||||||
mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG");
|
mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue