From c1dc0da9e34a2accb4ab75e9ba738181987ec963 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 25 May 2014 01:00:41 -0400 Subject: [PATCH] Some tweaks to progress, add "remove" button Doesn't remove anything yet though... --- .../activities/downloader/BookItemHolder.java | 14 +++++++++++--- .../activities/downloader/BookListAdapter.java | 2 +- .../downloader/manager/BookDownloadManager.java | 1 + .../downloader/manager/BookRefreshTask.java | 9 +++++---- .../downloader/manager/DLProgressEvent.java | 4 ---- .../downloader/manager/DownloadManager.java | 14 +++++++++++++- .../downloader/manager/RefreshManager.java | 2 +- .../main/res/drawable-hdpi/ic_action_cancel.png | Bin 0 -> 438 bytes .../main/res/drawable-mdpi/ic_action_cancel.png | Bin 0 -> 328 bytes .../main/res/drawable-xhdpi/ic_action_cancel.png | Bin 0 -> 513 bytes .../main/res/drawable-xxhdpi/ic_action_cancel.png | Bin 0 -> 567 bytes .../src/main/res/layout/list_download_items.xml | 2 +- 12 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png create mode 100644 MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png create mode 100644 MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png create mode 100644 MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png 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 0000000000000000000000000000000000000000..f889617e4471d6a0c65dd81a060bea482276b322 GIT binary patch literal 438 zcmV;n0ZIOeP)uR$+`ZL}CL9iu4pv&~TPqL?R?{{9XWYPqIRgeD^;8#3vi0QmIrbmFkC- z=lNP%LWrBV*rEMwV3MsoHqsVpnjWjFdZ5h9V<&ATapw~E1PAb=v+=Jp6hzH@=Ksnh z?p@-Z`}Cg%jQ{`u07*qoM6N<$g0AVdX8-^I literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..e84853e4f5e0e0ae1babf6c42ad375483668e3d8 GIT binary patch literal 328 zcmV-O0k{5%P)PbXFRCwBAU>F6XU=$26V8kbBY;0@^ zq{4u>@9f#Lk4Z5Ys8<$96#?-opx)!S)G-k-2V^-H$RMbJq*~4eHG_d%2lN5)H&Psd zX8AX$88`tmKFR0LpMR2)lDYX-@nh*(FEV>wX{AjT2oT23$* zkPyFQSx&M8a5#d2T+4}$0s_&&O0MO^WJ8(*W-3I%Z(_12RUCjL5gsSDoS?`7xUw3l zg%w#2Ae7H3aRf7^mQ(5oW@=bYi6aPQLy}84s2Y@7l#+5_6*+|rnj=YcL aAiw|+C&DJQP0oz~00002M=_pR@i* zPEjZcR^hV+AS76ZFCxHFf_3;}0xTpT!WR`#QUWS`aRDVHAj6vo$dP~!Zzf=k1ds5h z0`8IE6+U}6SYkz=AE7zA$Wy1p8|=~!7V&gK%#^meXz0%8wWZ964n9e$r4n+ z9g84Tf;flor_-F)OM-ZYj|(39WC&HeX8*_&=~AlY z`%pHfoh@Pshs;H>pYOJwV`TZC(D7dGud9|S&<QojJWq{W$G32b z+5V~1gJ(Xw^ejJ`(e%&xUmqVSJPiNw{_E=X^MpPv_%OM-#r}~0Ueza!552v22-k&k zw)=gRdH<(O`$GtK8R!4~v!1Zbc|A!_KQZ;k^r*>K?Gj2817|C@nmr5G57?Vqso%P4 zo96qq30ql}-e*n?kCATY?BH`Ktv3mA2oX5N&U~1)htK72frZO~6$vuuTo18);X9%D zr+{&9QxRvp(}8P^maY2A39BF6IW%49Lrz2A!_%AHd(*V&b)d^ZzkL#%zY!3T1~l9vDm!He@N#Jfu^j zcZ{=T|IvEE2|E;%<@c>-$vgG_=Q5kSK`&;A>NT$GJSg;Hj+UDB-^Sh9Nb<2H?#IoD$9}cKB rE>@6>R4b4>;QSjo7J%#o8+#@m23aH3DE>zRz930YS3j3^P6