-Subproject commit b09969d078b3a790b01c8d61a7298a37439a9f24
+Subproject commit c52f9c9b149f6427eeebbb68ef670b83cf3487b4
.show();
}
- public void shareFileWithLink(OCFile file) {
+
+ /**
+ /**
+ * Helper method to share a file via a public link. Starts a request to do it in {@link OperationsService}
+ *
+ * @param file The file to share.
+ */
+ public void shareFileViaLink(OCFile file) {
+ if (isSharedSupported()) {
+ if (file != null) {
+ mFileActivity.showLoadingDialog(
+ mFileActivity.getApplicationContext().
+ getString(R.string.wait_a_moment)
+ );
+ Intent service = new Intent(mFileActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
+
+ } else {
+ Log_OC.wtf(TAG, "Trying to share a NULL OCFile");
+ // TODO user-level error?
+ }
+
+ } else {
+ // Show a Message
+ Toast t = Toast.makeText(
+ mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api),
+ Toast.LENGTH_LONG
+ );
+ t.show();
+ }
+ }
+
+
+ public void shareFileWithLinkOLD(OCFile file) {
if (isSharedSupported()) {
if (file != null) {
/**
- * Helper method to share a file with a know sharee. Starts a request to do it in {@link OperationsService}
+ * Helper method to share a file with a known sharee. Starts a request to do it in {@link OperationsService}
*
* @param file The file to share.
* @param shareeName Name (user name or group name) of the target sharee.
}
return false;
}
+
}
// Update OCFile with data from share: ShareByLink and publicLink
OCFile file = getStorageManager().getFileByPath(mPath);
if (file!=null) {
- mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink());
file.setPublicLink(share.getShareLink());
file.setShareViaLink(true);
getStorageManager().saveFile(file);
+ if (mSendIntent != null) {
+ mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink());
+ }
}
}
updateFileFromDB();
Intent sendIntent = operation.getSendIntentWithSubject(this);
- startActivity(sendIntent);
+ if (sendIntent != null) {
+ startActivity(sendIntent);
+ }
+
} else {
// Detect Failure (403) --> needs Password
if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share_file: {
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
+ mContainerActivity.getFileOperationsHelper().shareFileWithLinkOLD(getFile());
return true;
}
case R.id.action_share_with_users: {
mTargetFile = (OCFile) mAdapter.getItem(filePosition);
switch (menuId) {
case R.id.action_share_file: {
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(mTargetFile);
+ mContainerActivity.getFileOperationsHelper().shareFileWithLinkOLD(mTargetFile);
return true;
}
case R.id.action_share_with_users: {
/** Public share bound to the file */
private OCShare mPublicShare;
+ /** Listener for changes on switch to share / unshare publicly */
+ private CompoundButton.OnCheckedChangeListener mOnShareViaLinkSwitchCheckedChangeListener;
+
/**
* Public factory method to create new ShareFileFragment instances.
});
// Switch to create public share
- Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch);
- shareViaLinkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ mOnShareViaLinkSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked) {
- // TODO real implementation: create public share
- // expand section
- getExpirationDateSection().setVisibility(View.VISIBLE);
- getPasswordSection().setVisibility(View.VISIBLE);
- getGetLinkButton().setVisibility(View.VISIBLE);
-
- } else {
- // TODO real implementation: unshare
- // collapse section
- getExpirationDateSection().setVisibility(View.GONE);
- getPasswordSection().setVisibility(View.GONE);
- getGetLinkButton().setVisibility(View.GONE);
- }
+ if (isResumed()) {
+ if (isChecked) {
+ ((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(mFile);
+
+ } else {
+ // TODO real implementation: unshare
+ // collapse section
+ getExpirationDateSection().setVisibility(View.GONE);
+ getPasswordSection().setVisibility(View.GONE);
+ getGetLinkButton().setVisibility(View.GONE);
+ }
+ } // else, nothing; very important, setCheched(...) is called automatically during Fragment
+ // recreation on device rotations
}
- });
+ };
+ Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch);
+ shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
// Switch for expiration date
Switch shareViaLinkExpirationSwitch = (Switch) view.findViewById(R.id.shareViaLinkExpirationSwitch);
private void updatePublicShareSection() {
if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) {
// public share bound -> expand section
- getShareViaLinkSwitch().setChecked(true);
+ Switch shareViaLinkSwitch = getShareViaLinkSwitch();
+ if (!shareViaLinkSwitch.isChecked()) {
+ // set null listener before setChecked() to prevent infinite loop of calls
+ shareViaLinkSwitch.setOnCheckedChangeListener(null);
+ getShareViaLinkSwitch().setChecked(true);
+ shareViaLinkSwitch.setOnCheckedChangeListener(
+ mOnShareViaLinkSwitchCheckedChangeListener
+ );
+ }
getExpirationDateSection().setVisibility(View.VISIBLE);
getPasswordSection().setVisibility(View.VISIBLE);
getGetLinkButton().setVisibility(View.VISIBLE);
} else {
// no public share -> collapse section
- getShareViaLinkSwitch().setChecked(false);
+ Switch shareViaLinkSwitch = getShareViaLinkSwitch();
+ if (shareViaLinkSwitch.isChecked()) {
+ shareViaLinkSwitch.setOnCheckedChangeListener(null);
+ getShareViaLinkSwitch().setChecked(false);
+ shareViaLinkSwitch.setOnCheckedChangeListener(
+ mOnShareViaLinkSwitchCheckedChangeListener
+ );
+ }
getExpirationDateSection().setVisibility(View.GONE);
getPasswordSection().setVisibility(View.GONE);
getGetLinkButton().setVisibility(View.GONE);
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share_file: {
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
+ mContainerActivity.getFileOperationsHelper().shareFileWithLinkOLD(getFile());
return true;
}
case R.id.action_share_with_users: {
switch (item.getItemId()) {
case R.id.action_share_file: {
stopPreview(false);
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
+ mContainerActivity.getFileOperationsHelper().shareFileWithLinkOLD(getFile());
return true;
}
case R.id.action_share_with_users: {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share_file: {
- mContainerActivity.getFileOperationsHelper().shareFileWithLink(getFile());
+ mContainerActivity.getFileOperationsHelper().shareFileWithLinkOLD(getFile());
return true;
}
case R.id.action_share_with_users: {