• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snowplow / snowplow-android-tracker / #1055

pending completion
#1055

push

github-actions

mscwilson
Merge branch 'release/5.0.0-beta.1' into next

214 of 214 new or added lines in 18 files covered. (100.0%)

3599 of 4680 relevant lines covered (76.9%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/ScreenStateMachine.kt
1
/*
2
 * Copyright (c) 2015-2023 Snowplow Analytics Ltd. All rights reserved.
3
 *
4
 * This program is licensed to you under the Apache License Version 2.0,
5
 * and you may not use this file except in compliance with the Apache License Version 2.0.
6
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
 *
8
 * Unless required by applicable law or agreed to in writing,
9
 * software distributed under the Apache License Version 2.0 is distributed on an
10
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
 */
13
package com.snowplowanalytics.core.tracker
14

15
import com.snowplowanalytics.core.constants.Parameters
16
import com.snowplowanalytics.core.constants.TrackerConstants
17
import com.snowplowanalytics.core.statemachine.State
18
import com.snowplowanalytics.core.statemachine.StateMachineInterface
19
import com.snowplowanalytics.snowplow.event.Event
20
import com.snowplowanalytics.snowplow.event.ScreenView
21
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson
22
import com.snowplowanalytics.snowplow.tracker.InspectableEvent
23

24
class ScreenStateMachine : StateMachineInterface {
1✔
25
    /*
26
     States: Init, Screen
27
     Events: SV (ScreenView)
28
     Transitions:
29
      - Init (SV) Screen
30
      - Screen (SV) Screen
31
     Entity Generation:
32
      - Screen
33
     */
34

35
    override val identifier: String
36
        get() = ID
1✔
37
    
38
    override val subscribedEventSchemasForTransitions: List<String>
39
        get() = listOf(TrackerConstants.SCHEMA_SCREEN_VIEW)
1✔
40

41
    override val subscribedEventSchemasForEntitiesGeneration: List<String>
42
        get() = listOf("*")
1✔
43

44
    override val subscribedEventSchemasForPayloadUpdating: List<String>
45
        get() = listOf(TrackerConstants.SCHEMA_SCREEN_VIEW)
1✔
46

47
    override val subscribedEventSchemasForAfterTrackCallback: List<String>
48
        get() = emptyList()
1✔
49

50
    override fun transition(event: Event, state: State?): State? {
51
        val screenView = event as? ScreenView
1✔
52
        val screenState: ScreenState? = if (state != null) {
1✔
53
            // - Screen (SV) Screen
54
            state as? ScreenState
1✔
55
        } else {
56
            // - Init (SV) Screen
57
            ScreenState()
1✔
58
        }
59
        screenView?.let {
1✔
60
            screenState?.updateScreenState(
1✔
61
                it.id,
1✔
62
                it.name,
1✔
63
                it.type,
1✔
64
                it.transitionType,
1✔
65
                it.fragmentClassName,
1✔
66
                it.fragmentTag,
1✔
67
                it.activityClassName,
1✔
68
                it.activityTag
1✔
69
            )
70
        }
71
        return screenState
1✔
72
    }
73

74
    override fun entities(event: InspectableEvent, state: State?): List<SelfDescribingJson>? {
75
        if (state == null) return ArrayList()
1✔
76
        val screenState = state as? ScreenState
1✔
77
        val entity = screenState?.getCurrentScreen(true)
1✔
78
        return entity?.let { listOf(it) }
1✔
79
    }
80

81
    override fun payloadValues(event: InspectableEvent, state: State?): Map<String, Any>? {
82
        if (state is ScreenState) {
1✔
83
            val addedValues: MutableMap<String, Any> = HashMap()
1✔
84
            var value = state.previousName
1✔
85
            if (value != null && value.isNotEmpty()) {
1✔
86
                addedValues[Parameters.SV_PREVIOUS_NAME] = value
1✔
87
            }
88
            value = state.previousId
1✔
89
            if (value != null && value.isNotEmpty()) {
1✔
90
                addedValues[Parameters.SV_PREVIOUS_ID] = value
1✔
91
            }
92
            value = state.previousType
1✔
93
            if (value != null && value.isNotEmpty()) {
1✔
94
                addedValues[Parameters.SV_PREVIOUS_TYPE] = value
×
95
            }
96
            return addedValues
1✔
97
        }
98
        return null
×
99
    }
100

101
    override fun afterTrack(event: InspectableEvent) {
102
    }
×
103

104
    companion object {
1✔
105
        val ID: String
106
            get() = "ScreenContext"
1✔
107
    }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc