diff --git a/app/build.gradle b/app/build.gradle index 32227260..c28a6f93 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "us.koller.cameraroll" minSdkVersion 19 targetSdkVersion 26 - versionCode 31 - versionName "v1.0.1" + versionCode 32 + versionName "v1.0.2" vectorDrawables.useSupportLibrary = true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 3bdebcc8..ff25c583 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java b/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java index 8a6609b9..1e59999e 100644 --- a/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java +++ b/app/src/main/java/us/koller/cameraroll/data/fileOperations/FileOperation.java @@ -20,6 +20,7 @@ import android.os.Parcelable; import android.provider.MediaStore; import android.support.annotation.RequiresApi; +import android.support.media.ExifInterface; import android.support.v4.app.NotificationCompat; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.provider.DocumentFile; @@ -27,9 +28,15 @@ import android.widget.Toast; import java.io.File; +import java.io.IOException; import java.lang.ref.WeakReference; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.Locale; import us.koller.cameraroll.R; import us.koller.cameraroll.data.ContentObserver; @@ -37,6 +44,7 @@ import us.koller.cameraroll.data.models.File_POJO; import us.koller.cameraroll.data.Settings; import us.koller.cameraroll.data.models.Video; +import us.koller.cameraroll.util.ExifUtil; import us.koller.cameraroll.util.MediaType; import us.koller.cameraroll.util.StorageUtil; @@ -397,6 +405,7 @@ public static void scanPathsWithToast(final Context context, final String[] path @SuppressLint("ShowToast") private static void scanPaths(final Context context, final String[] paths, final MediaScannerCallback callback, final boolean showToast) { + Log.i("FileOperation", "scanPaths(), paths: " + Arrays.toString(paths)); if (paths == null) { if (callback != null) { callback.onAllPathsScanned(); @@ -425,8 +434,11 @@ private static void scanPaths(final Context context, final String[] paths, final @Override public void onScanCompleted(String path, Uri uri) { if (uri == null) { + //Scanning failed --> changing MediaStore manually + Log.i("FileOperation", "MediaScannerConnection.scanFile() !FAILED! path = [" + path + "]"); + Uri contentUri = MediaStore.Files.getContentUri("external"); + ContentResolver resolver = context.getContentResolver(); if (new File(path).exists()) { - Log.i("FileOperation", "MediaScannerConnection.scanFile() !FAILED! path = [" + path + "]"); AlbumItem albumItem = AlbumItem.getInstance(path); ContentValues values = new ContentValues(); if (albumItem instanceof Video) { @@ -435,10 +447,26 @@ public void onScanCompleted(String path, Uri uri) { } else { values.put(MediaStore.Images.Media.DATA, path); values.put(MediaStore.Images.Media.MIME_TYPE, MediaType.getMimeType(path)); + try { + ExifInterface exif = new ExifInterface(path); + Locale locale = us.koller.cameraroll.util.Util.getLocale(context); + String dateString = String.valueOf(ExifUtil.getCastValue(exif, ExifInterface.TAG_DATETIME)); + try { + Date date = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", locale).parse(dateString); + long dateTaken = date.getTime(); + values.put(MediaStore.Images.Media.DATE_TAKEN, dateTaken); + } catch (ParseException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } } - Uri contentUri = MediaStore.Files.getContentUri("external"); - ContentResolver resolver = context.getContentResolver(); resolver.insert(contentUri, values); + } else { + resolver.delete(contentUri, + MediaStore.MediaColumns.DATA + "='" + path + "'", + null); } } else { Log.i("FileOperation", "MediaScannerConnection.scanFile() path = [" + path + "]"); diff --git a/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java b/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java index cbd2773c..33720d37 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/ItemActivity.java @@ -12,7 +12,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.FileUriExposedException; import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -194,7 +193,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) { } final ViewGroup rootView = findViewById(R.id.root_view); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH) @@ -446,18 +445,8 @@ public void setPhotoAs() { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - try { - startActivityForResult(Intent.createChooser(intent, - getString(R.string.set_as)), 13); - } catch (FileUriExposedException fuee) { - Toast.makeText(this, "Error (FileUriExposedException)", Toast.LENGTH_SHORT).show(); - fuee.printStackTrace(); - } - } else { - startActivityForResult(Intent.createChooser(intent, - getString(R.string.set_as)), 13); - } + startActivityForResult(Intent.createChooser(intent, + getString(R.string.set_as)), 13); } catch (SecurityException se) { Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show(); se.printStackTrace(); @@ -475,18 +464,8 @@ public void openWith() { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - try { - startActivityForResult(Intent.createChooser(intent, - getString(R.string.open_with)), 13); - } catch (FileUriExposedException fuee) { - Toast.makeText(this, "Error (FileUriExposedException)", Toast.LENGTH_SHORT).show(); - fuee.printStackTrace(); - } - } else { - startActivityForResult(Intent.createChooser(intent, - getString(R.string.open_with)), 13); - } + startActivityForResult(Intent.createChooser(intent, + getString(R.string.open_with)), 13); } catch (SecurityException se) { Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show(); se.printStackTrace(); diff --git a/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java b/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java index 74b7fe91..ff8b5459 100644 --- a/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java +++ b/app/src/main/java/us/koller/cameraroll/util/ExifUtil.java @@ -488,7 +488,7 @@ public static String[][] getExifValues() { return exifValues; } - static Object getCastValue(ExifInterface exif, String tag) + public static Object getCastValue(ExifInterface exif, String tag) throws NumberFormatException, NullPointerException { String value = exif.getAttribute(tag); return castValue(tag, value); diff --git a/app/src/main/java/us/koller/cameraroll/util/Util.java b/app/src/main/java/us/koller/cameraroll/util/Util.java index 10937571..f77d48dc 100644 --- a/app/src/main/java/us/koller/cameraroll/util/Util.java +++ b/app/src/main/java/us/koller/cameraroll/util/Util.java @@ -232,7 +232,7 @@ public static float getAnimatorSpeed(Context context) { android.provider.Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f); } - static Locale getLocale(Context context) { + public static Locale getLocale(Context context) { Locale locale; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { locale = context.getResources().getConfiguration().getLocales().get(0);