Scan single directory for dir and file properties in background thread. @param baseDir is directory to scan @param readyCallback is called on completion
( final FileInfo baseDir, final Runnable readyCallback, final boolean recursiveScan, final ScanControl scanControl )
| 229 | * @param readyCallback is called on completion |
| 230 | */ |
| 231 | public void scanDirectory( final FileInfo baseDir, final Runnable readyCallback, final boolean recursiveScan, final ScanControl scanControl ) |
| 232 | { |
| 233 | final long startTime = System.currentTimeMillis(); |
| 234 | listDirectory(baseDir); |
| 235 | listSubtree( baseDir, 2, android.os.SystemClock.uptimeMillis() + 700 ); |
| 236 | if ( (!getDirScanEnabled() || baseDir.isScanned) && !recursiveScan ) { |
| 237 | readyCallback.run(); |
| 238 | return; |
| 239 | } |
| 240 | engine.execute(new EngineTask() { |
| 241 | long nextProgressTime = startTime + 2000; |
| 242 | boolean progressShown = false; |
| 243 | final Collection<FileInfo> booksToSave = new ArrayList<FileInfo>(); |
| 244 | void progress( int percent ) |
| 245 | { |
| 246 | if ( recursiveScan ) |
| 247 | return; // no progress dialog for recursive scan |
| 248 | long ts = System.currentTimeMillis(); |
| 249 | if ( ts>=nextProgressTime ) { |
| 250 | engine.showProgress(percent, R.string.progress_scanning); |
| 251 | nextProgressTime = ts + 1500; |
| 252 | progressShown = true; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | public void done() { |
| 257 | baseDir.isScanned = true; |
| 258 | if ( progressShown ) |
| 259 | engine.hideProgress(); |
| 260 | readyCallback.run(); |
| 261 | |
| 262 | } |
| 263 | |
| 264 | public void fail(Exception e) { |
| 265 | L.e("Exception while scanning directory " + baseDir.pathname, e); |
| 266 | baseDir.isScanned = true; |
| 267 | if ( progressShown ) |
| 268 | engine.hideProgress(); |
| 269 | readyCallback.run(); |
| 270 | } |
| 271 | |
| 272 | public void scan( FileInfo baseDir ) { |
| 273 | if ( baseDir.isRecentDir() ) |
| 274 | return; |
| 275 | //listDirectory(baseDir); |
| 276 | progress(1000); |
| 277 | if ( scanControl.isStopped() ) |
| 278 | return; |
| 279 | for ( int i=baseDir.dirCount()-1; i>=0; i-- ) { |
| 280 | if ( scanControl.isStopped() ) |
| 281 | return; |
| 282 | listDirectory(baseDir.getDir(i)); |
| 283 | } |
| 284 | progress(2000); |
| 285 | if ( mHideEmptyDirs ) |
| 286 | baseDir.removeEmptyDirs(); |
| 287 | if ( scanControl.isStopped() ) |
| 288 | return; |
no test coverage detected