Skip to content

Commit 24473da

Browse files
committed
feat(app): assessment event content provider
#375
1 parent a874abe commit 24473da

10 files changed

+132
-46
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<action android:name="android.intent.action.BOOT_COMPLETED" />
3333
</intent-filter>
3434
</receiver>
35-
3635
<receiver android:name=".receiver.AnalyticsEventReceiver"
3736
android:enabled="true"
3837
android:exported="true">
@@ -59,26 +58,29 @@
5958
android:enabled="true"
6059
android:exported="true" />
6160
<provider
62-
android:name=".provider.WordLearningEventProvider"
63-
android:authorities="${applicationId}.provider.word_learning_event_provider"
61+
android:name=".provider.WordAssessmentEventProvider"
62+
android:authorities="${applicationId}.provider.word_assessment_event_provider"
6463
android:enabled="true"
6564
android:exported="true" />
6665
<provider
67-
android:name=".provider.WordAssessmentEventProvider"
68-
android:authorities="${applicationId}.provider.word_assessment_event_provider"
66+
android:name=".provider.WordLearningEventProvider"
67+
android:authorities="${applicationId}.provider.word_learning_event_provider"
6968
android:enabled="true"
7069
android:exported="true" />
71-
7270
<provider
73-
android:name=".provider.VideoLearningEventProvider"
74-
android:authorities="${applicationId}.provider.video_learning_event_provider"
71+
android:name=".provider.NumberAssessmentEventProvider"
72+
android:authorities="${applicationId}.provider.number_assessment_event_provider"
7573
android:enabled="true"
7674
android:exported="true" />
77-
7875
<provider
7976
android:name=".provider.NumberLearningEventProvider"
8077
android:authorities="${applicationId}.provider.number_learning_event_provider"
8178
android:enabled="true"
8279
android:exported="true" />
80+
<provider
81+
android:name=".provider.VideoLearningEventProvider"
82+
android:authorities="${applicationId}.provider.video_learning_event_provider"
83+
android:enabled="true"
84+
android:exported="true" />
8385
</application>
8486
</manifest>

app/src/main/java/ai/elimu/analytics/dao/NumberAssessmentEventDao.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ai.elimu.analytics.dao
22

33
import ai.elimu.analytics.entity.NumberAssessmentEvent
4+
import android.database.Cursor
45
import androidx.room.Dao
56
import androidx.room.Insert
67
import androidx.room.Query
@@ -16,6 +17,12 @@ interface NumberAssessmentEventDao {
1617
)
1718
fun loadAllOrderedByTimestamp(isAsc: Boolean): List<NumberAssessmentEvent>
1819

20+
@Query("SELECT * FROM NumberAssessmentEvent ORDER BY " +
21+
"CASE WHEN :isDesc = 1 THEN time END DESC," +
22+
"CASE WHEN :isDesc = 0 THEN time END ASC"
23+
)
24+
fun loadAllOrderedByTimestampCursor(isDesc: Boolean): Cursor
25+
1926
@Query("SELECT COUNT(*) FROM NumberAssessmentEvent")
2027
fun getCount(): Int
2128
}

app/src/main/java/ai/elimu/analytics/provider/LetterSoundAssessmentEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.UriMatcher
1010
import android.database.Cursor
1111
import android.net.Uri
1212
import android.os.Bundle
13-
import android.util.Log
1413
import timber.log.Timber
1514
import androidx.core.net.toUri
1615

