Skip to content

Commit e247c18

Browse files
committed
chore: clean up with spotless
1 parent b271d03 commit e247c18

File tree

12 files changed

+180
-180
lines changed

12 files changed

+180
-180
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/influence/impl/ChannelTracker.kt

Lines changed: 128 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -10,162 +10,162 @@ import org.json.JSONObject
1010

1111
internal abstract class ChannelTracker internal constructor(protected var dataRepository: InfluenceDataRepository, private var timeProvider: ITime) :
1212
IChannelTracker {
13-
override var influenceType: InfluenceType? = null
14-
override var indirectIds: JSONArray? = null
15-
override var directId: String? = null
13+
override var influenceType: InfluenceType? = null
14+
override var indirectIds: JSONArray? = null
15+
override var directId: String? = null
1616

17-
@get:Throws(JSONException::class)
18-
abstract val lastChannelObjects: JSONArray
19-
abstract val channelLimit: Int
20-
abstract val indirectAttributionWindow: Int
17+
@get:Throws(JSONException::class)
18+
abstract val lastChannelObjects: JSONArray
19+
abstract val channelLimit: Int
20+
abstract val indirectAttributionWindow: Int
2121

22-
abstract fun getLastChannelObjectsReceivedByNewId(id: String?): JSONArray
22+
abstract fun getLastChannelObjectsReceivedByNewId(id: String?): JSONArray
2323

24-
abstract fun saveChannelObjects(channelObjects: JSONArray)
24+
abstract fun saveChannelObjects(channelObjects: JSONArray)
2525

26-
abstract fun initInfluencedTypeFromCache()
26+
abstract fun initInfluencedTypeFromCache()
2727

28-
private val isDirectSessionEnabled: Boolean
29-
get() = dataRepository.isDirectInfluenceEnabled
28+
private val isDirectSessionEnabled: Boolean
29+
get() = dataRepository.isDirectInfluenceEnabled
3030

31-
private val isIndirectSessionEnabled: Boolean
32-
get() = dataRepository.isIndirectInfluenceEnabled
31+
private val isIndirectSessionEnabled: Boolean
32+
get() = dataRepository.isIndirectInfluenceEnabled
3333

34-
private val isUnattributedSessionEnabled: Boolean
35-
get() = dataRepository.isUnattributedInfluenceEnabled
34+
private val isUnattributedSessionEnabled: Boolean
35+
get() = dataRepository.isUnattributedInfluenceEnabled
3636

37-
/**
38-
* Get the current session based on state + if outcomes features are enabled.
39-
*/
40-
override val currentSessionInfluence: Influence
41-
get() {
42-
val sessionInfluence = Influence(channelType, InfluenceType.DISABLED, null)
43-
// Channel weren't init yet because application is starting
44-
if (influenceType == null) initInfluencedTypeFromCache()
37+
/**
38+
* Get the current session based on state + if outcomes features are enabled.
39+
*/
40+
override val currentSessionInfluence: Influence
41+
get() {
42+
val sessionInfluence = Influence(channelType, InfluenceType.DISABLED, null)
43+
// Channel weren't init yet because application is starting
44+
if (influenceType == null) initInfluencedTypeFromCache()
4545

46-
val currentInfluenceType = influenceType ?: InfluenceType.DISABLED
46+
val currentInfluenceType = influenceType ?: InfluenceType.DISABLED
4747

48-
if (currentInfluenceType.isDirect()) {
49-
if (isDirectSessionEnabled) {
50-
sessionInfluence.apply {
51-
ids = JSONArray().put(this@ChannelTracker.directId)
52-
influenceType = InfluenceType.DIRECT
53-
}
54-
}
55-
} else if (currentInfluenceType.isIndirect()) {
56-
if (isIndirectSessionEnabled) {
57-
sessionInfluence.apply {
58-
ids = this@ChannelTracker.indirectIds
59-
influenceType = InfluenceType.INDIRECT
60-
}
61-
}
62-
} else if (isUnattributedSessionEnabled) {
48+
if (currentInfluenceType.isDirect()) {
49+
if (isDirectSessionEnabled) {
6350
sessionInfluence.apply {
64-
influenceType = InfluenceType.UNATTRIBUTED
51+
ids = JSONArray().put(this@ChannelTracker.directId)
52+
influenceType = InfluenceType.DIRECT
6553
}
6654
}
67-
68-
return sessionInfluence
69-
}
70-
71-
/**
72-
* Get all received ids that may influence actions
73-
* @return ids that happen between attribution window
74-
*/
75-
override val lastReceivedIds: JSONArray
76-
get() {
77-
val ids = JSONArray()
78-
try {
79-
val lastChannelObjectReceived = lastChannelObjects
80-
Logging.debug("ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: $lastChannelObjectReceived")
81-
val attributionWindow = indirectAttributionWindow * 60 * 1000L
82-
val currentTime = timeProvider.currentTimeMillis
83-
for (i in 0 until lastChannelObjectReceived.length()) {
84-
val jsonObject = lastChannelObjectReceived.getJSONObject(i)
85-
val time = jsonObject.getLong(InfluenceConstants.TIME)
86-
val difference = currentTime - time
87-
if (difference <= attributionWindow) {
88-
val id = jsonObject.getString(idTag)
89-
ids.put(id)
90-
}
55+
} else if (currentInfluenceType.isIndirect()) {
56+
if (isIndirectSessionEnabled) {
57+
sessionInfluence.apply {
58+
ids = this@ChannelTracker.indirectIds
59+
influenceType = InfluenceType.INDIRECT
9160
}
92-
} catch (exception: JSONException) {
93-
Logging.error("ChannelTracker.getLastReceivedIds: Generating tracker getLastReceivedIds JSONObject ", exception)
9461
}
95-
return ids
62+
} else if (isUnattributedSessionEnabled) {
63+
sessionInfluence.apply {
64+
influenceType = InfluenceType.UNATTRIBUTED
65+
}
9666
}
9767

98-
override fun resetAndInitInfluence() {
99-
directId = null
100-
indirectIds = lastReceivedIds
101-
influenceType = if (indirectIds?.length() ?: 0 > 0) InfluenceType.INDIRECT else InfluenceType.UNATTRIBUTED
102-
cacheState()
103-
Logging.debug("ChannelTracker.resetAndInitInfluence: $idTag finish with influenceType: $influenceType")
68+
return sessionInfluence
10469
}
10570

106-
/**
107-
* Save state of last ids received
108-
*/
109-
override fun saveLastId(id: String?) {
110-
Logging.debug("ChannelTracker.saveLastId(id: $id): idTag=$idTag")
111-
if (id == null || id.isEmpty()) return
112-
113-
val lastChannelObjectsReceived = getLastChannelObjectsReceivedByNewId(id)
114-
Logging.debug("ChannelTracker.saveLastId: for $idTag saveLastId with lastChannelObjectsReceived: $lastChannelObjectsReceived")
115-
71+
/**
72+
* Get all received ids that may influence actions
73+
* @return ids that happen between attribution window
74+
*/
75+
override val lastReceivedIds: JSONArray
76+
get() {
77+
val ids = JSONArray()
11678
try {
117-
timeProvider.run {
118-
JSONObject()
119-
.put(idTag, id)
120-
.put(InfluenceConstants.TIME, currentTimeMillis)
121-
}.also { newInfluenceId ->
122-
lastChannelObjectsReceived.put(newInfluenceId)
79+
val lastChannelObjectReceived = lastChannelObjects
80+
Logging.debug("ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: $lastChannelObjectReceived")
81+
val attributionWindow = indirectAttributionWindow * 60 * 1000L
82+
val currentTime = timeProvider.currentTimeMillis
83+
for (i in 0 until lastChannelObjectReceived.length()) {
84+
val jsonObject = lastChannelObjectReceived.getJSONObject(i)
85+
val time = jsonObject.getLong(InfluenceConstants.TIME)
86+
val difference = currentTime - time
87+
if (difference <= attributionWindow) {
88+
val id = jsonObject.getString(idTag)
89+
ids.put(id)
90+
}
12391
}
12492
} catch (exception: JSONException) {
125-
Logging.error("ChannelTracker.saveLastId: Generating tracker newInfluenceId JSONObject ", exception)
126-
// We don't have new data, stop logic
127-
return
93+
Logging.error("ChannelTracker.getLastReceivedIds: Generating tracker getLastReceivedIds JSONObject ", exception)
12894
}
95+
return ids
96+
}
12997

130-
var channelObjectToSave = lastChannelObjectsReceived
131-
// Only save the last ids without surpassing the limit
132-
// Always keep the max quantity of ids possible
133-
// If the attribution window increases, old ids might influence
134-
if (lastChannelObjectsReceived.length() > channelLimit) {
135-
val lengthDifference = lastChannelObjectsReceived.length() - channelLimit
136-
// If min sdk is greater than KITKAT we can refactor this logic to removeObject from JSONArray
137-
channelObjectToSave = JSONArray()
138-
for (i in lengthDifference until lastChannelObjectsReceived.length()) {
139-
try {
140-
channelObjectToSave.put(lastChannelObjectsReceived[i])
141-
} catch (exception: JSONException) {
142-
Logging.error("ChannelTracker.saveLastId: Generating tracker lastChannelObjectsReceived get JSONObject ", exception)
143-
}
144-
}
98+
override fun resetAndInitInfluence() {
99+
directId = null
100+
indirectIds = lastReceivedIds
101+
influenceType = if (indirectIds?.length() ?: 0 > 0) InfluenceType.INDIRECT else InfluenceType.UNATTRIBUTED
102+
cacheState()
103+
Logging.debug("ChannelTracker.resetAndInitInfluence: $idTag finish with influenceType: $influenceType")
104+
}
105+
106+
/**
107+
* Save state of last ids received
108+
*/
109+
override fun saveLastId(id: String?) {
110+
Logging.debug("ChannelTracker.saveLastId(id: $id): idTag=$idTag")
111+
if (id == null || id.isEmpty()) return
112+
113+
val lastChannelObjectsReceived = getLastChannelObjectsReceivedByNewId(id)
114+
Logging.debug("ChannelTracker.saveLastId: for $idTag saveLastId with lastChannelObjectsReceived: $lastChannelObjectsReceived")
115+
116+
try {
117+
timeProvider.run {
118+
JSONObject()
119+
.put(idTag, id)
120+
.put(InfluenceConstants.TIME, currentTimeMillis)
121+
}.also { newInfluenceId ->
122+
lastChannelObjectsReceived.put(newInfluenceId)
145123
}
146-
Logging.debug("ChannelTracker.saveLastId: for $idTag with channelObjectToSave: $channelObjectToSave")
147-
saveChannelObjects(channelObjectToSave)
124+
} catch (exception: JSONException) {
125+
Logging.error("ChannelTracker.saveLastId: Generating tracker newInfluenceId JSONObject ", exception)
126+
// We don't have new data, stop logic
127+
return
148128
}
149129

150-
override fun toString(): String {
151-
return "ChannelTracker{" +
152-
"tag=" + idTag +
153-
", influenceType=" + influenceType +
154-
", indirectIds=" + indirectIds +
155-
", directId=" + directId +
156-
'}'
130+
var channelObjectToSave = lastChannelObjectsReceived
131+
// Only save the last ids without surpassing the limit
132+
// Always keep the max quantity of ids possible
133+
// If the attribution window increases, old ids might influence
134+
if (lastChannelObjectsReceived.length() > channelLimit) {
135+
val lengthDifference = lastChannelObjectsReceived.length() - channelLimit
136+
// If min sdk is greater than KITKAT we can refactor this logic to removeObject from JSONArray
137+
channelObjectToSave = JSONArray()
138+
for (i in lengthDifference until lastChannelObjectsReceived.length()) {
139+
try {
140+
channelObjectToSave.put(lastChannelObjectsReceived[i])
141+
} catch (exception: JSONException) {
142+
Logging.error("ChannelTracker.saveLastId: Generating tracker lastChannelObjectsReceived get JSONObject ", exception)
143+
}
144+
}
157145
}
146+
Logging.debug("ChannelTracker.saveLastId: for $idTag with channelObjectToSave: $channelObjectToSave")
147+
saveChannelObjects(channelObjectToSave)
148+
}
158149

159-
override fun equals(other: Any?): Boolean {
160-
if (this === other) return true
161-
if (other == null || javaClass != other.javaClass) return false
162-
val tracker = other as ChannelTracker
163-
return influenceType === tracker.influenceType && tracker.idTag == idTag
164-
}
150+
override fun toString(): String {
151+
return "ChannelTracker{" +
152+
"tag=" + idTag +
153+
", influenceType=" + influenceType +
154+
", indirectIds=" + indirectIds +
155+
", directId=" + directId +
156+
'}'
157+
}
165158

166-
override fun hashCode(): Int {
167-
var result = influenceType.hashCode()
168-
result = 31 * result + idTag.hashCode()
169-
return result
170-
}
159+
override fun equals(other: Any?): Boolean {
160+
if (this === other) return true
161+
if (other == null || javaClass != other.javaClass) return false
162+
val tracker = other as ChannelTracker
163+
return influenceType === tracker.influenceType && tracker.idTag == idTag
164+
}
165+
166+
override fun hashCode(): Int {
167+
var result = influenceType.hashCode()
168+
result = 31 * result + idTag.hashCode()
169+
return result
171170
}
171+
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/outcomes/impl/OutcomeSourceBody.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import org.json.JSONException
55
import org.json.JSONObject
66

77
internal class OutcomeSourceBody
8-
@JvmOverloads
9-
constructor(var notificationIds: JSONArray? = JSONArray(), var inAppMessagesIds: JSONArray? = JSONArray()) {
10-
@Throws(JSONException::class)
11-
fun toJSONObject(): JSONObject =
12-
JSONObject()
13-
.put(OutcomeConstants.NOTIFICATION_IDS, notificationIds)
14-
.put(OutcomeConstants.IAM_IDS, inAppMessagesIds)
8+
@JvmOverloads
9+
constructor(var notificationIds: JSONArray? = JSONArray(), var inAppMessagesIds: JSONArray? = JSONArray()) {
10+
@Throws(JSONException::class)
11+
fun toJSONObject(): JSONObject =
12+
JSONObject()
13+
.put(OutcomeConstants.NOTIFICATION_IDS, notificationIds)
14+
.put(OutcomeConstants.IAM_IDS, inAppMessagesIds)
1515

16-
override fun toString(): String {
17-
return "OutcomeSourceBody{" +
18-
"notificationIds=" + notificationIds +
19-
", inAppMessagesIds=" + inAppMessagesIds +
20-
'}'
21-
}
16+
override fun toString(): String {
17+
return "OutcomeSourceBody{" +
18+
"notificationIds=" + notificationIds +
19+
", inAppMessagesIds=" + inAppMessagesIds +
20+
'}'
2221
}
22+
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/SubscriptionOperationExecutor.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,17 @@ internal class SubscriptionOperationExecutor(
216216
ExecutionResponse(
217217
ExecutionResult.FAIL_NORETRY,
218218
operations =
219-
listOf(
220-
CreateSubscriptionOperation(
221-
lastOperation.appId,
222-
lastOperation.onesignalId,
223-
lastOperation.subscriptionId,
224-
lastOperation.type,
225-
lastOperation.enabled,
226-
lastOperation.address,
227-
lastOperation.status,
228-
),
219+
listOf(
220+
CreateSubscriptionOperation(
221+
lastOperation.appId,
222+
lastOperation.onesignalId,
223+
lastOperation.subscriptionId,
224+
lastOperation.type,
225+
lastOperation.enabled,
226+
lastOperation.address,
227+
lastOperation.status,
229228
),
229+
),
230230
)
231231
}
232232
else ->

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/backend/UserBackendServiceTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ class UserBackendServiceTests : FunSpec({
334334
PropertiesDeltasObject(
335335
amountSpent = BigDecimal(1111),
336336
purchases =
337-
listOf(
338-
PurchaseObject("sku1", "iso1", BigDecimal(2222)),
339-
PurchaseObject("sku2", "iso2", BigDecimal(4444)),
340-
),
337+
listOf(
338+
PurchaseObject("sku1", "iso1", BigDecimal(2222)),
339+
PurchaseObject("sku2", "iso2", BigDecimal(4444)),
340+
),
341341
)
342342

343343
// When

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/display/impl/InAppMessageView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ internal class InAppMessageView(
579579
messageView,
580580
(
581581
-height - marginPxSizeTop
582-
).toFloat(),
582+
).toFloat(),
583583
0f,
584584
IN_APP_BANNER_ANIMATION_DURATION_MS,
585585
OneSignalBounceInterpolator(0.1, 8.0),
@@ -598,7 +598,7 @@ internal class InAppMessageView(
598598
messageView,
599599
(
600600
height + marginPxSizeBottom
601-
).toFloat(),
601+
).toFloat(),
602602
0f,
603603
IN_APP_BANNER_ANIMATION_DURATION_MS,
604604
OneSignalBounceInterpolator(0.1, 8.0),

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/display/impl/OneSignalBounceInterpolator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class OneSignalBounceInterpolator(amplitude: Double, frequency: Double)
1313
Math.E,
1414
-time / mAmplitude,
1515
) * Math.cos(mFrequency * time) + 1
16-
).toFloat()
16+
).toFloat()
1717
}
1818

1919
init {

0 commit comments

Comments
 (0)