From 7558fc7f201de817fdd70d6c7d9149e1735de47e Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sat, 24 May 2014 22:34:55 -0400 Subject: [PATCH] Progress is working fine for most books Still seeing some strange issues, need to do some investigation... --- .../activities/downloader/BookItemHolder.java | 6 +++++- .../activities/downloader/BookListAdapter.java | 10 +++++++++- .../minimalbible/test/DownloadActivityTest.java | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java index 18225f8..04d8630 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookItemHolder.java @@ -52,12 +52,12 @@ public class BookItemHolder { if (dlProgressEvent != null) { displayProgress((int) dlProgressEvent.toCircular()); } + downloadManager.getDownloadBus().register(this); // TODO: Display a remove icon if the book has been downloaded. } @OnClick(R.id.download_ibtn_download) public void onDownloadItem(View v) { - downloadManager.getDownloadBus().register(this); bookDownloadManager.installBook(this.b); } @@ -117,4 +117,8 @@ public class BookItemHolder { downloadProgress.setVisibility(View.GONE); } } + + public void onScrollOffscreen() { + downloadManager.getDownloadBus().unregister(this); + } } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java index 92d43ab..30cbc8d 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/BookListAdapter.java @@ -3,6 +3,7 @@ package org.bspeice.minimalbible.activities.downloader; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AbsListView; import android.widget.BaseAdapter; import org.bspeice.minimalbible.R; @@ -13,7 +14,7 @@ import java.util.List; /** * Adapter to inflate list_download_items.xml */ -public class BookListAdapter extends BaseAdapter { +public class BookListAdapter extends BaseAdapter implements AbsListView.RecyclerListener { private List bookList; private LayoutInflater inflater; @@ -53,4 +54,11 @@ public class BookListAdapter extends BaseAdapter { viewHolder.bindHolder(); return convertView; } + + @Override + public void onMovedToScrapHeap(View view) { + BookItemHolder holder = (BookItemHolder) view.getTag(); + holder.onScrollOffscreen(); + } + } diff --git a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java index f5d35ed..d0307bd 100644 --- a/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java +++ b/MinimalBible/src/test/java/org/bspeice/minimalbible/test/DownloadActivityTest.java @@ -9,8 +9,8 @@ import org.bspeice.minimalbible.MinimalBible; import org.bspeice.minimalbible.MinimalBibleModules; import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.activities.downloader.BookItemHolder; +import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent; import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager; -import org.bspeice.minimalbible.activities.downloader.manager.DownloadProgressEvent; import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.install.Installer; @@ -54,7 +54,7 @@ public class DownloadActivityTest extends InstrumentationTestCase { BookItemHolder holder = new BookItemHolder(dummyView, testBook); dm.getDownloadBus().register(new Object() { - public void onEvent(DownloadProgressEvent event) { + public void onEvent(DLProgressEvent event) { Log.d("testInitial", Integer.toString(event.getProgress())); if (event.getProgress() == 0) { signal.countDown();