-
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.
Merge pull request #246 from mash-up-kr/feat/kk_count
[Feat] 리액션 모아서 보내기
- Loading branch information
Showing
17 changed files
with
215 additions
and
36 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
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) | ||
} | ||
|
||
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 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
core/data/src/main/java/team/ppac/data/mapper/ReactionMemeMapper.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,8 @@ | ||
package team.ppac.data.mapper | ||
|
||
import team.ppac.domain.model.ReactionMeme | ||
import team.ppac.remote.model.response.meme.ReactionMemeResponse | ||
|
||
internal fun ReactionMemeResponse.toReactionMeme(): ReactionMeme = ReactionMeme( | ||
count = count, | ||
) |
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
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
5 changes: 5 additions & 0 deletions
5
core/domain/src/main/java/team/ppac/domain/model/ReactionMeme.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,5 @@ | ||
package team.ppac.domain.model | ||
|
||
data class ReactionMeme ( | ||
val count: Int | ||
) |
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
7 changes: 4 additions & 3 deletions
7
core/domain/src/main/java/team/ppac/domain/usecase/ReactMemeUseCase.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,16 +1,17 @@ | ||
package team.ppac.domain.usecase | ||
|
||
import team.ppac.domain.model.ReactionMeme | ||
import team.ppac.domain.repository.MemeRepository | ||
import javax.inject.Inject | ||
|
||
interface ReactMemeUseCase { | ||
suspend operator fun invoke(memeId: String): Boolean | ||
suspend operator fun invoke(memeId: String, count: Int): ReactionMeme | ||
} | ||
|
||
internal class ReactMemeUseCaseImpl @Inject constructor( | ||
private val memeRepository: MemeRepository, | ||
) : ReactMemeUseCase { | ||
override suspend fun invoke(memeId: String): Boolean { | ||
return memeRepository.reactMeme(memeId) | ||
override suspend fun invoke(memeId: String, count: Int): ReactionMeme { | ||
return memeRepository.reactMeme(memeId, count) | ||
} | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
core/remote/src/main/kotlin/team/ppac/remote/model/request/meme/ReactMemeRequest.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,10 @@ | ||
package team.ppac.remote.model.request.meme | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class ReactMemeRequest ( | ||
@field:Json(name = "count") | ||
val count: Int, | ||
) |
10 changes: 10 additions & 0 deletions
10
core/remote/src/main/kotlin/team/ppac/remote/model/response/meme/ReactionMemeResponse.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,10 @@ | ||
package team.ppac.remote.model.response.meme | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class ReactionMemeResponse ( | ||
@field:Json(name = "count") | ||
val count: Int, | ||
) |
Oops, something went wrong.