From d36b8142f324626842979ca15f1f23480116d6ec Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 14 Jun 2016 09:41:43 +0200 Subject: [PATCH] do not implement OnScanCompleted with activities --- .../gallery/activities/MainActivity.java | 14 +++++++++----- .../gallery/activities/MediaActivity.java | 19 +++++++++---------- .../gallery/activities/ViewPagerActivity.java | 15 +++++++++------ 3 files changed, 27 insertions(+), 21 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 8672a7139..9ea175974 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -43,8 +43,7 @@ import butterknife.BindView; import butterknife.ButterKnife; public class MainActivity extends AppCompatActivity - implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener, - MediaScannerConnection.OnScanCompletedListener { + implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { @BindView(R.id.directories_grid) GridView gridView; private static final int STORAGE_PERMISSION = 1; @@ -305,7 +304,13 @@ public class MainActivity extends AppCompatActivity updatedFiles.add(newDir.getAbsolutePath()); final String[] changedFiles = updatedFiles.toArray(new String[updatedFiles.size()]); - MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, MainActivity.this); + MediaScannerConnection + .scanFile(getApplicationContext(), changedFiles, null, new MediaScannerConnection.OnScanCompletedListener() { + @Override + public void onScanCompleted(String path, Uri uri) { + scanCompleted(path); + } + }); } else { Utils.showToast(getApplicationContext(), R.string.rename_folder_error); } @@ -379,8 +384,7 @@ public class MainActivity extends AppCompatActivity return false; } - @Override - public void onScanCompleted(final String path, final Uri uri) { + private void scanCompleted(final String path) { final File dir = new File(path); if (dir.isDirectory()) { dirs = new ArrayList<>(getDirectories().values()); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index e21177809..0bd81f8c2 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -37,8 +37,7 @@ import butterknife.BindView; import butterknife.ButterKnife; public class MediaActivity extends AppCompatActivity - implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, MediaScannerConnection.OnScanCompletedListener, - GridView.OnTouchListener { + implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { @BindView(R.id.media_grid) GridView gridView; private List media; @@ -204,7 +203,14 @@ public class MediaActivity extends AppCompatActivity } final String[] deletedPaths = toBeDeleted.toArray(new String[toBeDeleted.size()]); - MediaScannerConnection.scanFile(this, deletedPaths, null, this); + MediaScannerConnection.scanFile(this, deletedPaths, null, new MediaScannerConnection.OnScanCompletedListener() { + @Override + public void onScanCompleted(String path, Uri uri) { + if (media != null && media.isEmpty()) { + finish(); + } + } + }); toBeDeleted.clear(); } @@ -276,13 +282,6 @@ public class MediaActivity extends AppCompatActivity selectedItemsCnt = 0; } - @Override - public void onScanCompleted(String path, Uri uri) { - if (media.isEmpty()) { - finish(); - } - } - @Override public boolean onTouch(View v, MotionEvent event) { if (isSnackbarShown) { diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index fe37f80d8..95ee30d7b 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -36,8 +36,7 @@ import butterknife.ButterKnife; import butterknife.OnClick; public class ViewPagerActivity extends AppCompatActivity - implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, MediaScannerConnection.OnScanCompletedListener, - ViewPager.OnTouchListener { + implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener { @BindView(R.id.undo_delete) View undoBtn; @BindView(R.id.view_pager) MyViewPager pager; @@ -167,7 +166,12 @@ public class ViewPagerActivity extends AppCompatActivity if (file.delete()) { beingDeleted = toBeDeleted; final String[] deletedPath = new String[]{toBeDeleted}; - MediaScannerConnection.scanFile(this, deletedPath, null, this); + MediaScannerConnection.scanFile(this, deletedPath, null, new MediaScannerConnection.OnScanCompletedListener() { + @Override + public void onScanCompleted(String path, Uri uri) { + scanCompleted(); + } + }); } toBeDeleted = ""; undoBtn.setVisibility(View.GONE); @@ -385,13 +389,12 @@ public class ViewPagerActivity extends AppCompatActivity adapter.updateUiVisibility(isFullScreen, pos); } - @Override - public void onScanCompleted(String path, Uri uri) { + private void scanCompleted() { beingDeleted = ""; runOnUiThread(new Runnable() { @Override public void run() { - if (media.size() <= 1) { + if (media != null && media.size() <= 1) { reloadViewPager(); } }