From 55dde5e80a3a938d5d6f5ff67b18587eb728abdc Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 1 Apr 2016 23:22:06 +0200 Subject: [PATCH] switch to the main thread only when doing UI things --- .../gallery/activities/MainActivity.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index abe67f174..5963cc587 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -334,27 +334,28 @@ public class MainActivity extends AppCompatActivity @Override public void onScanCompleted(final String path, final Uri uri) { - runOnUiThread(new Runnable() { - @Override - public void run() { - final File dir = new File(path); - if (dir.isDirectory()) { - final List updatedFiles = new ArrayList<>(); + final File dir = new File(path); + if (dir.isDirectory()) { + final List updatedFiles = new ArrayList<>(); - final File[] files = dir.listFiles(); - for (File f : files) { - updatedFiles.add(f.getAbsolutePath()); - } + final File[] files = dir.listFiles(); + for (File f : files) { + updatedFiles.add(f.getAbsolutePath()); + } - final String[] changedFiles = updatedFiles.toArray(new String[updatedFiles.size()]); - MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); + final String[] changedFiles = updatedFiles.toArray(new String[updatedFiles.size()]); + MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); - Utils.showToast(getApplicationContext(), R.string.rename_folder_ok); - dirs = new ArrayList<>(getDirectories().values()); + dirs = new ArrayList<>(getDirectories().values()); + + runOnUiThread(new Runnable() { + @Override + public void run() { updateGridView(); gridView.requestLayout(); + Utils.showToast(getApplicationContext(), R.string.rename_folder_ok); } - } - }); + }); + } } }