diff --git a/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/tracklist/summary/SummaryManager.kt b/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/tracklist/summary/SummaryManager.kt index 6c95072..d98e698 100644 --- a/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/tracklist/summary/SummaryManager.kt +++ b/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/tracklist/summary/SummaryManager.kt @@ -83,9 +83,13 @@ object summaryManager { } executor?.submit({ val cacheHit = summaryCache[trackUri] - val trackWaypointsUri = trackUri.append(WAYPOINTS) - if (cacheHit != null && trackWaypointsUri.count(context) == cacheHit.count) { - callbackSummary(cacheHit) + if (cacheHit != null) { + val trackWaypointsUri = trackUri.append(WAYPOINTS) + val trackCount = trackWaypointsUri.count(context) + val cacheCount = cacheHit.count + if (trackCount == cacheCount) { + callbackSummary(cacheHit) + } } else { executeTrackCalculation(context, trackUri, callbackSummary) } diff --git a/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/utils/ContentProviderExtensions.kt b/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/utils/ContentProviderExtensions.kt index 7617765..9a4b528 100644 --- a/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/utils/ContentProviderExtensions.kt +++ b/studio/app/src/main/java/nl/sogeti/android/gpstracker/ng/utils/ContentProviderExtensions.kt @@ -161,14 +161,14 @@ fun Uri.append(id: Long): Uri { return ContentUris.withAppendedId(this, id) } -fun Uri.count(context: Context, +fun Uri.count(context: Context, projection: List? = null, selectionPair: Pair >? = null) : Int { val selectionArgs = selectionPair?.second?.toTypedArray() val selection = selectionPair?.first var result = 0 var cursor: Cursor? = null try { - cursor = context.contentResolver.query(this, arrayOf(BaseColumns._ID), selection, selectionArgs, null) + cursor = context.contentResolver.query(this, projection?.toTypedArray(), selection, selectionArgs, null) if (cursor != null && cursor.moveToFirst()) { result = cursor.count } else {