@Override public Object convert(String input) { try { return new Version(input); } catch (IllegalArgumentException e) { return null; } } },
private Book getLatest(Book previous, Book current) { if (previous==null) { return current; } // SBMD defaults t0 1.0.0 if version does not exist Version previousVersion = new Version(previous.getBookMetaData().getProperty("Version")); Version currentVersion = new Version(current.getBookMetaData().getProperty("Version")); if (previousVersion.compareTo(currentVersion)<0) { return current; } else { return previous; } }
public boolean isIndexDownloadAvailable(Book document) throws InstallException, BookException { // not sure how to integrate reuse this in JSword index download String version = document.getBookMetaData().getProperty("Version"); String versionSuffix = version!=null ? "-" + new Version(version).toString() : ""; String url = "http://www.crosswire.org/and-bible/indices/v1/"+document.getInitials()+versionSuffix+".zip"; return CommonUtils.isHttpUrlAvailable(url); }
/** return install status - installed, not inst, or upgrade **/ 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) { // see if the new document is a later version 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); // probably not the same version if an error occurred comparing return new DocumentStatus(initials, UPGRADE_AVAILABLE, 100); } // otherwise same document is already installed return new DocumentStatus(initials, INSTALLED, 100); } else { return new DocumentStatus(initials, NOT_INSTALLED, 0); } }
@Override public boolean isAllowed(String aValue) { try { new Version(aValue); return true; } catch (IllegalArgumentException e) { return false; } }