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 1e59999e..29035aee 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 @@ -10,7 +10,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.media.MediaScannerConnection; import android.net.Uri; import android.os.Build; import android.os.Environment; @@ -88,7 +87,9 @@ protected void onHandleIntent(Intent workIntent) { startForeground(NOTIFICATION_ID, notification); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - manager.notify(NOTIFICATION_ID, notification); + if (manager != null) { + manager.notify(NOTIFICATION_ID, notification); + } ContentObserver.selfChange = true; @@ -133,7 +134,9 @@ private void createNotificationChannel() { getString(R.string.file_op_channel_name), NotificationManager.IMPORTANCE_LOW); mChannel.setDescription(getString(R.string.file_op_channel_description)); - mNotificationManager.createNotificationChannel(mChannel); + if (mNotificationManager != null) { + mNotificationManager.createNotificationChannel(mChannel); + } } private NotificationCompat.Builder getNotificationBuilder() { @@ -206,7 +209,9 @@ public void onProgress(final int progress, final int totalNumber) { notifBuilder.setProgress(0, 0, true); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - manager.notify(NOTIFICATION_ID, notifBuilder.build()); + if (manager != null) { + manager.notify(NOTIFICATION_ID, notifBuilder.build()); + } } public void showToast(final String message) { @@ -421,7 +426,68 @@ private static void scanPaths(final Context context, final String[] paths, final toastWeakReference = null; } - String[] mimeTypes = new String[paths.length]; + + for (int i = 0; i < paths.length; i++) { + String path = paths[i]; + if (MediaType.isMedia(path)) { + Uri contentUri = MediaStore.Files.getContentUri("external"); + ContentResolver resolver = context.getContentResolver(); + if (new File(path).exists()) { + AlbumItem albumItem = AlbumItem.getInstance(path); + ContentValues values = new ContentValues(); + if (albumItem instanceof Video) { + values.put(MediaStore.Video.Media.DATA, path); + values.put(MediaStore.Video.Media.MIME_TYPE, MediaType.getMimeType(path)); + } 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(); + } + } + resolver.insert(contentUri, values); + } else { + resolver.delete(contentUri, + MediaStore.MediaColumns.DATA + "='" + path + "'", + null); + } + } + + if (showToast) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + Toast toast = toastWeakReference.get(); + if (toast != null) { + toastWeakReference.get().show(); + } + } + }); + } + + } + + if (callback != null) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + callback.onAllPathsScanned(); + } + }); + } + + /*String[] mimeTypes = new String[paths.length]; for (int i = 0; i < paths.length; i++) { mimeTypes[i] = MediaType.getMimeType(paths[i]); } @@ -494,7 +560,7 @@ public void run() { }); } } - }); + });*/ } public static String getParentPath(String path) { diff --git a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java index 83469561..b7ed0b6a 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java @@ -1042,7 +1042,9 @@ protected void onDestroy() { @Override public boolean canSwipeBack(int dir) { - return SwipeBackCoordinatorLayout.canSwipeBackForThisView(recyclerView, dir) && !pick_photos; + RecyclerViewAdapter adapter = (RecyclerViewAdapter) recyclerView.getAdapter(); + return !adapter.isSelectorModeActive() && + SwipeBackCoordinatorLayout.canSwipeBackForThisView(recyclerView, dir) && !pick_photos; } @Override diff --git a/build.gradle b/build.gradle index 077585b2..2108872a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta7' + classpath 'com.android.tools.build:gradle:3.0.0' } }