mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -05:00
Fix issues the OsisParser regenerating VerseContent
BookManager is still currently unable to delete books
This commit is contained in:
parent
cce463cde9
commit
8137c4795a
@ -142,7 +142,7 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
|||||||
|
|
||||||
bookManager.getInstalledBooksList().add(mockBook);
|
bookManager.getInstalledBooksList().add(mockBook);
|
||||||
assertTrue(bookManager.getInstalledBooksList().contains(mockBook));
|
assertTrue(bookManager.getInstalledBooksList().contains(mockBook));
|
||||||
bookManager.removeBook(mockBook);
|
bookManager.removeBook(mockBook, driver);
|
||||||
assertFalse(bookManager.getInstalledBooksList().contains(mockBook));
|
assertFalse(bookManager.getInstalledBooksList().contains(mockBook));
|
||||||
verify(driver, times(1)).delete(mockBook);
|
verify(driver, times(1)).delete(mockBook);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.annotation.SuppressLint;
|
|||||||
import org.bspeice.minimalbible.MBTestCase;
|
import org.bspeice.minimalbible.MBTestCase;
|
||||||
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
|
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
|
||||||
import org.crosswire.jsword.book.OSISUtil;
|
import org.crosswire.jsword.book.OSISUtil;
|
||||||
|
import org.crosswire.jsword.passage.Verse;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@ -48,4 +49,26 @@ public class OsisParserTest extends MBTestCase {
|
|||||||
parser.endElement("", "", "");
|
parser.endElement("", "", "");
|
||||||
assertTrue(parser.getDoWrite().isEmpty());
|
assertTrue(parser.getDoWrite().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// During initial development, I accidentally set up the verseContent
|
||||||
|
// as a value computed every time - so you'd get a new "content" every time
|
||||||
|
// you tried to update it. Thus, if you updated the content only once, you're fine.
|
||||||
|
// Try and update multiple times, and things would start going crazy.
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public void ignoreTestVerseContentConsistent() {
|
||||||
|
String string1 = "1";
|
||||||
|
String string2 = "2";
|
||||||
|
|
||||||
|
// Yes, I need intimate knowledge of the state machine to run this test
|
||||||
|
// Also, Verse is final, so I can't mock that, which is why this test is ignored.
|
||||||
|
Verse mockVerse = mock(Verse.class);
|
||||||
|
parser.setVerse(mockVerse);
|
||||||
|
parser.getDoWrite().push(true);
|
||||||
|
parser.characters(string1.toCharArray(), 0, string1.length());
|
||||||
|
assertEquals(parser.getVerseContent().getContent(), string1);
|
||||||
|
|
||||||
|
parser.characters(string2.toCharArray(), 0, string2.length());
|
||||||
|
assertEquals(parser.getVerseContent().getContent(), string1 + string2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class BookItemHolder {
|
|||||||
public void onDownloadItem(View v) {
|
public void onDownloadItem(View v) {
|
||||||
if (bookManager.isInstalled(b)) {
|
if (bookManager.isInstalled(b)) {
|
||||||
// Remove the book
|
// Remove the book
|
||||||
boolean didRemove = bookManager.removeBook(b);
|
boolean didRemove = bookManager.removeBook(b, bookManager.getRealDriver(b));
|
||||||
if (didRemove) {
|
if (didRemove) {
|
||||||
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
isDownloaded.setImageResource(R.drawable.ic_action_download);
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,6 +14,7 @@ import rx.Observable;
|
|||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
import rx.subjects.PublishSubject;
|
import rx.subjects.PublishSubject;
|
||||||
import org.crosswire.jsword.book.BookException
|
import org.crosswire.jsword.book.BookException
|
||||||
|
import org.crosswire.jsword.book.BookDriver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single point of authority for what is being downloaded and its progress
|
* 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)
|
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.
|
* Remove a book from being installed.
|
||||||
* Currently only supports books that have been installed outside the current application run.
|
* 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.
|
* 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
|
* @param b The book to remove
|
||||||
* @return Whether the book was removed.
|
* @return Whether the book was removed.
|
||||||
*/
|
*/
|
||||||
fun removeBook(b: Book): Boolean {
|
fun removeBook(b: Book, driver: BookDriver): Boolean {
|
||||||
try {
|
try {
|
||||||
val realBook = installedBooks getBook b.getInitials()
|
driver delete b
|
||||||
realBook.getDriver().delete(b)
|
|
||||||
return installedBooksList remove b
|
return installedBooksList remove b
|
||||||
} catch (e: BookException) {
|
} catch (e: BookException) {
|
||||||
Log.e("InstalledManager",
|
Log.e("InstalledManager",
|
||||||
|
@ -6,6 +6,7 @@ import java.util.ArrayDeque
|
|||||||
import org.xml.sax.Attributes
|
import org.xml.sax.Attributes
|
||||||
import org.crosswire.jsword.book.OSISUtil
|
import org.crosswire.jsword.book.OSISUtil
|
||||||
import org.bspeice.minimalbible.SafeValDelegate
|
import org.bspeice.minimalbible.SafeValDelegate
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by bspeice on 9/10/14.
|
* 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
|
// Don't pass a verse as part of the constructor, but still guarantee
|
||||||
// that it will exist
|
// that it will exist
|
||||||
public var verse: Verse by SafeValDelegate()
|
public var verse: Verse by SafeValDelegate()
|
||||||
val verseContent: VerseContent
|
val verseContent: VerseContent by Delegates.lazy { VerseContent(verse) }
|
||||||
get() = VerseContent(verse)
|
|
||||||
|
|
||||||
// TODO: Implement a stack to keep min API 8
|
// TODO: Implement a stack to keep min API 8
|
||||||
val doWrite = ArrayDeque<Boolean>()
|
val doWrite = ArrayDeque<Boolean>()
|
||||||
|
Loading…
Reference in New Issue
Block a user