mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-21 23:48:18 -05:00
Fix the download progress not updating
Integer roundoff errors...
This commit is contained in:
parent
06ae1c0ed6
commit
90db3e6a1a
20
app-test/src/test/kotlin/DLProgressEventTest.kt
Normal file
20
app-test/src/test/kotlin/DLProgressEventTest.kt
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Created by bspeice on 11/20/14.
|
||||
*/
|
||||
|
||||
import org.junit.Test
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent
|
||||
import org.crosswire.jsword.book.Book
|
||||
import org.mockito.Mockito
|
||||
import org.junit.Assert
|
||||
|
||||
class DLProgressEventTest {
|
||||
|
||||
val b = Mockito.mock(javaClass<Book>())
|
||||
|
||||
Test fun fiftyPercentIsOneEighty() {
|
||||
|
||||
val e = DLProgressEvent(50, b)
|
||||
Assert.assertEquals(180, e.toCircular())
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class BookItemHolder {
|
||||
.subscribe(new Action1<DLProgressEvent>() {
|
||||
@Override
|
||||
public void call(DLProgressEvent event) {
|
||||
BookItemHolder.this.displayProgress((int) event.toCircular());
|
||||
BookItemHolder.this.displayProgress(event.toCircular());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -104,21 +104,15 @@ public class BookItemHolder {
|
||||
|
||||
/**
|
||||
* Display the current progress of this download
|
||||
* TODO: Clean up this logic if at all possible...
|
||||
* @param progress The progress out of 360 (degrees of a circle)
|
||||
*/
|
||||
private void displayProgress(int progress) {
|
||||
|
||||
int downloadView;
|
||||
|
||||
if (progress == DLProgressEvent.PROGRESS_BEGINNING) {
|
||||
// Download starting
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
downloadView = downloadProgress.getId();
|
||||
|
||||
isDownloaded.setVisibility(View.GONE);
|
||||
downloadProgress.setVisibility(View.VISIBLE);
|
||||
@ -126,13 +120,7 @@ public class BookItemHolder {
|
||||
downloadProgress.spin();
|
||||
} else if (progress < 360) {
|
||||
// Download in progress
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, downloadProgress.getId());
|
||||
downloadView = downloadProgress.getId();
|
||||
|
||||
isDownloaded.setVisibility(View.GONE);
|
||||
downloadProgress.setVisibility(View.VISIBLE);
|
||||
@ -142,18 +130,20 @@ public class BookItemHolder {
|
||||
} else {
|
||||
// Download complete
|
||||
subscription.unsubscribe();
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams)acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, isDownloaded.getId());
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams)itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, isDownloaded.getId());
|
||||
downloadView = downloadProgress.getId();
|
||||
|
||||
isDownloaded.setVisibility(View.VISIBLE);
|
||||
downloadProgress.setVisibility(View.GONE);
|
||||
displayInstalled();
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams acronymParams =
|
||||
(RelativeLayout.LayoutParams) acronym.getLayoutParams();
|
||||
acronymParams.addRule(RelativeLayout.LEFT_OF, downloadView);
|
||||
|
||||
RelativeLayout.LayoutParams nameParams =
|
||||
(RelativeLayout.LayoutParams) itemName.getLayoutParams();
|
||||
nameParams.addRule(RelativeLayout.LEFT_OF, downloadView);
|
||||
}
|
||||
|
||||
public void onScrollOffscreen() {
|
||||
|
@ -114,8 +114,10 @@ class BookManager(private val installedBooks: Books, val rM: RefreshManager) :
|
||||
val job = ev.getJob()
|
||||
bookMappings.filter { it.getKey() == job.getJobID() }
|
||||
.map {
|
||||
val event = DLProgressEvent(job.getWorkDone() / job.getTotalWork() * 100,
|
||||
it.getValue())
|
||||
// We multiply by 100 first to avoid integer truncation
|
||||
// Also avoids roundoff error. Neat trick, but I'm spending just as much time
|
||||
// documenting it as implementing the floating point would take
|
||||
val event = DLProgressEvent(job.getWorkDone() * 100 / job.getTotalWork(), it.getValue())
|
||||
downloadEvents onNext event
|
||||
|
||||
if (job.getWorkDone() == job.getTotalWork()) {
|
||||
|
@ -12,5 +12,5 @@ class DLProgressEvent(val progress: Int, val b: Book) {
|
||||
val PROGRESS_BEGINNING = 0
|
||||
}
|
||||
|
||||
fun toCircular() = progress.toFloat() * 360 / 100
|
||||
fun toCircular() = (progress.toFloat() * 360 / 100).toInt()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user