~singpolyma/cheogram-android

d087f31f14a8d79b628396b24c6ff6d79b7bb63a — Stephen Paul Weber 1 year, 1 month ago 7563964
Send a useful filename more often
1 files changed, 21 insertions(+), 1 deletions(-)

M src/main/java/eu/siacs/conversations/persistance/FileBackend.java
M src/main/java/eu/siacs/conversations/persistance/FileBackend.java => src/main/java/eu/siacs/conversations/persistance/FileBackend.java +21 -1
@@ 761,12 761,32 @@ public class FileBackend {
        try {
            setupRelativeFilePath(message, uri, extension);
            copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
            final String name = getDisplayNameFromUri(uri);
            if (name != null) {
                message.getFileParams().setName(name);
            }
        } catch (final XmppConnectionService.BlockedMediaException e) {
            message.setRelativeFilePath(null);
            message.setDeleted(true);
        }
    }

    private String getDisplayNameFromUri(final Uri uri) {
        final String[] projection = {OpenableColumns.DISPLAY_NAME};
        String filename = null;
        try (final Cursor cursor =
                mXmppConnectionService
                        .getContentResolver()
                        .query(uri, projection, null, null, null)) {
            if (cursor != null && cursor.moveToFirst()) {
                filename = cursor.getString(0);
            }
        } catch (final Exception e) {
            filename = null;
        }
        return filename;
    }

    private String getExtensionFromUri(final Uri uri) {
        final String[] projection = {MediaStore.MediaColumns.DATA};
        String filename = null;


@@ 1762,7 1782,7 @@ public class FileBackend {
        } else {
            fileParams.url = url;
        }
        fileParams.setName(file.getName());
        if (fileParams.getName() == null) fileParams.setName(file.getName());
        fileParams.setMediaType(mime);
        if (encrypted && !file.exists()) {
            Log.d(Config.LOGTAG, "skipping updateFileParams because file is encrypted");