From 86adeb49519ed2c97fb45a6093203addfebc65b6 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 11 Nov 2014 21:53:13 -0500 Subject: [PATCH] Refactor the DLProgressEvent to Kotlin --- .../manager/BookDownloadManager.java | 5 ++- .../downloader/manager/DLProgressEvent.java | 40 ------------------- .../downloader/manager/DLProgressEvent.kt | 16 ++++++++ 3 files changed, 19 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.java create mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.kt diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java index fd2cdac..164456f 100644 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java +++ b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/BookDownloadManager.java @@ -110,8 +110,9 @@ public class BookDownloadManager implements WorkListener, BooksListener { downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b)); } else { // Track the ongoing download - DLProgressEvent event = new DLProgressEvent(job.getWorkDone(), - job.getTotalWork(), b); + DLProgressEvent event = new DLProgressEvent( + (job.getWorkDone() / job.getTotalWork()) * 100, + b); inProgressDownloads.put(b, event); downloadEvents.onNext(event); } diff --git a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.java b/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.java deleted file mode 100644 index b664b12..0000000 --- a/app/src/main/java/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.bspeice.minimalbible.activity.downloader.manager; - -import org.crosswire.jsword.book.Book; - -/** - * Used for notifying that a book's download progress is ongoing - */ -public class DLProgressEvent { - private final int progress; - private final Book b; - - public static final int PROGRESS_COMPLETE = 100; - public static final int PROGRESS_BEGINNING = 0; - - public DLProgressEvent(int workDone, int totalWork, Book b) { - if (totalWork == 0) { - this.progress = 0; - } else { - this.progress = (int)((float) workDone / totalWork * 100); - } - this.b = b; - } - - public DLProgressEvent(int workDone, Book b) { - this.progress = workDone; - this.b = b; - } - - public int getProgress() { - return progress; - } - - public float toCircular() { - return ((float)progress) * 360 / 100; - } - - public Book getB() { - return this.b; - } -} diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.kt b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.kt new file mode 100644 index 0000000..7f1ed9e --- /dev/null +++ b/app/src/main/kotlin/org/bspeice/minimalbible/activity/downloader/manager/DLProgressEvent.kt @@ -0,0 +1,16 @@ +package org.bspeice.minimalbible.activity.downloader.manager + +import org.crosswire.jsword.book.Book + +/** + * Created by bspeice on 11/11/14. + */ + +class DLProgressEvent(val progress: Int, val b: Book) { + class object { + val PROGRESS_COMPLETE = 100 + val PROGRESS_BEGINNING = 0 + } + + fun toCircular() = progress.toFloat() * 360 / 100 +}