Skip to content

Commit

Permalink
fix issue with caching data in tracklist
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgroot committed Mar 10, 2017
1 parent 3fbebf7 commit 2c106c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? = null,
selectionPair: Pair <String, List<String>>? = 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 {
Expand Down

0 comments on commit 2c106c5

Please sign in to comment.