mirror of
https://github.com/MinimalBible/MinimalBible-Legacy
synced 2024-11-14 20:18:27 -05:00
Add code to remove books
This commit is contained in:
parent
4514c0f33f
commit
1a8b3f2eee
@ -14,6 +14,8 @@ import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent;
|
|||||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
|
||||||
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
import org.bspeice.minimalbible.activities.downloader.manager.InstalledManager;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
import org.crosswire.jsword.book.BookException;
|
||||||
|
import org.crosswire.jsword.book.Books;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -64,7 +66,13 @@ public class BookItemHolder {
|
|||||||
|
|
||||||
@OnClick(R.id.download_ibtn_download)
|
@OnClick(R.id.download_ibtn_download)
|
||||||
public void onDownloadItem(View v) {
|
public void onDownloadItem(View v) {
|
||||||
bookDownloadManager.installBook(this.b);
|
if (installedManager.isInstalled(b)) {
|
||||||
|
// Remove the book
|
||||||
|
installedManager.removeBook(b);
|
||||||
|
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
||||||
|
} else {
|
||||||
|
bookDownloadManager.installBook(this.b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEventMainThread(DLProgressEvent event) {
|
public void onEventMainThread(DLProgressEvent event) {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package org.bspeice.minimalbible.activities.downloader.manager;
|
package org.bspeice.minimalbible.activities.downloader.manager;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
|
import org.crosswire.jsword.book.BookException;
|
||||||
import org.crosswire.jsword.book.Books;
|
import org.crosswire.jsword.book.Books;
|
||||||
import org.crosswire.jsword.book.BooksEvent;
|
import org.crosswire.jsword.book.BooksEvent;
|
||||||
import org.crosswire.jsword.book.BooksListener;
|
import org.crosswire.jsword.book.BooksListener;
|
||||||
@ -18,7 +21,8 @@ public class InstalledManager implements BooksListener {
|
|||||||
|
|
||||||
@Inject DownloadManager downloadManager;
|
@Inject DownloadManager downloadManager;
|
||||||
|
|
||||||
private List<Book> installedBooks;
|
private Books installedBooks;
|
||||||
|
private List<Book> installedBooksList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register our manager to receive events on Book install
|
* Register our manager to receive events on Book install
|
||||||
@ -26,31 +30,39 @@ public class InstalledManager implements BooksListener {
|
|||||||
* so we don't put it in the constructor.
|
* so we don't put it in the constructor.
|
||||||
*/
|
*/
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
Books books = Books.installed();
|
installedBooks = Books.installed();
|
||||||
installedBooks = books.getBooks();
|
installedBooksList = installedBooks.getBooks();
|
||||||
books.addBooksListener(this);
|
installedBooks.addBooksListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInstalled(Book b) {
|
public boolean isInstalled(Book b) {
|
||||||
if (installedBooks == null) {
|
if (installedBooks == null) {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
return installedBooks.contains(b);
|
return installedBooksList.contains(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bookAdded(BooksEvent booksEvent) {
|
public void bookAdded(BooksEvent booksEvent) {
|
||||||
Book b = booksEvent.getBook();
|
Book b = booksEvent.getBook();
|
||||||
if (!installedBooks.contains(b)) {
|
if (!installedBooksList.contains(b)) {
|
||||||
installedBooks.add(b);
|
installedBooksList.add(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bookRemoved(BooksEvent booksEvent) {
|
public void bookRemoved(BooksEvent booksEvent) {
|
||||||
Book b = booksEvent.getBook();
|
Book b = booksEvent.getBook();
|
||||||
if (installedBooks.contains(b)) {
|
if (installedBooksList.contains(b)) {
|
||||||
installedBooks.remove(b);
|
installedBooksList.remove(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeBook(Book b) {
|
||||||
|
try {
|
||||||
|
installedBooks.removeBook(b);
|
||||||
|
} catch (BookException e) {
|
||||||
|
Log.e("InstalledManager", "Unable to remove book (already uninstalled?): " + e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user