public DocumentStatus getDocumentStatus(Book document) {
String initials = document.getInitials();
if (downloadQueue.isInQueue(document)) {
return new DocumentStatus(initials, BEING_INSTALLED, documentDownloadProgressCache.getPercentDone(document));
}
if (downloadQueue.isErrorDownloading(document)) {
return new DocumentStatus(initials, ERROR_DOWNLOADING, 0);
}
Book installedBook = swordDocumentFacade.getDocumentByInitials(document.getInitials());
if (installedBook!=null) {
try {
Version newVersionObj = new Version(document.getBookMetaData().getProperty("Version"));
Version installedVersionObj = new Version(installedBook.getBookMetaData().getProperty("Version"));
if (newVersionObj.compareTo(installedVersionObj)>0) {
return new DocumentStatus(initials, UPGRADE_AVAILABLE, 100);
}
} catch (Exception e) {
Log.e(TAG, "Error comparing versions", e);
return new DocumentStatus(initials, UPGRADE_AVAILABLE, 100);
}
return new DocumentStatus(initials, INSTALLED, 100);
} else {
return new DocumentStatus(initials, NOT_INSTALLED, 0);
}
}