11package ai.elimu.kukariri.receiver
22
3- import ai.elimu.analytics.utils.EventProviderUtil
4- import ai.elimu.content_provider.utils.ContentProviderUtil.getAllWordGsons
5- import ai.elimu.kukariri.BuildConfig
63import ai.elimu.kukariri.MainActivity
7- import ai.elimu.kukariri.logic.ReviewHelper
8- import ai.elimu.model.v2.enums.content.WordType
9- import ai.elimu.model.v2.gson.content.WordGson
104import android.content.BroadcastReceiver
115import android.content.Context
126import android.content.Intent
@@ -16,77 +10,24 @@ import android.view.Display
1610
1711class ScreenOnReceiver : BroadcastReceiver () {
1812
19- companion object {
20- private const val TAG = " ScreenOnReceiver"
21- }
22-
2313 override fun onReceive (context : Context , intent : Intent ) {
24- Log .i(TAG , " onReceive" )
14+ Log .i(this :: class .simpleName , " onReceive" )
2515
26- Log .i(TAG , " intent: $intent " )
27- Log .i(TAG , " intent.getAction(): " + intent.action)
16+ Log .i(this :: class .simpleName , " intent: $intent " )
17+ Log .i(this :: class .simpleName , " intent.action: ${ intent.action} " )
2818
2919 // Do not proceed if the screen is not active
3020 val displayManager = context.getSystemService(Context .DISPLAY_SERVICE ) as DisplayManager
3121 for (display in displayManager.displays) {
32- Log .i(TAG , " display: $display " )
22+ Log .i(this :: class .simpleName , " display: $display " )
3323 if (display.state != Display .STATE_ON ) {
3424 return
3525 }
3626 }
3727
38- // Get a list of the Words that have been previously learned
39- val wordLearningEventGsons = EventProviderUtil .getWordLearningEventGsons(
40- context = context,
41- analyticsApplicationId = BuildConfig .ANALYTICS_APPLICATION_ID
42- )
43-
44- // Get a set of the Words that have been previously learned
45- val idsOfWordsInWordLearningEvents = EventProviderUtil .getIdsOfWordsInWordLearningEvents(
46- context = context,
47- analyticsApplicationId = BuildConfig .ANALYTICS_APPLICATION_ID
48- )
49-
50- // Get a list of assessment events for the words that have been previously learned
51- val wordAssessmentEventGsons = EventProviderUtil .getWordAssessmentEventGsons(
52- context = context,
53- analyticsApplicationId = BuildConfig .ANALYTICS_APPLICATION_ID
54- )
55-
56- // Determine which of the previously learned Words are pending a review (based on WordAssessmentEvents)
57- val idsOfWordsPendingReview = ReviewHelper .getIdsOfWordsPendingReview(
58- idsOfWordsInWordLearningEvents,
59- wordLearningEventGsons,
60- wordAssessmentEventGsons
61- )
62- Log .i(
63- TAG ,
64- " idsOfWordsPendingReview.size(): " + idsOfWordsPendingReview.size
65- )
66-
67- // Get list of adjectives/nouns/verbs pending review
68- val wordGsonsPendingReview: MutableList <WordGson ?> = ArrayList ()
69- val allWordGsons: List <WordGson > = getAllWordGsons(
70- context = context,
71- contentProviderApplicationId = BuildConfig .CONTENT_PROVIDER_APPLICATION_ID
72- )
73- for (wordGson in allWordGsons) {
74- if (idsOfWordsPendingReview.contains(wordGson.id)) {
75- // Only include adjectives/nouns/verbs
76- if ((wordGson.wordType == WordType .ADJECTIVE )
77- || (wordGson.wordType == WordType .NOUN )
78- || (wordGson.wordType == WordType .VERB )
79- ) {
80- wordGsonsPendingReview.add(wordGson)
81- }
82- }
83- }
84- Log .i(TAG , " wordGsonsPendingReview.size(): " + wordGsonsPendingReview.size)
85- if (wordGsonsPendingReview.isNotEmpty()) {
86- // Launch the application
87- val launchIntent = Intent (context, MainActivity ::class .java)
88- launchIntent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
89- context.startActivity(launchIntent)
90- }
28+ // Launch the application
29+ val launchIntent = Intent (context, MainActivity ::class .java)
30+ launchIntent.addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
31+ context.startActivity(launchIntent)
9132 }
9233}
0 commit comments