Skip to content

Commit

Permalink
chore: 参数调整
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 25, 2023
1 parent ce3ca5a commit 3439e95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/li/songe/gkd/ui/component/SettingItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package li.songe.gkd.ui.component
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowRight
Expand All @@ -30,7 +30,7 @@ fun SettingItem(
)
.fillMaxWidth()
.padding(10.dp, 10.dp)
.height(30.dp),
.defaultMinSize(minHeight = 30.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/java/li/songe/gkd/util/NavExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import com.ramcosta.composedestinations.spec.Direction
val LocalNavController =
compositionLocalOf<NavHostController> { error("not found DestinationsNavigator") }

private var lastNavigateTime = -1L
private val navThrottle = useThrottle()
fun NavController.navigate(
direction: Direction,
navOptionsBuilder: NavOptionsBuilder.() -> Unit = {},
) {
val t = System.currentTimeMillis()
if (t - lastNavigateTime < 1000) {
return
navThrottle {
navigate(direction.route, navOptionsBuilder)
}
lastNavigateTime = t
navigate(direction.route, navOptionsBuilder)
}
11 changes: 11 additions & 0 deletions app/src/main/java/li/songe/gkd/util/TimeExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ fun Long.format(formatStr: String): String {
formatDateMap[formatStr] = df
}
return df.format(this)
}

fun useThrottle(interval: Long = 1000L): (fn: () -> Unit) -> Unit {
var lastTriggerTime = 0L
return { fn ->
val t = System.currentTimeMillis()
if (t - lastTriggerTime > interval) {
lastTriggerTime = t
fn()
}
}
}

0 comments on commit 3439e95

Please sign in to comment.