Fix issues the OsisParser regenerating VerseContent

BookManager is still currently unable to delete books
This commit is contained in:
Bradlee Speice
2014-11-12 00:34:31 -05:00
parent cce463cde9
commit 8137c4795a
5 changed files with 39 additions and 9 deletions

View File

@ -90,7 +90,7 @@ public class BookItemHolder {
public void onDownloadItem(View v) {
if (bookManager.isInstalled(b)) {
// Remove the book
boolean didRemove = bookManager.removeBook(b);
boolean didRemove = bookManager.removeBook(b, bookManager.getRealDriver(b));
if (didRemove) {
isDownloaded.setImageResource(R.drawable.ic_action_download);
} else {

View File

@ -14,6 +14,7 @@ import rx.Observable;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
import org.crosswire.jsword.book.BookException
import org.crosswire.jsword.book.BookDriver
/**
* Single point of authority for what is being downloaded and its progress
@ -70,19 +71,25 @@ class BookManager(private val installedBooks: Books, val rM: RefreshManager) :
downloadEvents onNext DLProgressEvent(DLProgressEvent.PROGRESS_BEGINNING, b)
}
/**
* For whatever reason, not just any old "book" reference will do. We need to actually
* get a reference corresponding to a physically installed book to get the proper driver.
* Plus, it makes the removeBook method easier to test.
* @param b The book to find the actual driver for
* @return The driver corresponding to the physical book
*/
fun getRealDriver(b: Book): BookDriver = (installedBooks getBook b.getInitials()).getDriver()
/**
* Remove a book from being installed.
* Currently only supports books that have been installed outside the current application run.
* Not quite sure why this is, but And-Bible exhibits the same behavior.
* Also, make sure to manually test if you change this implementation. The `drivers` are
* a bit persnickety.
* @param b The book to remove
* @return Whether the book was removed.
*/
fun removeBook(b: Book): Boolean {
fun removeBook(b: Book, driver: BookDriver): Boolean {
try {
val realBook = installedBooks getBook b.getInitials()
realBook.getDriver().delete(b)
driver delete b
return installedBooksList remove b
} catch (e: BookException) {
Log.e("InstalledManager",

View File

@ -6,6 +6,7 @@ import java.util.ArrayDeque
import org.xml.sax.Attributes
import org.crosswire.jsword.book.OSISUtil
import org.bspeice.minimalbible.SafeValDelegate
import kotlin.properties.Delegates
/**
* Created by bspeice on 9/10/14.
@ -16,8 +17,7 @@ class OsisParser() : DefaultHandler() {
// Don't pass a verse as part of the constructor, but still guarantee
// that it will exist
public var verse: Verse by SafeValDelegate()
val verseContent: VerseContent
get() = VerseContent(verse)
val verseContent: VerseContent by Delegates.lazy { VerseContent(verse) }
// TODO: Implement a stack to keep min API 8
val doWrite = ArrayDeque<Boolean>()