Add scan button to navigation drawer
This commit is contained in:
parent
db42454261
commit
9b3243e3e2
7 changed files with 248 additions and 77 deletions
|
|
@ -14,15 +14,15 @@ import java.lang.ref.WeakReference;
|
|||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class UpdateToastMediaScannerCompletionListener implements MediaScannerConnection.OnScanCompletedListener {
|
||||
int scanned = 0;
|
||||
int failed = 0;
|
||||
private int scanned = 0;
|
||||
private int failed = 0;
|
||||
|
||||
private final String[] toBeScanned;
|
||||
|
||||
private final String scannedFiles;
|
||||
private final String couldNotScanFiles;
|
||||
|
||||
private final WeakReference<Toast> toastWeakReference;
|
||||
private Toast toast;
|
||||
private final WeakReference<Activity> activityWeakReference;
|
||||
|
||||
@SuppressLint("ShowToast")
|
||||
|
|
@ -30,7 +30,7 @@ public class UpdateToastMediaScannerCompletionListener implements MediaScannerCo
|
|||
this.toBeScanned = toBeScanned;
|
||||
scannedFiles = activity.getString(R.string.scanned_files);
|
||||
couldNotScanFiles = activity.getString(R.string.could_not_scan_files);
|
||||
toastWeakReference = new WeakReference<>(Toast.makeText(activity, "", Toast.LENGTH_SHORT));
|
||||
toast = Toast.makeText(activity.getApplicationContext(), "", Toast.LENGTH_SHORT);
|
||||
activityWeakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
|
|
@ -39,17 +39,14 @@ public class UpdateToastMediaScannerCompletionListener implements MediaScannerCo
|
|||
Activity activity = activityWeakReference.get();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(() -> {
|
||||
Toast toast = toastWeakReference.get();
|
||||
if (toast != null) {
|
||||
if (uri == null) {
|
||||
failed++;
|
||||
} else {
|
||||
scanned++;
|
||||
}
|
||||
String text = " " + String.format(scannedFiles, scanned, toBeScanned.length) + (failed > 0 ? " " + String.format(couldNotScanFiles, failed) : "");
|
||||
toast.setText(text);
|
||||
toast.show();
|
||||
if (uri == null) {
|
||||
failed++;
|
||||
} else {
|
||||
scanned++;
|
||||
}
|
||||
String text = " " + String.format(scannedFiles, scanned, toBeScanned.length) + (failed > 0 ? " " + String.format(couldNotScanFiles, failed) : "");
|
||||
toast.setText(text);
|
||||
toast.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue