mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-14 12:08:51 -05:00
Some tweaks to progress, add "remove" button
Doesn't remove anything yet though...
This commit is contained in:
parent
7558fc7f20
commit
c1dc0da9e3
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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{
|
||||
|
||||
|
@ -32,10 +32,9 @@ public class BookRefreshTask extends AsyncTask<Installer, Integer, List<Book>> {
|
||||
@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<Installer, Integer, List<Book>> {
|
||||
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();
|
||||
}
|
||||
|
@ -34,10 +34,6 @@ public class DLProgressEvent {
|
||||
return ((float)progress) * 360 / 100;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return progress >= 100;
|
||||
}
|
||||
|
||||
public Book getB() {
|
||||
return this.b;
|
||||
}
|
||||
|
@ -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<Book> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
BIN
MinimalBible/src/main/res/drawable-hdpi/ic_action_cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 438 B |
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
BIN
MinimalBible/src/main/res/drawable-mdpi/ic_action_cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 B |
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
BIN
MinimalBible/src/main/res/drawable-xhdpi/ic_action_cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 513 B |
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png
Normal file
BIN
MinimalBible/src/main/res/drawable-xxhdpi/ic_action_cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 567 B |
@ -28,7 +28,7 @@
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/ic_action_download"
|
||||
android:src="@drawable/ic_action_download"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:id="@+id/download_ibtn_download"
|
||||
style="@style/AppBaseTheme.Borderless" />
|
||||
|
Loading…
Reference in New Issue
Block a user