-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PmDescription and PmParams replaced with serializable arguments (PmAr…
…gs).
- Loading branch information
Showing
58 changed files
with
495 additions
and
550 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -74,10 +74,10 @@ internal class DialogGroupNavigatorImpl( | |
hostPm.SaveableFlow( | ||
key = key, | ||
initialValueProvider = { listOf() }, | ||
saveTypeMapper = { dialogs -> dialogs.map { it.description } }, | ||
restoreTypeMapper = { descriptions -> | ||
descriptions.mapNotNull { description -> | ||
dialogNavigators.find { it.dialog?.description == description }?.dialog | ||
saveTypeMapper = { dialogs -> dialogs.map { it.pmArgs } }, | ||
restoreTypeMapper = { pmArgsList -> | ||
pmArgsList.mapNotNull { pmArgs -> | ||
dialogNavigators.find { it.dialog?.pmArgs == pmArgs }?.dialog | ||
} | ||
} | ||
) | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -91,7 +91,7 @@ internal class DialogNavigatorImpl<D : PresentationModel, R : PmMessage>( | |
private val _dialog: MutableStateFlow<D?> = hostPm.SaveableFlow( | ||
key = key, | ||
initialValueProvider = { null }, | ||
saveTypeMapper = { it?.description }, | ||
saveTypeMapper = { it?.pmArgs }, | ||
restoreTypeMapper = { it?.let { hostPm.AttachedChild(it) as D } } | ||
) | ||
override val dialogFlow: StateFlow<D?> = _dialog.asStateFlow() | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -25,7 +25,6 @@ | |
package me.dmdev.premo.navigation | ||
|
||
import kotlinx.coroutines.flow.StateFlow | ||
import me.dmdev.premo.PmDescription | ||
import me.dmdev.premo.PmMessageHandler | ||
import me.dmdev.premo.PresentationModel | ||
|
||
|
@@ -39,13 +38,13 @@ interface MasterDetailNavigation<M, D> | |
} | ||
|
||
fun <M : PresentationModel, D : PresentationModel> PresentationModel.MasterDetailNavigation( | ||
masterDescription: PmDescription, | ||
masterPm: M, | ||
key: String = DEFAULT_MASTER_DETAIL_NAVIGATOR_KEY, | ||
backHandler: (MasterDetailNavigator<M, D>) -> Boolean = DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER, | ||
initHandlers: PmMessageHandler.(navigator: MasterDetailNavigator<M, D>) -> Unit = {} | ||
): MasterDetailNavigation<M, D> { | ||
return MasterDetailNavigator( | ||
masterDescription = masterDescription, | ||
masterPm = masterPm, | ||
key = key, | ||
backHandler = backHandler, | ||
initHandlers = initHandlers | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import me.dmdev.premo.AttachedChild | ||
import me.dmdev.premo.PmDescription | ||
import me.dmdev.premo.PmArgs | ||
import me.dmdev.premo.PmMessageHandler | ||
import me.dmdev.premo.PresentationModel | ||
import me.dmdev.premo.SaveableFlow | ||
|
@@ -57,14 +57,14 @@ fun MasterDetailNavigator<*, *>.handleBack(): Boolean { | |
} | ||
|
||
fun <M : PresentationModel, D : PresentationModel> PresentationModel.MasterDetailNavigator( | ||
masterDescription: PmDescription, | ||
masterPm: M, | ||
key: String = DEFAULT_MASTER_DETAIL_NAVIGATOR_KEY, | ||
backHandler: (MasterDetailNavigator<M, D>) -> Boolean = DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER, | ||
initHandlers: PmMessageHandler.(navigator: MasterDetailNavigator<M, D>) -> Unit = {} | ||
): MasterDetailNavigator<M, D> { | ||
val navigator = MasterDetailNavigatorImpl<M, D>( | ||
hostPm = this, | ||
masterDescription = masterDescription, | ||
masterPm = masterPm, | ||
key = key | ||
) | ||
messageHandler.handle<BackMessage> { backHandler.invoke(navigator) } | ||
|
@@ -80,19 +80,23 @@ internal val DEFAULT_MASTER_DETAIL_NAVIGATOR_BACK_HANDLER: (MasterDetailNavigato | |
|
||
internal class MasterDetailNavigatorImpl<M, D>( | ||
private val hostPm: PresentationModel, | ||
masterDescription: PmDescription, | ||
masterPm: M, | ||
key: String | ||
) : MasterDetailNavigator<M, D> | ||
where M : PresentationModel, | ||
D : PresentationModel { | ||
|
||
override val master: M = hostPm.AttachedChild(masterDescription) | ||
override val master: M = masterPm | ||
|
||
init { | ||
masterPm.attachToParent() | ||
} | ||
|
||
private val _detailFlow: MutableStateFlow<D?> = hostPm.SaveableFlow( | ||
key = "${key}_detail_pm", | ||
initialValueProvider = { null }, | ||
saveType = typeOf<PmDescription>(), | ||
saveTypeMapper = { it?.description }, | ||
saveType = typeOf<PmArgs>(), | ||
saveTypeMapper = { it?.pmArgs }, | ||
restoreTypeMapper = { it?.let { hostPm.AttachedChild(it) as D } } | ||
) | ||
override val detailFlow: StateFlow<D?> = _detailFlow.asStateFlow() | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -25,7 +25,6 @@ | |
package me.dmdev.premo.navigation | ||
|
||
import kotlinx.coroutines.flow.StateFlow | ||
import me.dmdev.premo.PmDescription | ||
import me.dmdev.premo.PresentationModel | ||
|
||
interface SetNavigation { | ||
|
@@ -38,13 +37,13 @@ interface SetNavigation { | |
} | ||
|
||
fun PresentationModel.SetNavigation( | ||
vararg initialDescriptions: PmDescription, | ||
initValues: () -> List<PresentationModel>, | ||
key: String = DEFAULT_SET_NAVIGATOR_KEY, | ||
backHandler: (SetNavigator) -> Boolean = DEFAULT_SET_NAVIGATOR_BACK_HANDLER, | ||
onChangeCurrent: (index: Int, navigator: SetNavigator) -> Unit = DEFAULT_SET_NAVIGATOR_ON_CHANGE_CURRENT | ||
): SetNavigation { | ||
return SetNavigator( | ||
initialDescriptions = initialDescriptions, | ||
initValues = initValues, | ||
key = key, | ||
backHandler = backHandler, | ||
onChangeCurrent = onChangeCurrent | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020-2023 Dmitriy Gorbunov ([email protected]) | ||
* Copyright (c) 2020-2024 Dmitriy Gorbunov ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -27,7 +27,6 @@ package me.dmdev.premo.navigation | |
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import me.dmdev.premo.ExperimentalPremoApi | ||
import me.dmdev.premo.PmDescription | ||
import me.dmdev.premo.PmMessageHandler | ||
import me.dmdev.premo.PresentationModel | ||
|
||
|
@@ -42,41 +41,13 @@ interface StackNavigation { | |
} | ||
|
||
fun PresentationModel.StackNavigation( | ||
initialDescription: PmDescription? = null, | ||
initBackStack: () -> List<PresentationModel>, | ||
key: String = DEFAULT_STACK_NAVIGATOR_KEY, | ||
backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, | ||
initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} | ||
): StackNavigation { | ||
return StackNavigator( | ||
initialBackStack = initialDescription?.let { listOf(it) } ?: listOf(), | ||
key = key, | ||
backHandler = backHandler, | ||
initHandlers = initHandlers | ||
) | ||
} | ||
|
||
fun PresentationModel.StackNavigation( | ||
vararg initialDescriptions: PmDescription, | ||
key: String = DEFAULT_STACK_NAVIGATOR_KEY, | ||
backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, | ||
initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} | ||
): StackNavigation { | ||
return StackNavigator( | ||
initialBackStack = initialDescriptions.asList(), | ||
key = key, | ||
backHandler = backHandler, | ||
initHandlers = initHandlers | ||
) | ||
} | ||
|
||
fun PresentationModel.StackNavigation( | ||
initialBackStack: List<PmDescription>, | ||
key: String = DEFAULT_STACK_NAVIGATOR_KEY, | ||
backHandler: (StackNavigator) -> Boolean = DEFAULT_STACK_NAVIGATOR_BACK_HANDLER, | ||
initHandlers: PmMessageHandler.(navigator: StackNavigator) -> Unit = {} | ||
): StackNavigation { | ||
return StackNavigator( | ||
initialBackStack = initialBackStack, | ||
initBackStack = initBackStack, | ||
key = key, | ||
backHandler = backHandler, | ||
initHandlers = initHandlers | ||
|
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.