Commit 79b6d163 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

file transfer: update for new API

Change-Id: I24add1f0bcdb5847245dc66f84585bd65d6e7042
parent b7f1f383
...@@ -181,8 +181,8 @@ STATIC_LIBS_ALL="-llog -lOpenSLES -landroid \ ...@@ -181,8 +181,8 @@ STATIC_LIBS_ALL="-llog -lOpenSLES -landroid \
-lyaml-cpp -ljsoncpp -lhttp_parser -lfmt\ -lyaml-cpp -ljsoncpp -lhttp_parser -lfmt\
-luuid -lz -ldl \ -luuid -lz -ldl \
-lvpx -lopus -lspeex -lspeexdsp -lx264 \ -lvpx -lopus -lspeex -lspeexdsp -lx264 \
-largon2 \
-lgit2 \ -lgit2 \
-largon2 \
-liconv" -liconv"
LIBRING_JNI_DIR=${ANDROID_APP_DIR}/app/src/main/libs/${ANDROID_ABI} LIBRING_JNI_DIR=${ANDROID_APP_DIR}/app/src/main/libs/${ANDROID_ABI}
......
...@@ -442,31 +442,19 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -442,31 +442,19 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
if (interaction.getType() == (InteractionType.CONTACT)) if (interaction.getType() == (InteractionType.CONTACT))
return false; return false;
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.conv_action_download: { if (itemId == R.id.conv_action_download) {
presenter.saveFile(interaction); presenter.saveFile(interaction);
break; } else if (itemId == R.id.conv_action_share) {
} presenter.shareFile(interaction);
case R.id.conv_action_share: { } else if (itemId == R.id.conv_action_open) {
presenter.shareFile(interaction); presenter.openFile(interaction);
break; } else if (itemId == R.id.conv_action_delete) {
} presenter.deleteConversationItem(interaction);
case R.id.conv_action_open: { } else if (itemId == R.id.conv_action_cancel_message) {
presenter.openFile(interaction); presenter.cancelMessage(interaction);
break; } else if (itemId == R.id.conv_action_copy_text) {
} addToClipboard((interaction).getBody());
case R.id.conv_action_delete: {
presenter.deleteConversationItem(interaction);
break;
}
case R.id.conv_action_cancel_message: {
presenter.cancelMessage(interaction);
break;
}
case R.id.conv_action_copy_text: {
addToClipboard((interaction).getBody());
break;
}
} }
return true; return true;
} }
...@@ -487,8 +475,10 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -487,8 +475,10 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
viewHolder.mImage.setOnClickListener(v -> { viewHolder.mImage.setOnClickListener(v -> {
Uri contentUri = ContentUriHandler.getUriForFile(v.getContext(), ContentUriHandler.AUTHORITY_FILES, path); Uri contentUri = ContentUriHandler.getUriForFile(v.getContext(), ContentUriHandler.AUTHORITY_FILES, path);
Intent i = new Intent(context, MediaViewerActivity.class); Intent i = new Intent(context, MediaViewerActivity.class)
i.setAction(Intent.ACTION_VIEW).setDataAndType(contentUri, "image/*").setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); .setAction(Intent.ACTION_VIEW)
.setDataAndType(contentUri, "image/*")
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ActivityOptionsCompat options = ActivityOptionsCompat. ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(conversationFragment.getActivity(), viewHolder.mImage, "picture"); makeSceneTransitionAnimation(conversationFragment.getActivity(), viewHolder.mImage, "picture");
conversationFragment.startActivityForResult(i, 3006, options.toBundle()); conversationFragment.startActivityForResult(i, 3006, options.toBundle());
...@@ -628,23 +618,24 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -628,23 +618,24 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
private void configureForFileInfo(@NonNull final ConversationViewHolder viewHolder, private void configureForFileInfo(@NonNull final ConversationViewHolder viewHolder,
@NonNull final Interaction interaction, int position) { @NonNull final Interaction interaction, int position) {
DataTransfer file = (DataTransfer) interaction; DataTransfer file = (DataTransfer) interaction;
File path = presenter.getDeviceRuntimeService().getConversationPath(interaction.getConversationId() == null ? interaction.getConversation().getParticipant() : interaction.getConversationId(), file.getStoragePath());
File path = presenter.getDeviceRuntimeService().getConversationPath(file);
if (file.isComplete()) if (file.isComplete())
file.setSize(path.length()); file.setSize(path.length());
String timeString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp()); String timeString = timestampToDetailString(viewHolder.itemView.getContext(), file.getTimestamp());
viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(t -> { viewHolder.compositeDisposable.add(timestampUpdateTimer.subscribe(time -> {
if (file.getStatus() == InteractionStatus.TRANSFER_FINISHED) { InteractionStatus status = file.getStatus();
if (status == InteractionStatus.TRANSFER_FINISHED) {
viewHolder.mMsgDetailTxt.setText(String.format("%s - %s", viewHolder.mMsgDetailTxt.setText(String.format("%s - %s",
timeString, Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize()))); timeString, Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize())));
} else if (file.getStatus() == InteractionStatus.TRANSFER_ONGOING) { } else if (status == InteractionStatus.TRANSFER_ONGOING) {
viewHolder.mMsgDetailTxt.setText(String.format("%s / %s - %s", viewHolder.mMsgDetailTxt.setText(String.format("%s / %s - %s",
Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getBytesProgress()), Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize()), Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getBytesProgress()), Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize()),
ResourceMapper.getReadableFileTransferStatus(conversationFragment.getActivity(), file.getStatus()))); ResourceMapper.getReadableFileTransferStatus(viewHolder.itemView.getContext(), status)));
} else { } else {
viewHolder.mMsgDetailTxt.setText(String.format("%s - %s - %s", viewHolder.mMsgDetailTxt.setText(String.format("%s - %s - %s",
timeString, Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize()), timeString, Formatter.formatFileSize(viewHolder.itemView.getContext(), file.getTotalSize()),
ResourceMapper.getReadableFileTransferStatus(conversationFragment.getActivity(), file.getStatus()))); ResourceMapper.getReadableFileTransferStatus(viewHolder.itemView.getContext(), status)));
} }
})); }));
...@@ -731,7 +722,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -731,7 +722,8 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
} else if (type == TransferMsgType.AUDIO) { } else if (type == TransferMsgType.AUDIO) {
configureAudio(viewHolder, path); configureAudio(viewHolder, path);
} else { } else {
if (file.getStatus().isError()) { InteractionStatus status = file.getStatus();
if (status.isError()) {
viewHolder.mIcon.setImageResource(R.drawable.baseline_warning_24); viewHolder.mIcon.setImageResource(R.drawable.baseline_warning_24);
} else { } else {
viewHolder.mIcon.setImageResource(R.drawable.baseline_attach_file_24); viewHolder.mIcon.setImageResource(R.drawable.baseline_attach_file_24);
...@@ -739,13 +731,18 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -739,13 +731,18 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
viewHolder.mMsgTxt.setText(file.getDisplayName()); viewHolder.mMsgTxt.setText(file.getDisplayName());
if (file.getStatus() == InteractionStatus.TRANSFER_AWAITING_HOST) { if (status == InteractionStatus.TRANSFER_AWAITING_HOST) {
viewHolder.btnRefuse.setVisibility(View.VISIBLE);
viewHolder.mAnswerLayout.setVisibility(View.VISIBLE); viewHolder.mAnswerLayout.setVisibility(View.VISIBLE);
viewHolder.btnAccept.setOnClickListener(v -> presenter.acceptFile(file)); viewHolder.btnAccept.setOnClickListener(v -> presenter.acceptFile(file));
viewHolder.btnRefuse.setOnClickListener(v -> presenter.refuseFile(file)); viewHolder.btnRefuse.setOnClickListener(v -> presenter.refuseFile(file));
} else if (status == InteractionStatus.FILE_AVAILABLE) {
viewHolder.btnRefuse.setVisibility(View.GONE);
viewHolder.mAnswerLayout.setVisibility(View.VISIBLE);
viewHolder.btnAccept.setOnClickListener(v -> presenter.acceptFile(file));
} else { } else {
viewHolder.mAnswerLayout.setVisibility(View.GONE); viewHolder.mAnswerLayout.setVisibility(View.GONE);
if (file.getStatus() == InteractionStatus.TRANSFER_ONGOING) { if (status == InteractionStatus.TRANSFER_ONGOING) {
viewHolder.progress.setMax((int) (file.getTotalSize() / 1024)); viewHolder.progress.setMax((int) (file.getTotalSize() / 1024));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
viewHolder.progress.setProgress((int) (file.getBytesProgress() / 1024), true); viewHolder.progress.setProgress((int) (file.getBytesProgress() / 1024), true);
...@@ -1194,14 +1191,14 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo ...@@ -1194,14 +1191,14 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationViewHo
FIRST, FIRST,
MIDDLE, MIDDLE,
LAST, LAST,
SINGLE; SINGLE
} }
private enum TransferMsgType { private enum TransferMsgType {
FILE, FILE,
IMAGE, IMAGE,
AUDIO, AUDIO,
VIDEO; VIDEO
} }
public enum MessageType { public enum MessageType {
INCOMING_FILE(R.layout.item_conv_file_peer), INCOMING_FILE(R.layout.item_conv_file_peer),
......
...@@ -759,23 +759,25 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen ...@@ -759,23 +759,25 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
return; return;
} }
requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class) requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, transfer.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
} }
@Override @Override
public void refuseFile(String accountId, Uri conversationUri, DataTransfer transfer) { public void refuseFile(String accountId, Uri conversationUri, DataTransfer transfer) {
requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class) requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL, ConversationPath.toUri(accountId, conversationUri), requireContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, transfer.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
} }
@Override @Override
public void shareFile(File path) { public void shareFile(File path, String displayName) {
Context c = getContext(); Context c = getContext();
if (c == null) if (c == null)
return; return;
android.net.Uri fileUri = null; android.net.Uri fileUri = null;
try { try {
fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path, displayName);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e("File Selector", "The selected file can't be shared: " + path.getName()); Log.e("File Selector", "The selected file can't be shared: " + path.getName());
} }
...@@ -783,7 +785,7 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen ...@@ -783,7 +785,7 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
Intent sendIntent = new Intent(); Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String type = c.getContentResolver().getType(fileUri); String type = c.getContentResolver().getType(fileUri.buildUpon().appendPath(displayName).build());
sendIntent.setDataAndType(fileUri, type); sendIntent.setDataAndType(fileUri, type);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(sendIntent, null)); startActivity(Intent.createChooser(sendIntent, null));
...@@ -791,13 +793,13 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen ...@@ -791,13 +793,13 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
} }
@Override @Override
public void openFile(File path) { public void openFile(File path, String displayName) {
Context c = getContext(); Context c = getContext();
if (c == null) if (c == null)
return; return;
android.net.Uri fileUri = null; android.net.Uri fileUri = null;
try { try {
fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path); fileUri = ContentUriHandler.getUriForFile(c, ContentUriHandler.AUTHORITY_FILES, path, displayName);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "The selected file can't be shared: " + path.getName()); Log.e(TAG, "The selected file can't be shared: " + path.getName());
} }
...@@ -805,7 +807,7 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen ...@@ -805,7 +807,7 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
Intent sendIntent = new Intent(); Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW); sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String type = c.getContentResolver().getType(fileUri); String type = c.getContentResolver().getType(fileUri.buildUpon().appendPath(displayName).build());
sendIntent.setDataAndType(fileUri, type); sendIntent.setDataAndType(fileUri, type);
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
//startActivity(Intent.createChooser(sendIntent, null)); //startActivity(Intent.createChooser(sendIntent, null));
......
...@@ -97,6 +97,7 @@ public class DRingService extends Service { ...@@ -97,6 +97,7 @@ public class DRingService extends Service {
static public final String ACTION_FILE_ACCEPT = BuildConfig.APPLICATION_ID + ".action.FILE_ACCEPT"; static public final String ACTION_FILE_ACCEPT = BuildConfig.APPLICATION_ID + ".action.FILE_ACCEPT";
static public final String ACTION_FILE_CANCEL = BuildConfig.APPLICATION_ID + ".action.FILE_CANCEL"; static public final String ACTION_FILE_CANCEL = BuildConfig.APPLICATION_ID + ".action.FILE_CANCEL";
static public final String KEY_MESSAGE_ID = "messageId";
static public final String KEY_TRANSFER_ID = "transferId"; static public final String KEY_TRANSFER_ID = "transferId";
static public final String KEY_TEXT_REPLY = "textReply"; static public final String KEY_TEXT_REPLY = "textReply";
...@@ -651,13 +652,14 @@ public class DRingService extends Service { ...@@ -651,13 +652,14 @@ public class DRingService extends Service {
} }
private void handleFileAction(android.net.Uri uri, String action, Bundle extras) { private void handleFileAction(android.net.Uri uri, String action, Bundle extras) {
long id = extras.getLong(KEY_TRANSFER_ID); String messageId = extras.getString(KEY_MESSAGE_ID);
String id = extras.getString(KEY_TRANSFER_ID);
ConversationPath path = ConversationPath.fromUri(uri); ConversationPath path = ConversationPath.fromUri(uri);
if (action.equals(ACTION_FILE_ACCEPT)) { if (action.equals(ACTION_FILE_ACCEPT)) {
mNotificationService.removeTransferNotification(path.getAccountId(), path.getConversationUri(), id); mNotificationService.removeTransferNotification(path.getAccountId(), path.getConversationUri(), id);
mAccountService.acceptFileTransfer(path.getAccountId(), path.getConversationUri(), id); mAccountService.acceptFileTransfer(path.getAccountId(), path.getConversationUri(), messageId, id);
} else if (action.equals(ACTION_FILE_CANCEL)) { } else if (action.equals(ACTION_FILE_CANCEL)) {
mConversationFacade.cancelFileTransfer(path.getAccountId(), path.getConversationUri(), id); mConversationFacade.cancelFileTransfer(path.getAccountId(), path.getConversationUri(), messageId, id);
} }
} }
......
...@@ -97,6 +97,11 @@ public class DeviceRuntimeServiceImpl extends DeviceRuntimeService { ...@@ -97,6 +97,11 @@ public class DeviceRuntimeServiceImpl extends DeviceRuntimeService {
return AndroidFileUtils.getConversationPath(mContext, conversationId, name); return AndroidFileUtils.getConversationPath(mContext, conversationId, name);
} }
@Override
public File getConversationPath(String accountId, String conversationId, String name) {
return AndroidFileUtils.getConversationPath(mContext, accountId, conversationId, name);
}
@Override @Override
public File getTemporaryPath(String conversationId, String name) { public File getTemporaryPath(String conversationId, String name) {
return AndroidFileUtils.getTempPath(mContext, conversationId, name); return AndroidFileUtils.getTempPath(mContext, conversationId, name);
......
...@@ -471,12 +471,12 @@ public class NotificationServiceImpl implements NotificationService { ...@@ -471,12 +471,12 @@ public class NotificationServiceImpl implements NotificationService {
if (!remove) { if (!remove) {
showFileTransferNotification(conversation, transfer); showFileTransferNotification(conversation, transfer);
} else { } else {
removeTransferNotification(ConversationPath.toUri(conversation), transfer.getDaemonId()); removeTransferNotification(ConversationPath.toUri(conversation), transfer.getFileId());
} }
} }
@Override @Override
public void removeTransferNotification(String accountId, Uri conversationUri, long transferId) { public void removeTransferNotification(String accountId, Uri conversationUri, String transferId) {
removeTransferNotification(ConversationPath.toUri(accountId, conversationUri), transferId); removeTransferNotification(ConversationPath.toUri(accountId, conversationUri), transferId);
} }
...@@ -485,7 +485,7 @@ public class NotificationServiceImpl implements NotificationService { ...@@ -485,7 +485,7 @@ public class NotificationServiceImpl implements NotificationService {
* *
* @param transferId the transfer id which is required to generate the notification id * @param transferId the transfer id which is required to generate the notification id
*/ */
public void removeTransferNotification(android.net.Uri path, long transferId) { public void removeTransferNotification(android.net.Uri path, String transferId) {
int id = getFileTransferNotificationId(path, transferId); int id = getFileTransferNotificationId(path, transferId);
dataTransferNotifications.remove(id); dataTransferNotifications.remove(id);
cancelFileNotification(id, false); cancelFileNotification(id, false);
...@@ -749,7 +749,7 @@ public class NotificationServiceImpl implements NotificationService { ...@@ -749,7 +749,7 @@ public class NotificationServiceImpl implements NotificationService {
} }
android.net.Uri path = ConversationPath.toUri(conversation); android.net.Uri path = ConversationPath.toUri(conversation);
Log.d(TAG, "showFileTransferNotification " + path); Log.d(TAG, "showFileTransferNotification " + path);
long dataTransferId = info.getDaemonId(); String dataTransferId = info.getFileId();
int notificationId = getFileTransferNotificationId(path, dataTransferId); int notificationId = getFileTransferNotificationId(path, dataTransferId);
Intent intentConversation = new Intent(DRingService.ACTION_CONV_ACCEPT, path, mContext, DRingService.class); Intent intentConversation = new Intent(DRingService.ACTION_CONV_ACCEPT, path, mContext, DRingService.class);
...@@ -955,7 +955,7 @@ public class NotificationServiceImpl implements NotificationService { ...@@ -955,7 +955,7 @@ public class NotificationServiceImpl implements NotificationService {
return (NOTIF_MSG + accountId + contact.toString()).hashCode(); return (NOTIF_MSG + accountId + contact.toString()).hashCode();
} }
private int getFileTransferNotificationId(android.net.Uri path, long dataTransferId) { private int getFileTransferNotificationId(android.net.Uri path, String dataTransferId) {
return (NOTIF_FILE_TRANSFER + path.toString() + dataTransferId).hashCode(); return (NOTIF_FILE_TRANSFER + path.toString() + dataTransferId).hashCode();
} }
......
...@@ -632,13 +632,15 @@ public class TvConversationAdapter extends RecyclerView.Adapter<TvConversationVi ...@@ -632,13 +632,15 @@ public class TvConversationAdapter extends RecyclerView.Adapter<TvConversationVi
} }
context.startService(new Intent(DRingService.ACTION_FILE_ACCEPT) context.startService(new Intent(DRingService.ACTION_FILE_ACCEPT)
.setClass(context.getApplicationContext(), DRingService.class) .setClass(context.getApplicationContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, file.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, file.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, file.getFileId()));
}); });
viewHolder.btnRefuse.setOnClickListener(v -> { viewHolder.btnRefuse.setOnClickListener(v -> {
Context context = v.getContext(); Context context = v.getContext();
context.startService(new Intent(DRingService.ACTION_FILE_CANCEL) context.startService(new Intent(DRingService.ACTION_FILE_CANCEL)
.setClass(context.getApplicationContext(), DRingService.class) .setClass(context.getApplicationContext(), DRingService.class)
.putExtra(DRingService.KEY_TRANSFER_ID, file.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, file.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, file.getFileId()));
}); });
} else { } else {
viewHolder.mAnswerLayout.setVisibility(View.GONE); viewHolder.mAnswerLayout.setVisibility(View.GONE);
......
...@@ -379,7 +379,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres ...@@ -379,7 +379,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
} }
@Override @Override
public void shareFile(File path) { public void shareFile(File path, String displayName) {
Context c = getContext(); Context c = getContext();
if (c == null) if (c == null)
return; return;
...@@ -400,7 +400,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres ...@@ -400,7 +400,7 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
} }
@Override @Override
public void openFile(File path) { public void openFile(File path, String displayName) {
Context c = getContext(); Context c = getContext();
if (c == null) if (c == null)
return; return;
...@@ -807,7 +807,8 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres ...@@ -807,7 +807,8 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT) requireActivity().startService(new Intent(DRingService.ACTION_FILE_ACCEPT)
.setClass(requireContext(), DRingService.class) .setClass(requireContext(), DRingService.class)
.setData(ConversationPath.toUri(accountId, conversationUri)) .setData(ConversationPath.toUri(accountId, conversationUri))
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, transfer.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
} }
@Override @Override
...@@ -815,7 +816,8 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres ...@@ -815,7 +816,8 @@ public class TvConversationFragment extends BaseSupportFragment<ConversationPres
requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL) requireActivity().startService(new Intent(DRingService.ACTION_FILE_CANCEL)
.setClass(requireContext(), DRingService.class) .setClass(requireContext(), DRingService.class)
.setData(ConversationPath.toUri(accountId, conversationUri)) .setData(ConversationPath.toUri(accountId, conversationUri))
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getDaemonId())); .putExtra(DRingService.KEY_MESSAGE_ID, transfer.getMessageId())
.putExtra(DRingService.KEY_TRANSFER_ID, transfer.getFileId()));
} }
} }
...@@ -52,6 +52,7 @@ import java.util.Locale; ...@@ -52,6 +52,7 @@ import java.util.Locale;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.jami.model.Conversation;
import net.jami.utils.FileUtils; import net.jami.utils.FileUtils;
import io.reactivex.Completable; import io.reactivex.Completable;
...@@ -317,6 +318,22 @@ public class AndroidFileUtils { ...@@ -317,6 +318,22 @@ public class AndroidFileUtils {
}).subscribeOn(Schedulers.io()); }).subscribeOn(Schedulers.io());
} }
public static @NonNull Single<File> getFileToSend(@NonNull Context context, @NonNull Conversation conversation, @NonNull Uri uri) {
ContentResolver contentResolver = context.getContentResolver();
File cacheDir = context.getCacheDir();
return Single.fromCallable(() -> {
File file = new File(cacheDir, getFilename(contentResolver, uri));
try (InputStream inputStream = contentResolver.openInputStream(uri);
FileOutputStream output = new FileOutputStream(file)) {
if (inputStream == null)
throw new FileNotFoundException();
net.jami.utils.FileUtils.copyFile(inputStream, output);
output.flush();
}
return file;
}).subscribeOn(Schedulers.io());
}
public static Completable moveToUri(@NonNull ContentResolver cr, @NonNull File input, @NonNull Uri outUri) { public static Completable moveToUri(@NonNull ContentResolver cr, @NonNull File input, @NonNull Uri outUri) {
return Completable.fromAction(() -> { return Completable.fromAction(() -> {
try (InputStream inputStream = new FileInputStream(input); try (InputStream inputStream = new FileInputStream(input);
...@@ -363,7 +380,6 @@ public class AndroidFileUtils { ...@@ -363,7 +380,6 @@ public class AndroidFileUtils {
public static File getConversationDir(Context context, String conversationId) { public static File getConversationDir(Context context, String conversationId) {
File conversationsDir = getFilePath(context, "conversation_data"); File conversationsDir = getFilePath(context, "conversation_data");
if (!conversationsDir.exists()) if (!conversationsDir.exists())
conversationsDir.mkdir(); conversationsDir.mkdir();
...@@ -374,9 +390,28 @@ public class AndroidFileUtils { ...@@ -374,9 +390,28 @@ public class AndroidFileUtils {