Refactor the DLProgressEvent to Kotlin

This commit is contained in:
Bradlee Speice 2014-11-11 21:53:13 -05:00
parent b778748ee0
commit 86adeb4951
3 changed files with 19 additions and 42 deletions

View File

@ -110,8 +110,9 @@ public class BookDownloadManager implements WorkListener, BooksListener {
downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b)); downloadEvents.onNext(new DLProgressEvent(DLProgressEvent.PROGRESS_COMPLETE, b));
} else { } else {
// Track the ongoing download // Track the ongoing download
DLProgressEvent event = new DLProgressEvent(job.getWorkDone(), DLProgressEvent event = new DLProgressEvent(
job.getTotalWork(), b); (job.getWorkDone() / job.getTotalWork()) * 100,
b);
inProgressDownloads.put(b, event); inProgressDownloads.put(b, event);
downloadEvents.onNext(event); downloadEvents.onNext(event);
} }

View File

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

View File

@ -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
}