@@ -438,6 +438,19 @@ synchronized void applyFullUpdate(InputStream inputStream) throws IOException {
438438 Logger .d ("Full update took %d ms" , time2 );
439439 }
440440
441+ /**
442+ * Updates the current database in the background by requesting new data from the backend.
443+ * <p>
444+ * Updates can be either delta updates or full updates depending on how big the difference between
445+ * the last update was.
446+ * <p>
447+ * While updating, the database can still be queried for data, after the update completes calls to the database
448+ * return the updated data.
449+ */
450+ public void update () {
451+ update (null );
452+ }
453+
441454 /**
442455 * Updates the current database in the background by requesting new data from the backend.
443456 * <p>
@@ -451,12 +464,29 @@ synchronized void applyFullUpdate(InputStream inputStream) throws IOException {
451464 * Or error() in case a network error occurred.
452465 */
453466 public void update (final UpdateCallback callback ) {
467+ update (callback , false );
468+ }
469+
470+ /**
471+ * Updates the current database in the background by requesting new data from the backend.
472+ * <p>
473+ * Updates can be either delta updates or full updates depending on how big the difference between
474+ * the last update was.
475+ * <p>
476+ * While updating, the database can still be queried for data, after the update completes calls to the database
477+ * return the updated data.
478+ *
479+ * @param callback A {@link UpdateCallback} that returns success when the operation is successfully completed.
480+ * Or error() in case a network error occurred. Can be null.
481+ * @param deltaUpdateOnly set to true if you want to only update when the update would be an delta update
482+ */
483+ public void update (final UpdateCallback callback , boolean deltaUpdateOnly ) {
454484 if (dbName == null ){
455485 return ;
456486 }
457487
458488 productDatabaseDownloader .invalidate ();
459- productDatabaseDownloader .loadAsync (new Downloader .Callback () {
489+ productDatabaseDownloader .update (new Downloader .Callback () {
460490 @ Override
461491 protected void onDataLoaded (boolean wasStillValid ) {
462492 updateLastUpdateTimestamp (System .currentTimeMillis ());
@@ -482,9 +512,31 @@ protected void onError() {
482512 }
483513 }
484514 }
485- });
515+ }, deltaUpdateOnly );
486516 }
487517
518+ /**
519+ * Cancels a database update, if one is currently running.
520+ */
521+ public void cancelUpdate () {
522+ productDatabaseDownloader .cancel ();
523+ }
524+
525+ /**
526+ * @return true if a database update is currently running, false otherwise.
527+ */
528+ public boolean isUpdating () {
529+ return productDatabaseDownloader .isLoading ();
530+ }
531+
532+ private boolean deleteDatabase (File dbFile ) {
533+ if (dbFile .exists ()) {
534+ return application .deleteDatabase (dbFile .getName ());
535+ }
536+ return true ;
537+ }
538+
539+
488540 /**
489541 * Closes and deletes the locally stored database and falls back to online only mode.
490542 */
@@ -513,40 +565,6 @@ public long size() {
513565 return dbFile .length ();
514566 }
515567
516- /**
517- * Updates the current database in the background by requesting new data from the backend.
518- * <p>
519- * Updates can be either delta updates or full updates depending on how big the difference between
520- * the last update was.
521- * <p>
522- * While updating, the database can still be queried for data, after the update completes calls to the database
523- * return the updated data.
524- */
525- public void update () {
526- update (null );
527- }
528-
529- /**
530- * Cancels a database update, if one is currently running.
531- */
532- public void cancelUpdate () {
533- productDatabaseDownloader .cancel ();
534- }
535-
536- /**
537- * @return true if a database update is currently running, false otherwise.
538- */
539- public boolean isUpdating () {
540- return productDatabaseDownloader .isLoading ();
541- }
542-
543- private boolean deleteDatabase (File dbFile ) {
544- if (dbFile .exists ()) {
545- return application .deleteDatabase (dbFile .getName ());
546- }
547- return true ;
548- }
549-
550568 private void swap (File otherDbFile ) throws IOException {
551569 boolean ok = true ;
552570
0 commit comments