From 2c106c526388b15e9a097b56e1e0db542b8b17e0 Mon Sep 17 00:00:00 2001 From: Rene de Groot Date: Fri, 10 Mar 2017 06:39:32 +0100 Subject: [PATCH] fix issue with caching data in tracklist --- .../gpstracker/ng/tracklist/summary/SummaryManager.kt | 10 +++++++--- .../gpstracker/ng/utils/ContentProviderExtensions.kt | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) 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 {