-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hyejin12-ju
committed
Sep 24, 2024
1 parent
b574697
commit 569c214
Showing
3 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
core/common/kotlin/src/main/java/team/ppac/common/kotlin/model/ReactionState.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package team.ppac.common.kotlin.model | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class ReactionState { | ||
private val _isFirstClickEvent = AtomicBoolean(true) | ||
private val _reactionCount = AtomicInteger(0) | ||
private val _isUpdating = AtomicBoolean(false) | ||
private var lastClickTime: Long = 0 | ||
|
||
val reactionCount: Int | ||
get() = _reactionCount.get() | ||
|
||
val isUpdating: Boolean | ||
get() = _isUpdating.get() | ||
|
||
val isFirstClickEvent: Boolean | ||
get() = _isFirstClickEvent.get() | ||
|
||
fun setIsFirstClickEvent(value: Boolean) { | ||
_isFirstClickEvent.set(value) | ||
} | ||
|
||
fun addReactionCount(count: Int) { | ||
_reactionCount.addAndGet(count) | ||
} | ||
|
||
fun startUpdate() { | ||
_isUpdating.compareAndSet(false, true) | ||
.also { print("isRelease Setting = ${_isUpdating.get()}") } | ||
} | ||
|
||
fun endUpdate() { | ||
_isUpdating.set(false) | ||
} | ||
|
||
fun releaseState() { | ||
_reactionCount.set(0) | ||
_isFirstClickEvent.set(true) | ||
} | ||
|
||
fun isDoubleClickEvent(): Boolean { | ||
val currentClickTime: Long = System.currentTimeMillis() | ||
return if (currentClickTime - lastClickTime <= DOUBLE_CLICK_INTERVAL) { | ||
true | ||
} else { | ||
lastClickTime = System.currentTimeMillis() | ||
false | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DOUBLE_CLICK_INTERVAL = 400 | ||
} | ||
} |
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
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