use correct file for message while sharing via link

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2019-07-03 10:39:29 +02:00
parent d78900e07c
commit 0e26340a19
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
4 changed files with 14 additions and 20 deletions

View file

@ -656,16 +656,16 @@ public abstract class FileActivity extends DrawerActivity
}
}
public static void copyAndShareFileLink(FileActivity activity, String link) {
public static void copyAndShareFileLink(FileActivity activity, OCFile file, String link) {
ClipboardUtil.copyToClipboard(activity, link, false);
Snackbar snackbar = Snackbar.make(activity.findViewById(android.R.id.content), R.string.clipboard_text_copied,
Snackbar.LENGTH_LONG)
.setAction(R.string.share, v -> showShareLinkDialog(activity, link));
.setAction(R.string.share, v -> showShareLinkDialog(activity, file, link));
ThemeUtils.colorSnackbar(activity, snackbar);
snackbar.show();
}
public static void showShareLinkDialog(FileActivity activity, String link) {
public static void showShareLinkDialog(FileActivity activity, OCFile file, String link) {
// Create dialog to allow the user choose an app to send the link
Intent intentToShareLink = new Intent(Intent.ACTION_SEND);
@ -689,11 +689,11 @@ public abstract class FileActivity extends DrawerActivity
if (username != null) {
intentToShareLink.putExtra(Intent.EXTRA_SUBJECT,
activity.getString(R.string.subject_user_shared_with_you, username,
activity.getFile().getFileName()));
file.getFileName()));
} else {
intentToShareLink.putExtra(Intent.EXTRA_SUBJECT,
activity.getString(R.string.subject_shared_with_you,
activity.getFile().getFileName()));
file.getFileName()));
}
String[] packagesToExclude = new String[]{activity.getPackageName()};

View file

@ -1987,15 +1987,17 @@ public class FileDisplayActivity extends FileActivity
// if share to user and share via link multiple ocshares are returned,
// therefore filtering for public_link
String link = "";
OCFile file = null;
for (Object object : result.getData()) {
OCShare shareLink = (OCShare) object;
if (TAG_PUBLIC_LINK.equalsIgnoreCase(shareLink.getShareType().name())) {
link = shareLink.getShareLink();
file = getStorageManager().getFileByPath(shareLink.getPath());
break;
}
}
copyAndShareFileLink(this, link);
copyAndShareFileLink(this, file, link);
if (fileDetailFragment != null && fileDetailFragment.getFileDetailSharingFragment() != null) {
fileDetailFragment.getFileDetailSharingFragment().refreshPublicShareFromDB();

View file

@ -346,7 +346,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
return;
}
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, createInternalLink(account, file));
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, createInternalLink(account, file));
}
private String createInternalLink(OwnCloudAccount account, OCFile file) {
@ -371,7 +371,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
if (TextUtils.isEmpty(file.getPublicLink())) {
fileOperationsHelper.getFileWithLink(file);
} else {
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file.getPublicLink());
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, file.getPublicLink());
}
}
}
@ -466,7 +466,7 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
}
case R.id.action_share_send_link: {
if(shareByLink.isChecked() && file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) {
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file.getPublicLink());
FileDisplayActivity.showShareLinkDialog(fileDisplayActivity, file, file.getPublicLink());
} else {
showSendLinkTo();
}

View file

@ -59,7 +59,6 @@ import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.ClipboardUtil;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ThemeUtils;
@ -210,15 +209,17 @@ public class PreviewImageActivity extends FileActivity implements
// if share to user and share via link multiple ocshares are returned,
// therefore filtering for public_link
String link = "";
OCFile file = null;
for (Object object : result.getData()) {
OCShare shareLink = (OCShare) object;
if (FileDisplayActivity.TAG_PUBLIC_LINK.equalsIgnoreCase(shareLink.getShareType().name())) {
link = shareLink.getShareLink();
file = getStorageManager().getFileByPath(shareLink.getPath());
break;
}
}
copyAndShareFileLink(link);
copyAndShareFileLink(this, file, link);
} else {
// Detect Failure (403) --> maybe needs password
String password = op.getPassword();
@ -239,15 +240,6 @@ public class PreviewImageActivity extends FileActivity implements
}
}
private void copyAndShareFileLink(String link) {
ClipboardUtil.copyToClipboard(this, link, false);
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), R.string.clipboard_text_copied,
Snackbar.LENGTH_LONG)
.setAction(R.string.share, v -> showShareLinkDialog(this, link));
ThemeUtils.colorSnackbar(this, snackbar);
snackbar.show();
}
private void onSynchronizeFileOperationFinish(RemoteOperationResult result) {
if (result.isSuccess()) {
supportInvalidateOptionsMenu();