mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Share public link in ShareFileFragment
This commit is contained in:
parent
f1b3208f1a
commit
261299cf23
10 changed files with 88 additions and 28 deletions
|
@ -1 +1 @@
|
|||
Subproject commit b09969d078b3a790b01c8d61a7298a37439a9f24
|
||||
Subproject commit c52f9c9b149f6427eeebbb68ef670b83cf3487b4
|
|
@ -139,7 +139,43 @@ public class FileOperationsHelper {
|
|||
.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) {
|
||||
|
@ -194,7 +230,7 @@ public class FileOperationsHelper {
|
|||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -492,4 +528,5 @@ public class FileOperationsHelper {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,10 +148,12 @@ public class CreateShareViaLinkOperation extends SyncOperation {
|
|||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -785,7 +785,10 @@ public class FileActivity extends AppCompatActivity
|
|||
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) {
|
||||
|
|
|
@ -227,7 +227,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
|
|||
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: {
|
||||
|
|
|
@ -344,7 +344,7 @@ public class OCFileListFragment extends ExtendedListFragment
|
|||
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: {
|
||||
|
|
|
@ -92,6 +92,9 @@ public class ShareFileFragment extends Fragment
|
|||
/** 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.
|
||||
|
@ -175,26 +178,26 @@ public class ShareFileFragment extends Fragment
|
|||
});
|
||||
|
||||
// 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);
|
||||
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 {
|
||||
// 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);
|
||||
|
@ -344,14 +347,29 @@ public class ShareFileFragment extends Fragment
|
|||
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);
|
||||
|
|
|
@ -286,7 +286,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
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: {
|
||||
|
|
|
@ -350,7 +350,7 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
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: {
|
||||
|
|
|
@ -299,7 +299,7 @@ public class PreviewTextFragment extends FileFragment {
|
|||
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: {
|
||||
|
|
Loading…
Reference in a new issue