@@ -48,10 +47,6 @@ class LetterSoundAssessmentEventProvider : ContentProvider() {
4847
Timber.i("query")
4948

5049
Timber.i("uri: ${uri}")
51-
Timber.i("projection: ${projection}")
52-
Timber.i("selection: ${selection}")
53-
Timber.i("selectionArgs: ${selectionArgs}")
54-
Timber.i("sortOrder: ${sortOrder}")
5550

5651
val context = context
5752
Timber.i("context: ${context}")
@@ -99,7 +94,7 @@ class LetterSoundAssessmentEventProvider : ContentProvider() {
9994
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
10095
*/
10196
private fun prepareBundle(): Bundle {
102-
Log.i(this::class.simpleName, "prepareBundle")
97+
Timber.i("prepareBundle")
10398
val bundle = Bundle().apply {
10499
putInt("version_code", BuildConfig.VERSION_CODE)
105100
putString(BundleKeys.KEY_ID, LetterSoundAssessmentEvent::id.name)

app/src/main/java/ai/elimu/analytics/provider/LetterSoundLearningEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import android.content.UriMatcher
1111
import android.database.Cursor
1212
import android.net.Uri
1313
import android.os.Bundle
14-
import android.util.Log
1514
import timber.log.Timber
1615
import androidx.core.net.toUri
1716

@@ -35,10 +34,6 @@ class LetterSoundLearningEventProvider : ContentProvider() {
3534
Timber.i("query")
3635

3736
Timber.i("uri: $uri")
38-
Timber.i("projection: $projection")
39-
Timber.i("selection: $selection")
40-
Timber.i("selectionArgs: $selectionArgs")
41-
Timber.i("sortOrder: $sortOrder")
4237

4338
val context = context
4439
Timber.i("context: $context")
@@ -66,7 +61,7 @@ class LetterSoundLearningEventProvider : ContentProvider() {
6661
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
6762
*/
6863
private fun prepareBundle(): Bundle {
69-
Log.i(this::class.simpleName, "prepareBundle")
64+
Timber.i("prepareBundle")
7065
val bundle = Bundle().apply {
7166
putInt("version_code", BuildConfig.VERSION_CODE)
7267
putString(BundleKeys.KEY_ID, WordLearningEvent::id.name)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package ai.elimu.analytics.provider
2+
3+
import ai.elimu.analytics.BuildConfig
4+
import ai.elimu.analytics.db.RoomDb
5+
import ai.elimu.analytics.entity.NumberAssessmentEvent
6+
import ai.elimu.analytics.utils.BundleKeys
7+
import android.content.ContentProvider
8+
import android.content.ContentValues
9+
import android.content.UriMatcher
10+
import android.database.Cursor
11+
import android.net.Uri
12+
import android.os.Bundle
13+
import timber.log.Timber
14+
import androidx.core.net.toUri
15+
16+
class NumberAssessmentEventProvider : ContentProvider() {
17+
companion object {
18+
private const val AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.number_assessment_event_provider"
19+
private const val TABLE = "events"
20+
private const val CODE_EVENTS = 1
21+
22+
private val MATCHER = UriMatcher(UriMatcher.NO_MATCH)
23+
24+
init {
25+
MATCHER.addURI(AUTHORITY, TABLE, CODE_EVENTS)
26+
}
27+
}
28+
29+
override fun onCreate(): Boolean {
30+
Timber.i("onCreate")
31+
32+
val eventsUri = ("content://$AUTHORITY/$TABLE").toUri()
33+
Timber.i("eventsUri: $eventsUri")
34+
35+
return true
36+
}
37+
38+
override fun query(uri: Uri, projection: Array<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Cursor? {
39+
Timber.i("query")
40+
41+
Timber.i("uri: $uri")
42+
43+
val context = context
44+
Timber.i("context: $context")
45+
if (context == null) {
46+
return null
47+
}
48+
49+
val code = MATCHER.match(uri)
50+
Timber.i("code: $code")
51+
if (code == CODE_EVENTS) {
52+
// Get the Room Cursor
53+
val roomDb = RoomDb.getDatabase(context)
54+
val numberAssessmentEventDao = roomDb.numberAssessmentEventDao()
55+
val cursor = numberAssessmentEventDao.loadAllOrderedByTimestampCursor(isDesc = true)
56+
Timber.i("cursor: $cursor")
57+
cursor.setNotificationUri(context.contentResolver, uri)
58+
cursor.extras = prepareBundle()
59+
return cursor
60+
} else {
61+
throw IllegalArgumentException("Unknown URI: $uri")
62+
}
63+
}
64+
65+
/**
66+
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
67+
*/
68+
private fun prepareBundle(): Bundle {
69+
Timber.i("prepareBundle")
70+
val bundle = Bundle().apply {
71+
putInt("version_code", BuildConfig.VERSION_CODE)
72+
putString(BundleKeys.KEY_ID, NumberAssessmentEvent::id.name)
73+
putString(BundleKeys.KEY_ANDROID_ID, NumberAssessmentEvent::androidId.name)
74+
putString(BundleKeys.KEY_PACKAGE_NAME, NumberAssessmentEvent::packageName.name)
75+
putString(BundleKeys.KEY_TIMESTAMP, NumberAssessmentEvent::time.name)
76+
putString(BundleKeys.KEY_MASTERY_SCORE, NumberAssessmentEvent::masteryScore.name)
77+
putString(BundleKeys.KEY_TIME_SPENT_MS, NumberAssessmentEvent::timeSpentMs.name)
78+
putString(BundleKeys.KEY_ADDITIONAL_DATA, NumberAssessmentEvent::additionalData.name)
79+
putString(BundleKeys.KEY_NUMBER_VALUE, NumberAssessmentEvent::numberValue.name)
80+
putString(BundleKeys.KEY_NUMBER_ID, NumberAssessmentEvent::numberId.name)
81+
}
82+
return bundle
83+
}
84+
85+
override fun getType(uri: Uri): String? {
86+
Timber.i("getType")
87+
88+
throw UnsupportedOperationException("Not yet implemented")
89+
}
90+
91+
override fun insert(uri: Uri, values: ContentValues?): Uri? {
92+
Timber.i("insert")
93+
94+
throw UnsupportedOperationException("Not yet implemented")
95+
}
96+
97+
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
98+
Timber.i("delete")
99+
100+
throw UnsupportedOperationException("Not yet implemented")
101+
}
102+
103+
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?): Int {
104+
Timber.i("update")
105+
106+
throw UnsupportedOperationException("Not yet implemented")
107+
}
108+
}

app/src/main/java/ai/elimu/analytics/provider/NumberLearningEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.UriMatcher
1010
import android.database.Cursor
1111
import android.net.Uri
1212
import android.os.Bundle
13-
import android.util.Log
1413
import timber.log.Timber
1514
import androidx.core.net.toUri
1615

@@ -34,10 +33,6 @@ class NumberLearningEventProvider : ContentProvider() {
3433
Timber.i("query")
3534

3635
Timber.i("uri: $uri")
37-
Timber.i("projection: $projection")
38-
Timber.i("selection: $selection")
39-
Timber.i("selectionArgs: $selectionArgs")
40-
Timber.i("sortOrder: $sortOrder")
4136

4237
val context = context
4338
Timber.i("context: $context")
@@ -65,7 +60,7 @@ class NumberLearningEventProvider : ContentProvider() {
6560
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
6661
*/
6762
private fun prepareBundle(): Bundle {
68-
Log.i(this::class.simpleName, "prepareBundle")
63+
Timber.i("prepareBundle")
6964
val bundle = Bundle().apply {
7065
putInt("version_code", BuildConfig.VERSION_CODE)
7166
putString(BundleKeys.KEY_ID, NumberLearningEvent::id.name)

app/src/main/java/ai/elimu/analytics/provider/VideoLearningEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.UriMatcher
1010
import android.database.Cursor
1111
import android.net.Uri
1212
import android.os.Bundle
13-
import android.util.Log
1413
import timber.log.Timber
1514
import androidx.core.net.toUri
1615

@@ -34,10 +33,6 @@ class VideoLearningEventProvider : ContentProvider() {
3433
Timber.i("query")
3534

3635
Timber.i("uri: $uri")
37-
Timber.i("projection: $projection")
38-
Timber.i("selection: $selection")
39-
Timber.i("selectionArgs: $selectionArgs")
40-
Timber.i("sortOrder: $sortOrder")
4136

4237
val context = context
4338
Timber.i("context: $context")
@@ -65,7 +60,7 @@ class VideoLearningEventProvider : ContentProvider() {
6560
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
6661
*/
6762
private fun prepareBundle(): Bundle {
68-
Log.i(this::class.simpleName, "prepareBundle")
63+
Timber.i("prepareBundle")
6964
val bundle = Bundle().apply {
7065
putInt("version_code", BuildConfig.VERSION_CODE)
7166
putString(BundleKeys.KEY_ID, VideoLearningEvent::id.name)

app/src/main/java/ai/elimu/analytics/provider/WordAssessmentEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.UriMatcher
1010
import android.database.Cursor
1111
import android.net.Uri
1212
import android.os.Bundle
13-
import android.util.Log
1413
import timber.log.Timber
1514
import androidx.core.net.toUri
1615

@@ -34,10 +33,6 @@ class WordAssessmentEventProvider : ContentProvider() {
3433
Timber.i("query")
3534

3635
Timber.i("uri: $uri")
37-
Timber.i("projection: $projection")
38-
Timber.i("selection: $selection")
39-
Timber.i("selectionArgs: $selectionArgs")
40-
Timber.i("sortOrder: $sortOrder")
4136

4237
val context = context
4338
Timber.i("context: $context")
@@ -85,7 +80,7 @@ class WordAssessmentEventProvider : ContentProvider() {
8580
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
8681
*/
8782
private fun prepareBundle(): Bundle {
88-
Log.i(this::class.simpleName, "prepareBundle")
83+
Timber.i("prepareBundle")
8984
val bundle = Bundle().apply {
9085
putInt("version_code", BuildConfig.VERSION_CODE)
9186
putString(BundleKeys.KEY_ID, WordAssessmentEvent::id.name)

app/src/main/java/ai/elimu/analytics/provider/WordLearningEventProvider.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.content.UriMatcher
1010
import android.database.Cursor
1111
import android.net.Uri
1212
import android.os.Bundle
13-
import android.util.Log
1413
import timber.log.Timber
1514
import androidx.core.net.toUri
1615

@@ -34,10 +33,6 @@ class WordLearningEventProvider : ContentProvider() {
3433
Timber.i("query")
3534

3635
Timber.i("uri: $uri")
37-
Timber.i("projection: $projection")
38-
Timber.i("selection: $selection")
39-
Timber.i("selectionArgs: $selectionArgs")
40-
Timber.i("sortOrder: $sortOrder")
4136

4237
val context = context
4338
Timber.i("context: $context")
@@ -65,7 +60,7 @@ class WordLearningEventProvider : ContentProvider() {
6560
* Prepare database column names needed by the Cursor-to-Gson converter in the `:utils` module.
6661
*/
6762
private fun prepareBundle(): Bundle {
68-
Log.i(this::class.simpleName, "prepareBundle")
63+
Timber.i("prepareBundle")
6964
val bundle = Bundle().apply {
7065
putInt("version_code", BuildConfig.VERSION_CODE)
7166
putString(BundleKeys.KEY_ID, WordLearningEvent::id.name)

app/src/main/java/ai/elimu/analytics/task/UploadEventsWorker.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ai.elimu.analytics.enum.toServiceClass
77
import ai.elimu.analytics.rest.NumberAssessmentEventService
88
import ai.elimu.analytics.util.SharedPreferencesHelper
99
import ai.elimu.analytics.util.VersionHelper.extractVersionCode
10-
import ai.elimu.model.v2.enums.Language
1110
import android.content.Context
1211
import androidx.work.Worker
1312
import androidx.work.WorkerParameters

0 commit comments

Comments
 (0)