Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Open only a single fragment instance incase of multiple clicks … #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.goldenraven.padawanwallet.theme.*
import com.goldenraven.padawanwallet.ui.FadedVerticalDivider
import com.goldenraven.padawanwallet.ui.Screen
import com.goldenraven.padawanwallet.ui.standardBorder
import com.goldenraven.padawanwallet.utils.ClickHelper
import com.goldenraven.padawanwallet.utils.ScreenSizeWidth
import com.goldenraven.padawanwallet.utils.formatCurrency
import com.goldenraven.padawanwallet.utils.formatInBtc
Expand Down Expand Up @@ -289,7 +290,7 @@ fun SendReceive(navController: NavHostController) {
.height(70.dp)
) {
Button(
onClick = { 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 @@ -310,7 +311,7 @@ fun SendReceive(navController: NavHostController) {
}
}
Button(
onClick = { 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
@@ -0,0 +1,14 @@
package com.goldenraven.padawanwallet.utils

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
}
}