-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation refactor - NavigationRouter added (#1698)
- Loading branch information
1 parent
8a77a38
commit f60ba75
Showing
24 changed files
with
131 additions
and
268 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
ui-lib/src/main/java/co/electriccoin/zcash/ui/NavigationRouter.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,53 @@ | ||
package co.electriccoin.zcash.ui | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.consumeAsFlow | ||
import kotlinx.coroutines.launch | ||
|
||
interface NavigationRouter { | ||
fun forward(route: String) | ||
|
||
fun replace(route: String) | ||
|
||
fun back() | ||
|
||
fun observe(): Flow<NavigationCommand> | ||
} | ||
|
||
class NavigationRouterImpl : NavigationRouter { | ||
private val scope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob()) | ||
|
||
private val channel = Channel<NavigationCommand>() | ||
|
||
override fun forward(route: String) { | ||
scope.launch { | ||
channel.send(NavigationCommand.Forward(route)) | ||
} | ||
} | ||
|
||
override fun replace(route: String) { | ||
scope.launch { | ||
channel.send(NavigationCommand.Replace(route)) | ||
} | ||
} | ||
|
||
override fun back() { | ||
scope.launch { | ||
channel.send(NavigationCommand.Back) | ||
} | ||
} | ||
|
||
override fun observe() = channel.consumeAsFlow() | ||
} | ||
|
||
sealed interface NavigationCommand { | ||
data class Forward(val route: String) : NavigationCommand | ||
|
||
data class Replace(val route: String) : NavigationCommand | ||
|
||
data object Back : NavigationCommand | ||
} |
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
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
Oops, something went wrong.