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 04d8630..5d4a522 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 @@ -1,6 +1,6 @@ package org.bspeice.minimalbible.activities.downloader; -import android.util.Log; +import android.annotation.SuppressLint; import android.view.View; import android.widget.ImageButton; import android.widget.RelativeLayout; @@ -51,9 +51,15 @@ public class BookItemHolder { DLProgressEvent dlProgressEvent = bookDownloadManager.getInProgressDownloadProgress(b); if (dlProgressEvent != null) { displayProgress((int) dlProgressEvent.toCircular()); + } else if (downloadManager.isInstalled(b)) { + displayInstalled(); } downloadManager.getDownloadBus().register(this); - // TODO: Display a remove icon if the book has been downloaded. + } + + private void displayInstalled() { + isDownloaded.setImageResource(android.R.color.transparent); + isDownloaded.setImageResource(R.drawable.ic_action_cancel); } @OnClick(R.id.download_ibtn_download) @@ -61,8 +67,9 @@ public class BookItemHolder { bookDownloadManager.installBook(this.b); } + @SuppressLint("") public void onEventMainThread(DLProgressEvent event) { - if (event.getB().getName().equals(b.getName())) { + if (event.getB().getOsisID().equals(b.getOsisID())) { displayProgress((int) event.toCircular()); } } @@ -115,6 +122,7 @@ public class BookItemHolder { isDownloaded.setVisibility(View.VISIBLE); downloadProgress.setVisibility(View.GONE); + displayInstalled(); } } 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 30cbc8d..3f0a619 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 @@ -45,7 +45,7 @@ public class BookListAdapter extends BaseAdapter implements AbsListView.Recycler // Nasty Android issue - if you don't check the getTag(), Android will start recycling, // and you'll get some really strange issues if (convertView == null || convertView.getTag() == null) { - convertView = inflater.inflate(R.layout.list_download_items, null); + convertView = inflater.inflate(R.layout.list_download_items, parent, false); viewHolder = new BookItemHolder(convertView, getItem(position)); } else { viewHolder = (BookItemHolder) convertView.getTag(); diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java index cf9610b..1a555d4 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookDownloadManager.java @@ -21,6 +21,7 @@ import de.greenrobot.event.EventBus; /** * Wrapper to convert JSword progress events to MinimalBible EventBus-based */ +//TODO: Listen for installed downloads in case the download took very little time? @Singleton public class BookDownloadManager implements WorkListener{ diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java index 40179e9..a253e35 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/BookRefreshTask.java @@ -32,10 +32,9 @@ public class BookRefreshTask extends AsyncTask> { @Inject DownloadPrefs downloadPrefs; - private EventBus downloadBus; + @Inject DownloadManager downloadManager; - public BookRefreshTask(EventBus downloadBus) { - this.downloadBus = downloadBus; + public BookRefreshTask() { MinimalBible.getApplication().inject(this); } @@ -59,8 +58,10 @@ public class BookRefreshTask extends AsyncTask> { publishProgress(++index, params.length); } + // Pre-cache the DownloadManager with the list of installed books + downloadManager.isInstalled(bookList.values().iterator().next().get(0)); EventBookList event = new EventBookList(bookList); - downloadBus.post(event); + downloadManager.getDownloadBus().post(event); return event.getBookList(); } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DLProgressEvent.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DLProgressEvent.java index 7c3f1f1..ae5f981 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DLProgressEvent.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DLProgressEvent.java @@ -34,10 +34,6 @@ public class DLProgressEvent { return ((float)progress) * 360 / 100; } - public boolean isComplete() { - return progress >= 100; - } - public Book getB() { return this.b; } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DownloadManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DownloadManager.java index 151a6ef..ea8000c 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DownloadManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/DownloadManager.java @@ -3,12 +3,15 @@ package org.bspeice.minimalbible.activities.downloader.manager; import android.util.Log; import org.bspeice.minimalbible.MinimalBible; +import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.BookCategory; +import org.crosswire.jsword.book.Books; import org.crosswire.jsword.book.install.InstallManager; import org.crosswire.jsword.book.install.Installer; import org.crosswire.jsword.book.sword.SwordBookPath; import java.io.File; +import java.util.List; import java.util.Map; import javax.inject.Inject; @@ -16,7 +19,7 @@ import javax.inject.Singleton; import de.greenrobot.event.EventBus; -// TODO: Rename to RefreshManager? Refactor to RefreshManager? +// TODO: Listen to BookInstall events? @Singleton public class DownloadManager { @@ -25,6 +28,8 @@ public class DownloadManager { @Inject protected EventBus downloadBus; + private List installedBooks; + public static final BookCategory[] VALID_CATEGORIES = { BookCategory.BIBLE, BookCategory.COMMENTARY, BookCategory.DICTIONARY, BookCategory.MAPS }; @@ -77,4 +82,11 @@ public class DownloadManager { public EventBus getDownloadBus() { return this.downloadBus; } + + public boolean isInstalled(Book b) { + if (installedBooks == null) { + installedBooks = Books.installed().getBooks(); + } + return installedBooks.contains(b); + } } diff --git a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java index 95897a0..91fde17 100644 --- a/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java +++ b/MinimalBible/src/main/java/org/bspeice/minimalbible/activities/downloader/manager/RefreshManager.java @@ -40,7 +40,7 @@ public class RefreshManager { private void refreshModules() { EventBus refreshBus = downloadManager.getDownloadBus(); refreshBus.register(this); - new BookRefreshTask(refreshBus).execute(downloadManager.getInstallersArray()); + new BookRefreshTask().execute(downloadManager.getInstallersArray()); } /** diff --git a/MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png b/MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png new file mode 100644 index 0000000..f889617 Binary files /dev/null and b/MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png differ diff --git a/MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png b/MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png new file mode 100644 index 0000000..e84853e Binary files /dev/null and b/MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png differ diff --git a/MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png b/MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png new file mode 100644 index 0000000..58e2e3b Binary files /dev/null and b/MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png differ diff --git a/MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png b/MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png new file mode 100644 index 0000000..a9bbcde Binary files /dev/null and b/MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png differ diff --git a/MinimalBible/src/main/res/layout/list_download_items.xml b/MinimalBible/src/main/res/layout/list_download_items.xml index de9cf98..159f480 100644 --- a/MinimalBible/src/main/res/layout/list_download_items.xml +++ b/MinimalBible/src/main/res/layout/list_download_items.xml @@ -28,7 +28,7 @@