do not implement OnScanCompleted with activities

This commit is contained in:
tibbi 2016-06-14 09:41:43 +02:00
parent 714b1804da
commit d36b8142f3
3 changed files with 27 additions and 21 deletions

View File

@ -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());

View File

@ -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<Medium> 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) {

View File

@ -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();
}
}