Skip to content

Commit fe49ec8

Browse files
committed
refactor: Simplify UiThreadRouter implementation
- Remove unnecessary `runOnUiThread` and `runBlocking` wrappers from `adaptiveNavigateToDetail` and `adaptiveNavigateBack` methods. - Simplify `setAdaptiveNavigator` to use an expression body. - Remove the unused `kotlinx.coroutines.runBlocking` import.
1 parent a4947d3 commit fe49ec8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.softartdev.notedelight
22

33
import com.softartdev.notedelight.navigation.Router
4-
import kotlinx.coroutines.runBlocking
54

65

76
class UiThreadRouter(private val router: Router) : Router {
@@ -12,26 +11,21 @@ class UiThreadRouter(private val router: Router) : Router {
1211

1312
override fun <T : Any> navigate(route: T) = runOnUiThread { router.navigate(route) }
1413

15-
override fun <T : Any> navigateClearingBackStack(route: T) = runOnUiThread {
16-
router.navigateClearingBackStack(route)
17-
}
14+
override fun <T : Any> navigateClearingBackStack(route: T) =
15+
runOnUiThread { router.navigateClearingBackStack(route) }
1816

1917
override fun <T : Any> popBackStack(route: T, inclusive: Boolean, saveState: Boolean): Boolean =
2018
runOnUiThread { router.popBackStack(route, inclusive, saveState) }
2119

2220
override fun popBackStack(): Boolean = runOnUiThread { router.popBackStack() }
2321

24-
override fun setAdaptiveNavigator(adaptiveNavigator: Any) {
22+
override fun setAdaptiveNavigator(adaptiveNavigator: Any) =
2523
router.setAdaptiveNavigator(adaptiveNavigator)
26-
}
2724

2825
override fun releaseAdaptiveNavigator() = router.releaseAdaptiveNavigator()
2926

30-
override suspend fun adaptiveNavigateToDetail(contentKey: Long?) = runOnUiThread {
31-
return@runOnUiThread runBlocking { router.adaptiveNavigateToDetail(contentKey) }
32-
}
27+
override suspend fun adaptiveNavigateToDetail(contentKey: Long?) =
28+
router.adaptiveNavigateToDetail(contentKey)
3329

34-
override suspend fun adaptiveNavigateBack(): Boolean = runOnUiThread {
35-
return@runOnUiThread runBlocking { router.adaptiveNavigateBack() }
36-
}
30+
override suspend fun adaptiveNavigateBack(): Boolean = router.adaptiveNavigateBack()
3731
}

0 commit comments

Comments
 (0)