-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Change unique request code generator
- Loading branch information
1 parent
72b769f
commit 3b01b21
Showing
2 changed files
with
10 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
personalizatio-sdk/src/main/kotlin/com/personalizatio/notification/RequestCodeGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package com.personalizatio.notification | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
import kotlin.math.abs | ||
|
||
object RequestCodeGenerator { | ||
private val counter = AtomicInteger(0) | ||
|
||
fun getNextRequestCode(): Int { | ||
return counter.getAndIncrement() | ||
/** | ||
* Create a unique requestCode based on the hashcode of the combination of action and currentIndex | ||
* */ | ||
fun generateRequestCode(action: String, currentIndex: Int): Int { | ||
val uniqueKey = "${action}_${currentIndex}".hashCode() | ||
return if (uniqueKey != Int.MIN_VALUE) abs(uniqueKey) else 0 | ||
} | ||
} | ||
} |