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 68ba86e6..e7acfea0 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 @@ -1,5 +1,6 @@ package us.koller.cameraroll.data.fileOperations; +import android.annotation.SuppressLint; import android.app.IntentService; import android.app.Notification; import android.app.NotificationChannel; @@ -23,6 +24,7 @@ import android.widget.Toast; import java.io.File; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -359,7 +361,7 @@ public static boolean isOnRemovableStorage(String path) { return false; } - static ArrayList getAllChildPaths(ArrayList paths, String path) { + public static ArrayList getAllChildPaths(ArrayList paths, String path) { File file = new File(path); if (file.exists()) { if (file.isDirectory()) { @@ -400,5 +402,34 @@ public void run() { } }); } + + public static void scanPathsWithToast(final Context context, final String[] paths) { + @SuppressLint("ShowToast") final WeakReference toastWeakReference = new WeakReference<>( + Toast.makeText(context, R.string.scanning, Toast.LENGTH_SHORT)); + MediaScannerConnection.scanFile(context.getApplicationContext(), + paths, + null, + new MediaScannerConnection.OnScanCompletedListener() { + int pathsScanned; + + @Override + public void onScanCompleted(String path, Uri uri) { + Log.d("FileOperation", "onScanCompleted() called with: path = [" + path + "]"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + Toast toast = toastWeakReference.get(); + if (toast != null) { + toastWeakReference.get().show(); + } + } + }); + pathsScanned++; + if (pathsScanned == paths.length) { + toastWeakReference.clear(); + } + } + }); + } } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java b/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java index a35b6657..45a469c8 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java @@ -44,6 +44,8 @@ import android.widget.TextView; import android.widget.Toast; +import java.util.ArrayList; + import us.koller.cameraroll.R; import us.koller.cameraroll.themes.Theme; import us.koller.cameraroll.adapter.fileExplorer.RecyclerViewAdapter; @@ -430,27 +432,32 @@ public boolean onCreateOptionsMenu(Menu menu) { public void manageMenuItems() { if (menu != null) { for (int i = 0; i < menu.size(); i++) { - menu.getItem(i).setVisible(false); - - int id = menu.getItem(i).getItemId(); - if (id == R.id.exclude) { - MenuItem item = menu.getItem(i); - if (currentDir != null) { - item.setVisible(!currentDir.getPath().equals(STORAGE_ROOTS)); - if (Provider.isPathPermanentlyExcluded(currentDir.getPath())) { - item.setChecked(true); - item.setEnabled(false); + MenuItem item = menu.getItem(i); + switch (item.getItemId()) { + case R.id.exclude: + if (currentDir != null) { + item.setVisible(!currentDir.getPath().equals(STORAGE_ROOTS)); + if (Provider.isPathPermanentlyExcluded(currentDir.getPath())) { + item.setChecked(true); + item.setEnabled(false); + } else { + item.setChecked(currentDir.excluded); + item.setEnabled(!currentDir.getPath().equals(STORAGE_ROOTS) + && !Provider.isDirExcludedBecauseParentDirIsExcluded( + currentDir.getPath(), Provider.getExcludedPaths())); + } } else { - item.setChecked(currentDir.excluded); - item.setEnabled(!currentDir.getPath().equals(STORAGE_ROOTS) - && !Provider.isDirExcludedBecauseParentDirIsExcluded( - currentDir.getPath(), Provider.getExcludedPaths())); + item.setVisible(true); + item.setChecked(false); + item.setEnabled(false); } - } else { - item.setVisible(true); - item.setChecked(false); - item.setEnabled(false); - } + break; + case R.id.scan: + item.setVisible(!currentDir.getPath().equals(STORAGE_ROOTS)); + break; + default: + item.setVisible(false); + break; } } } @@ -477,6 +484,13 @@ public boolean onOptionsItemSelected(MenuItem item) { FilesProvider.removeExcludedPath(this, currentDir.getPath()); } break; + case R.id.scan: + ArrayList paths = FileOperation.Util + .getAllChildPaths(new ArrayList(), currentDir.getPath()); + String[] pathsArray = new String[paths.size()]; + paths.toArray(pathsArray); + FileOperation.Util.scanPathsWithToast(this, pathsArray); + break; case R.id.paste: if (!currentDir.getPath().equals(STORAGE_ROOTS)) { recyclerViewAdapter.cancelMode(); @@ -487,9 +501,7 @@ public boolean onOptionsItemSelected(MenuItem item) { fileOpIntent = null; } } else { - Toast.makeText(this, "You can't " - + fileOpIntent.getAction() - + " files here!", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.paste_error, Toast.LENGTH_SHORT).show(); } break; case R.id.copy: @@ -713,11 +725,16 @@ public void run() { //make menu items visible for (int i = 0; i < menu.size(); i++) { - int id = menu.getItem(i).getItemId(); - if (id == R.id.paste || id == R.id.exclude) { - menu.getItem(i).setVisible(false); - } else { - menu.getItem(i).setVisible(true); + MenuItem item = menu.getItem(i); + switch (item.getItemId()) { + case R.id.copy: + case R.id.move: + case R.id.delete: + item.setVisible(true); + break; + default: + item.setVisible(false); + break; } } } @@ -822,11 +839,14 @@ public void setTitle(Toolbar toolbar) { public void run() { //hide menu items for (int i = 0; i < menu.size(); i++) { - int id = menu.getItem(i).getItemId(); - if (id == R.id.paste) { - menu.getItem(i).setVisible(true); - } else { - menu.getItem(i).setVisible(false); + MenuItem item = menu.getItem(i); + switch (item.getItemId()) { + case R.id.paste: + item.setVisible(true); + break; + default: + item.setVisible(false); + break; } } } @@ -900,7 +920,7 @@ public void setTitle(Toolbar toolbar) { }); //fade overflow menu icon - ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(), accentTextColor, textColorPrimary); + ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(), accentTextColor, textColorSecondary); Drawable navIcon = toolbar.getNavigationIcon(); if (navIcon instanceof Animatable) { @@ -926,11 +946,15 @@ public void run() { //hide menu items for (int i = 0; i < menu.size(); i++) { - int id = menu.getItem(i).getItemId(); - if (id == R.id.exclude) { - menu.getItem(i).setVisible(true); - } else { - menu.getItem(i).setVisible(false); + MenuItem item = menu.getItem(i); + switch (item.getItemId()) { + case R.id.exclude: + case R.id.scan: + item.setVisible(true); + break; + default: + item.setVisible(false); + break; } } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java b/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java index 2fa93827..43fe26ac 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java @@ -154,7 +154,6 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override public void recreate() { recreated = true; - super.recreate(); } @@ -163,7 +162,6 @@ public void onBackPressed() { if (recreated) { setResult(RESULT_OK); } - super.onBackPressed(); } diff --git a/app/src/main/res/menu/file_explorer.xml b/app/src/main/res/menu/file_explorer.xml index 057e7343..6fb0eb58 100644 --- a/app/src/main/res/menu/file_explorer.xml +++ b/app/src/main/res/menu/file_explorer.xml @@ -9,6 +9,11 @@ android:title="@string/exclude" app:showAsAction="never" /> + + KEINE DATEIEN Speicher + Scannen + Scanning… %1$d Datei kopieren %1$d Dateien kopieren %1$d Datei bewegen %1$d Dateien bewegen %1$d Datei löschen + Hierhin können keine Dateien eingefügt werden! Erscheinungsbild Theme diff --git a/app/src/main/res/values/strings_translatable.xml b/app/src/main/res/values/strings_translatable.xml index 114af5c4..6cb269dc 100644 --- a/app/src/main/res/values/strings_translatable.xml +++ b/app/src/main/res/values/strings_translatable.xml @@ -73,11 +73,14 @@ NO FILES Storage + Scan + Scanning… Copy %1$d file Copy %1$d files Move %1$d file Move %1$d files Delete %1$d file + You can\'t paste files here! Appearance Theme