Skip to content

Commit

Permalink
Fix: Use Kotlin object to create the singleton ClickHelper.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakhar-Agarwal-byte authored and thunderbiscuit committed Jul 21, 2023
1 parent 83836fc commit 6fda520
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fun SendReceive(navController: NavHostController) {
.height(70.dp)
) {
Button(
onClick = { ClickHelper.getInstance().clickOnce { navController.navigate(Screen.ReceiveScreen.route) }},
onClick = { ClickHelper.clickOnce { navController.navigate(Screen.ReceiveScreen.route) }},
colors = ButtonDefaults.buttonColors(containerColor = padawan_theme_button_secondary),
shape = RoundedCornerShape(20.dp),
border = standardBorder,
Expand All @@ -311,7 +311,7 @@ fun SendReceive(navController: NavHostController) {
}
}
Button(
onClick = { ClickHelper.getInstance().clickOnce { navController.navigate(Screen.SendScreen.route) }},
onClick = { ClickHelper.clickOnce { navController.navigate(Screen.SendScreen.route) }},
colors = ButtonDefaults.buttonColors(containerColor = padawan_theme_button_primary),
shape = RoundedCornerShape(20.dp),
border = standardBorder,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package com.goldenraven.padawanwallet.utils

class ClickHelper private constructor() {
object ClickHelper {
private val now: Long
get() = System.currentTimeMillis()
private var lastEventTimeMs: Long = 0

fun clickOnce(event: () -> Unit) {
if (now - lastEventTimeMs >= 800L) {
event.invoke()
}
lastEventTimeMs = now
}
companion object {
@Volatile
private var instance: ClickHelper? = null
fun getInstance() =
instance ?: synchronized(this) {
instance ?: ClickHelper().also { instance = it }
}
}
}
}

0 comments on commit 6fda520

Please sign in to comment.