@Test public void doNotScheduleAnotherUpdateIfListenerDoNotWantsIt() { Cursor cursor = mock(Cursor.class); when(cursor.getLong(eq(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR.hashCode()))).thenReturn(42L); when(cursor.getLong(eq(DownloadManager.COLUMN_TOTAL_SIZE_BYTES.hashCode()))).thenReturn(4242L); when(mListener.onProgress(anyInt(), anyInt())).thenReturn(false); mReleaseDownloader.onDownloadProgress(cursor); verify(mListener).onProgress(anyInt(), anyInt()); verifyStatic(never()); AsyncTaskUtils.execute(anyString(), isA(DownloadManagerUpdateTask.class), Mockito.<Void>anyVararg()); }
@WorkerThread synchronized void onDownloadProgress(Cursor cursor) { if (isCancelled()) { return; } long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (mListener.onProgress(currentSize, totalSize)) { HandlerUtils.getMainHandler().postAtTime(new Runnable() { @Override public void run() { update(); } }, HANDLER_TOKEN_CHECK_PROGRESS, SystemClock.uptimeMillis() + UPDATE_PROGRESS_TIME_THRESHOLD); } }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadProgress(Cursor cursor) { if (isCancelled()) { return; } long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (mListener.onProgress(currentSize, totalSize)) { HandlerUtils.getMainHandler().postAtTime(new Runnable() { @Override public void run() { update(); } }, HANDLER_TOKEN_CHECK_PROGRESS, SystemClock.uptimeMillis() + UPDATE_PROGRESS_TIME_THRESHOLD); } } }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadProgress(Cursor cursor) { if (isCancelled()) { return; } long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (mListener.onProgress(currentSize, totalSize)) { HandlerUtils.getMainHandler().postAtTime(new Runnable() { @Override public void run() { update(); } }, HANDLER_TOKEN_CHECK_PROGRESS, SystemClock.uptimeMillis() + UPDATE_PROGRESS_TIME_THRESHOLD); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadProgress(Cursor cursor) { if (isCancelled()) { return; } long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (mListener.onProgress(currentSize, totalSize)) { HandlerUtils.getMainHandler().postAtTime(new Runnable() { @Override public void run() { update(); } }, HANDLER_TOKEN_CHECK_PROGRESS, SystemClock.uptimeMillis() + UPDATE_PROGRESS_TIME_THRESHOLD); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); @Override synchronized boolean isDownloading(); @AnyThread @Override synchronized void resume(); @Override synchronized void cancel(); }
DownloadManagerReleaseDownloader extends AbstractReleaseDownloader { @WorkerThread synchronized void onDownloadProgress(Cursor cursor) { if (isCancelled()) { return; } long totalSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)); long currentSize = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)); if (mListener.onProgress(currentSize, totalSize)) { HandlerUtils.getMainHandler().postAtTime(new Runnable() { @Override public void run() { update(); } }, HANDLER_TOKEN_CHECK_PROGRESS, SystemClock.uptimeMillis() + UPDATE_PROGRESS_TIME_THRESHOLD); } } DownloadManagerReleaseDownloader(@NonNull Context context, @NonNull ReleaseDetails releaseDetails, @NonNull Listener listener); @Override synchronized boolean isDownloading(); @AnyThread @Override synchronized void resume(); @Override synchronized void cancel();  }