@@ -15,12 +15,11 @@ class ActivityDatabaseHelper(context: Context) :
1515
1616 companion object {
1717 private const val DATABASE_NAME = " activity_database.db"
18- private const val DATABASE_VERSION = 4
18+ private const val DATABASE_VERSION = 5
1919
2020 // Activities table
2121 const val TABLE_ACTIVITIES = " activities"
2222 const val COLUMN_ACTIVITY_ID = " id"
23- const val COLUMN_ACTIVITY_TYPE = " type"
2423 const val COLUMN_START_DATETIME = " start_datetime"
2524 const val COLUMN_END_DATETIME = " end_datetime"
2625 const val COLUMN_DISTANCE = " distance"
@@ -30,11 +29,6 @@ class ActivityDatabaseHelper(context: Context) :
3029 const val COLUMN_POWER = " power"
3130 const val COLUMN_ALTITUDE = " altitude"
3231 const val COLUMN_TIME = " time"
33- const val COLUMN_USER_ID = " user_id"
34- const val COLUMN_USER_NAME = " user_name"
35- const val COLUMN_USER_AVATAR = " user_avatar"
36- const val COLUMN_LIKES_COUNT = " likes_count"
37- const val COLUMN_HAS_CURRENT_USER_LIKED = " has_current_user_liked"
3832
3933 // Locations table
4034 const val TABLE_LOCATIONS = " locations"
@@ -54,7 +48,6 @@ class ActivityDatabaseHelper(context: Context) :
5448 val createActivitiesTable = """
5549 CREATE TABLE $TABLE_ACTIVITIES (
5650 $COLUMN_ACTIVITY_ID TEXT PRIMARY KEY,
57- $COLUMN_ACTIVITY_TYPE TEXT NOT NULL,
5851 $COLUMN_START_DATETIME INTEGER NOT NULL,
5952 $COLUMN_END_DATETIME INTEGER NOT NULL,
6053 $COLUMN_DISTANCE REAL NOT NULL,
@@ -63,12 +56,7 @@ class ActivityDatabaseHelper(context: Context) :
6356 $COLUMN_CALORIES REAL NOT NULL,
6457 $COLUMN_POWER REAL NOT NULL,
6558 $COLUMN_ALTITUDE REAL NOT NULL,
66- $COLUMN_TIME REAL NOT NULL,
67- $COLUMN_USER_ID TEXT NOT NULL,
68- $COLUMN_USER_NAME TEXT NOT NULL,
69- $COLUMN_USER_AVATAR TEXT,
70- $COLUMN_LIKES_COUNT REAL NOT NULL,
71- $COLUMN_HAS_CURRENT_USER_LIKED INTEGER NOT NULL
59+ $COLUMN_TIME REAL NOT NULL
7260 )
7361 """ .trimIndent()
7462
@@ -119,7 +107,6 @@ class ActivityDatabaseHelper(context: Context) :
119107
120108 val activity1Values = ContentValues ().apply {
121109 put(COLUMN_ACTIVITY_ID , activity1Id)
122- put(COLUMN_ACTIVITY_TYPE , " cycling" )
123110 put(COLUMN_START_DATETIME , activity1Start)
124111 put(COLUMN_END_DATETIME , activity1End)
125112 put(COLUMN_DISTANCE , 25.5 )
@@ -129,11 +116,6 @@ class ActivityDatabaseHelper(context: Context) :
129116 put(COLUMN_POWER , 180.0 )
130117 put(COLUMN_ALTITUDE , 150.0 )
131118 put(COLUMN_TIME , 5400.0 ) // 90 minutes in seconds
132- put(COLUMN_USER_ID , " user_1" )
133- put(COLUMN_USER_NAME , " João Silva" )
134- put(COLUMN_USER_AVATAR , " https://example.com/avatar1.jpg" )
135- put(COLUMN_LIKES_COUNT , 12.0 )
136- put(COLUMN_HAS_CURRENT_USER_LIKED , 0 )
137119 }
138120 db.insert(TABLE_ACTIVITIES , null , activity1Values)
139121
@@ -367,7 +349,6 @@ class ActivityDatabaseHelper(context: Context) :
367349
368350 val activity2Values = ContentValues ().apply {
369351 put(COLUMN_ACTIVITY_ID , activity2Id)
370- put(COLUMN_ACTIVITY_TYPE , " running" )
371352 put(COLUMN_START_DATETIME , activity2Start)
372353 put(COLUMN_END_DATETIME , activity2End)
373354 put(COLUMN_DISTANCE , 8.2 )
@@ -377,11 +358,6 @@ class ActivityDatabaseHelper(context: Context) :
377358 put(COLUMN_POWER , 220.0 )
378359 put(COLUMN_ALTITUDE , 85.0 )
379360 put(COLUMN_TIME , 4500.0 ) // 75 minutes in seconds
380- put(COLUMN_USER_ID , " user_2" )
381- put(COLUMN_USER_NAME , " Maria Santos" )
382- put(COLUMN_USER_AVATAR , " https://example.com/avatar2.jpg" )
383- put(COLUMN_LIKES_COUNT , 8.0 )
384- put(COLUMN_HAS_CURRENT_USER_LIKED , 0 )
385361 }
386362 db.insert(TABLE_ACTIVITIES , null , activity2Values)
387363
@@ -442,52 +418,40 @@ class ActivityDatabaseHelper(context: Context) :
442418
443419 val activity3Values = ContentValues ().apply {
444420 put(COLUMN_ACTIVITY_ID , activity3Id)
445- put(COLUMN_ACTIVITY_TYPE , " cycling" )
446421 put(COLUMN_START_DATETIME , activity3Start)
447422 put(COLUMN_END_DATETIME , activity3End)
448- put(COLUMN_DISTANCE , 25.5 )
449- put(COLUMN_SPEED , 18.2 )
450- put(COLUMN_CADENCE , 85.0 )
451- put(COLUMN_CALORIES , 600.0 ) // Medium-low calories
452- put(COLUMN_POWER , 220.0 )
453- put(COLUMN_ALTITUDE , 150.0 )
454- put(COLUMN_TIME , 5400.0 ) // 90 minutes in seconds
455- put(COLUMN_USER_ID , " user_3" )
456- put(COLUMN_USER_NAME , " Carlos Silva" )
457- put(COLUMN_USER_AVATAR , " https://example.com/avatar3.jpg" )
458- put(COLUMN_LIKES_COUNT , 12.0 )
459- put(COLUMN_HAS_CURRENT_USER_LIKED , 0 )
423+ put(COLUMN_DISTANCE , 12.5 )
424+ put(COLUMN_SPEED , 12.2 )
425+ put(COLUMN_CADENCE , 175.0 )
426+ put(COLUMN_CALORIES , 2200.0 ) // High calories - long activity
427+ put(COLUMN_POWER , 250.0 )
428+ put(COLUMN_ALTITUDE , 120.0 )
429+ put(COLUMN_TIME , 6000.0 ) // 100 minutes in seconds
460430 }
461431 db.insert(TABLE_ACTIVITIES , null , activity3Values)
462432
463- // Activity 4: Intense walk/run (medium-high calories)
433+ // Activity 4: Intense walk/run (medium-high calories) - January
464434 val activity4Id = " fake_activity_4"
465435 val activity4Start = Calendar .getInstance().apply {
466- set(2024 , Calendar .OCTOBER , 23 , 18 , 0 , 0 )
436+ set(2025 , Calendar .JANUARY , 15 , 18 , 0 , 0 )
467437 set(Calendar .MILLISECOND , 0 )
468438 }.timeInMillis
469439 val activity4End = Calendar .getInstance().apply {
470- set(2024 , Calendar .OCTOBER , 23 , 18 , 45 , 0 )
440+ set(2025 , Calendar .JANUARY , 15 , 18 , 45 , 0 )
471441 set(Calendar .MILLISECOND , 0 )
472442 }.timeInMillis
473443
474444 val activity4Values = ContentValues ().apply {
475445 put(COLUMN_ACTIVITY_ID , activity4Id)
476- put(COLUMN_ACTIVITY_TYPE , " running" )
477446 put(COLUMN_START_DATETIME , activity4Start)
478447 put(COLUMN_END_DATETIME , activity4End)
479- put(COLUMN_DISTANCE , 5.8 )
480- put(COLUMN_SPEED , 7.8 )
481- put(COLUMN_CADENCE , 170.0 )
482- put(COLUMN_CALORIES , 1000.0 ) // Medium-high calories
483- put(COLUMN_POWER , 250.0 )
484- put(COLUMN_ALTITUDE , 45.0 )
485- put(COLUMN_TIME , 2700.0 ) // 45 minutes in seconds
486- put(COLUMN_USER_ID , " user_4" )
487- put(COLUMN_USER_NAME , " Ana Costa" )
488- put(COLUMN_USER_AVATAR , " https://example.com/avatar4.jpg" )
489- put(COLUMN_LIKES_COUNT , 18.0 )
490- put(COLUMN_HAS_CURRENT_USER_LIKED , 1 )
448+ put(COLUMN_DISTANCE , 6.8 )
449+ put(COLUMN_SPEED , 8.5 )
450+ put(COLUMN_CADENCE , 155.0 )
451+ put(COLUMN_CALORIES , 1400.0 ) // Moderate calories
452+ put(COLUMN_POWER , 200.0 )
453+ put(COLUMN_ALTITUDE , 65.0 )
454+ put(COLUMN_TIME , 3600.0 ) // 60 minutes in seconds
491455 }
492456 db.insert(TABLE_ACTIVITIES , null , activity4Values)
493457
@@ -594,6 +558,7 @@ class ActivityDatabaseHelper(context: Context) :
594558
595559 // Method to get activity data for statistics
596560 fun getActivityData (activityId : String ): List <Map <String , Any >> {
561+ Log .d(" ActivityDatabaseHelper" , " getActivityData called with activityId: $activityId " )
597562 val data = mutableListOf<Map <String , Any >>()
598563
599564 val db = readableDatabase
@@ -606,9 +571,11 @@ class ActivityDatabaseHelper(context: Context) :
606571 FROM $TABLE_LOCATIONS l
607572 WHERE l.$COLUMN_LOCATION_ACTIVITY_ID = ?
608573 ORDER BY l.$COLUMN_LOCATION_DATETIME ASC
574+ LIMIT 100
609575 """ .trimIndent()
610576
611577 val cursor = db.rawQuery(query, arrayOf(activityId))
578+ Log .d(" ActivityDatabaseHelper" , " Query executed, cursor count: ${cursor.count} " )
612579
613580 if (cursor.moveToFirst()) {
614581 do {
@@ -619,7 +586,7 @@ class ActivityDatabaseHelper(context: Context) :
619586 val altitude = cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_LOCATION_ALTITUDE ))
620587
621588 data.add(mapOf (
622- " timestamp" to Date ( timestamp) ,
589+ " timestamp" to timestamp,
623590 " speed" to speed,
624591 " cadence" to cadence,
625592 " power" to power,
@@ -629,6 +596,7 @@ class ActivityDatabaseHelper(context: Context) :
629596 }
630597
631598 cursor.close()
599+ Log .d(" ActivityDatabaseHelper" , " getActivityData returning ${data.size} data points" )
632600 return data
633601 }
634602
@@ -648,7 +616,6 @@ class ActivityDatabaseHelper(context: Context) :
648616 do {
649617 val activity = mapOf (
650618 " id" to cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_ACTIVITY_ID )),
651- " type" to cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_ACTIVITY_TYPE )),
652619 " startDatetime" to cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_START_DATETIME )),
653620 " endDatetime" to cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_END_DATETIME )),
654621 " distance" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_DISTANCE )),
@@ -657,12 +624,7 @@ class ActivityDatabaseHelper(context: Context) :
657624 " calories" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_CALORIES )),
658625 " power" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_POWER )),
659626 " altitude" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_ALTITUDE )),
660- " time" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_TIME )),
661- " userId" to cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_USER_ID )),
662- " userName" to cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_USER_NAME )),
663- " userAvatar" to cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_USER_AVATAR )),
664- " likesCount" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_LIKES_COUNT )),
665- " hasCurrentUserLiked" to (cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_HAS_CURRENT_USER_LIKED )) == 1 )
627+ " time" to cursor.getDouble(cursor.getColumnIndexOrThrow(COLUMN_TIME ))
666628 )
667629 activities.add(activity)
668630 } while (cursor.moveToNext())
0 commit comments