~singpolyma/cheogram-android

48f8c1a6a0115bd2fd9782a9a4344e29b159a7bc — Daniel Gultsch 2 years ago 3534c61
use try with resources. remove unused methods
1 files changed, 11 insertions(+), 39 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 +11 -39
@@ 186,11 186,6 @@ public class FileBackend {
        return paint;
    }

    private static String getTakePhotoPath() {
        return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
                + "/Camera/";
    }

    public static Uri getUriForUri(Context context, Uri uri) {
        if ("file".equals(uri.getScheme())) {
            return getUriForFile(context, new File(uri.getPath()));


@@ 474,19 469,6 @@ public class FileBackend {
        return bitmap;
    }

    private void createNoMedia(File diretory) {
        final File noMedia = new File(diretory, ".nomedia");
        if (!noMedia.exists()) {
            try {
                if (!noMedia.createNewFile()) {
                    Log.d(Config.LOGTAG, "created nomedia file " + noMedia.getAbsolutePath());
                }
            } catch (Exception e) {
                Log.d(Config.LOGTAG, "could not create nomedia file");
            }
        }
    }

    public void updateMediaScanner(File file) {
        updateMediaScanner(file, null);
    }


@@ 724,28 706,18 @@ public class FileBackend {
        copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
    }

    private String getExtensionFromUri(Uri uri) {
        String[] projection = {MediaStore.MediaColumns.DATA};
    private String getExtensionFromUri(final Uri uri) {
        final String[] projection = {MediaStore.MediaColumns.DATA};
        String filename = null;
        Cursor cursor;
        try {
            cursor =
                    mXmppConnectionService
                            .getContentResolver()
                            .query(uri, projection, null, null, null);
        } catch (IllegalArgumentException e) {
            cursor = null;
        }
        if (cursor != null) {
            try {
                if (cursor.moveToFirst()) {
                    filename = cursor.getString(0);
                }
            } catch (Exception e) {
                filename = null;
            } finally {
                cursor.close();
        try (final Cursor cursor =
                mXmppConnectionService
                        .getContentResolver()
                        .query(uri, projection, null, null, null)) {
            if (cursor != null && cursor.moveToFirst()) {
                filename = cursor.getString(0);
            }
        } catch (final SecurityException | IllegalArgumentException e) {
            filename = null;
        }
        if (filename == null) {
            final List<String> segments = uri.getPathSegments();


@@ 753,7 725,7 @@ public class FileBackend {
                filename = segments.get(segments.size() - 1);
            }
        }
        int pos = filename == null ? -1 : filename.lastIndexOf('.');
        final int pos = filename == null ? -1 : filename.lastIndexOf('.');
        return pos > 0 ? filename.substring(pos + 1) : null;
    }