Skip to content

Commit e5e5d97

Browse files
committed
made product validity time configurable
1 parent 0ebb846 commit e5e5d97

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424
}
2525

2626
project.ext {
27-
sdkVersion='0.11.0-alpha6'
27+
sdkVersion='0.11.0-alpha7'
2828
versionCode=1
2929

3030
compileSdkVersion=28

core/src/main/java/io/snabble/sdk/ProductDatabase.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ private Cursor rawQuery(String sql, String[] args, CancellationSignal cancellati
492492
* <p>
493493
* While updating, the database can still be queried for data, after the update completes calls to the database
494494
* return the updated data.
495+
*
496+
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
497+
*
498+
* If the database is not present or schematic changes are done that can not be resolved via a delta update
499+
* a full update is needed.
495500
*/
496501
public void update() {
497502
update(null);
@@ -506,6 +511,11 @@ public void update() {
506511
* While updating, the database can still be queried for data, after the update completes calls to the database
507512
* return the updated data.
508513
*
514+
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
515+
*
516+
* If the database is not present or schematic changes are done that can not be resolved via a delta update
517+
* a full update is needed.
518+
*
509519
* @param callback A {@link UpdateCallback} that returns success when the operation is successfully completed.
510520
* Or error() in case a network error occurred.
511521
*/
@@ -522,6 +532,11 @@ public void update(final UpdateCallback callback) {
522532
* While updating, the database can still be queried for data, after the update completes calls to the database
523533
* return the updated data.
524534
*
535+
* Note that database updates are usually very cheap and do not transmit data that is already on your device.
536+
*
537+
* If the database is not present or schematic changes are done that can not be resolved via a delta update
538+
* a full update is needed.
539+
*
525540
* @param callback A {@link UpdateCallback} that returns success when the operation is successfully completed.
526541
* Or error() in case a network error occurred. Can be null.
527542
* @param deltaUpdateOnly set to true if you want to only update when the update would be an delta update
@@ -869,7 +884,7 @@ public boolean isUpToDate() {
869884
if (lastUpdateDate != null) {
870885
long time = lastUpdateDate.getTime();
871886
long currentTime = new Date().getTime();
872-
long t = time + TimeUnit.HOURS.toMillis(1);
887+
long t = time + Snabble.getInstance().getConfig().productDbValidityTimeMs;
873888
return t > currentTime;
874889
}
875890

core/src/main/java/io/snabble/sdk/Snabble.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Locale;
2424
import java.util.concurrent.CopyOnWriteArrayList;
2525
import java.util.concurrent.CountDownLatch;
26+
import java.util.concurrent.TimeUnit;
2627

2728
import javax.net.ssl.SSLSocketFactory;
2829
import javax.net.ssl.X509TrustManager;
@@ -490,6 +491,14 @@ public static class Config {
490491
*/
491492
public boolean generateSearchIndex;
492493

494+
/**
495+
* The time that the database is allowed to be out of date. After the specified time in
496+
* milliseconds the database only uses online requests for asynchronous requests.
497+
*
498+
* Successfully calling {@link ProductDatabase#update()} resets the timer.
499+
*/
500+
public long productDbValidityTimeMs = TimeUnit.HOURS.toMillis(1);
501+
493502
/**
494503
* If set to true, downloads receipts automatically and stores them in the projects
495504
* internal storage folder.

0 commit comments

Comments
 (0)