2525import java .util .List ;
2626import java .util .Scanner ;
2727import java .util .concurrent .CopyOnWriteArrayList ;
28+ import java .util .concurrent .TimeUnit ;
2829
2930import io .snabble .sdk .utils .Downloader ;
3031import io .snabble .sdk .utils .Logger ;
@@ -754,6 +755,17 @@ public boolean isAvailableOffline() {
754755 return db != null ;
755756 }
756757
758+ public boolean isUpToDate () {
759+ if (lastUpdateDate != null ){
760+ long time = lastUpdateDate .getTime ();
761+ long currentTime = new Date ().getTime ();
762+ long t = time + TimeUnit .HOURS .toMillis (1 );
763+ return t > currentTime ;
764+ }
765+
766+ return false ;
767+ }
768+
757769 private Cursor productQuery (String appendSql , String [] args , boolean distinct ) {
758770 return productQuery (appendSql , args , distinct , null );
759771 }
@@ -775,7 +787,7 @@ private Cursor rawQuery(String sql, String[] args, CancellationSignal cancellati
775787 }
776788 }
777789
778- //query executes when we call the first function that needs data, not on db.rawQuery
790+ // query executes when we call the first function that needs data, not on db.rawQuery
779791 int count = cursor .getCount ();
780792
781793 long time2 = SystemClock .elapsedRealtime () - time ;
@@ -897,7 +909,7 @@ public void findBySkuOnline(String sku,
897909 return ;
898910 }
899911
900- if (onlineOnly ) {
912+ if (onlineOnly || ! isUpToDate () ) {
901913 productApi .findBySku (sku , productAvailableListener );
902914 } else {
903915 Product local = findBySku (sku );
@@ -930,7 +942,7 @@ public void findByCodeOnline(String code,
930942 return ;
931943 }
932944
933- if (onlineOnly ) {
945+ if (onlineOnly || ! isUpToDate () ) {
934946 productApi .findByCode (code , productAvailableListener );
935947 } else {
936948 Product local = findByCode (code );
@@ -1024,7 +1036,7 @@ public void findByWeighItemIdOnline(String weighItemId,
10241036 return ;
10251037 }
10261038
1027- if (onlineOnly ) {
1039+ if (onlineOnly || ! isUpToDate () ) {
10281040 productApi .findByWeighItemId (weighItemId , productAvailableListener );
10291041 } else {
10301042 Product local = findByWeighItemId (weighItemId );
0 commit comments