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
internal class ChangeFavoriteStatusCommand( | |
private val mainItemUid: String, | |
private val changeToFavorite: Boolean, | |
private val changeFavoriteAction: suspend () -> Unit, | |
private val onFavoriteChangeFailed: (Throwable) -> Unit | |
) : ActionCommandWithStrategy<Unit, ListScreenState>(ConcurrentStrategyWithTag(mainItemUid)) { | |
override fun onCommandWasAdded(dataState: ListScreenState): ListScreenState = | |
// we update item state only if the list contains this item | |
if (dataState.pageData?.itemsList?.any { it.key == mainItemUid } == true) { |
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
class SimpleListViewModel(application: Application) : ListViewModel(application) { | |
private val mutableScreenState = MutableLiveData( | |
ListScreenState(null, null, null) | |
) | |
override val screenState: LiveData<ListScreenState> = mutableScreenState | |
override val commandManager: CommandManager<ListScreenState> by lazy { | |
CommandManagerImpl(mutableScreenState, viewModelScope) | |
} |
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
open class SingleStrategy : ExecutionStrategy { | |
override fun shouldAddToPendingActions( | |
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>, | |
runningActionCommands: List<ActionCommand<*, *>> | |
): Boolean = | |
!pendingActionCommands.any { it.strategy is SingleStrategy } | |
&& !runningActionCommands.any { it.strategy is SingleStrategy } | |
override fun shouldBlockOtherTask(pendingActionCommand: ActionCommand<*, *>): Boolean = |
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
open class ConcurrentStrategyWithTag(private val tag: Any) : ConcurrentStrategy() { | |
override fun shouldAddToPendingActions( | |
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>, | |
runningActionCommands: List<ActionCommand<*, *>> | |
): Boolean { | |
pendingActionCommands.removeAll { command -> | |
command.strategy.let { it is ConcurrentStrategyWithTag && it.tag == tag } | |
} | |
return true |
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
open class ConcurrentStrategy : ExecutionStrategy { | |
override fun shouldAddToPendingActions( | |
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>, | |
runningActionCommands: List<ActionCommand<*, *>> | |
): Boolean = | |
true | |
override fun shouldBlockOtherTask(pendingActionCommand: ActionCommand<*, *>): Boolean = | |
false |
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
abstract fun shouldAddToPendingActions( | |
dataState: DataState, | |
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>, | |
runningActionCommands: List<ActionCommand<*, *>> | |
): Boolean | |
abstract fun shouldBlockOtherTask(pendingActionCommand: ActionCommand<*, *>): Boolean | |
abstract fun shouldExecuteAction( |
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
open fun onCommandWasAdded(dataState: DataState): DataState = dataState | |
open fun onExecuteStarting(dataState: DataState): DataState = dataState | |
abstract suspend fun executeCommand(dataState: DataState): CommandResult | |
open fun onExecuteSuccess(dataState: DataState, result: CommandResult): DataState = dataState | |
open fun onExecuteFail(dataState: DataState, error: Throwable): DataState = dataState | |
open fun onExecuteFinished(dataState: DataState): DataState = dataState |
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
bazel build //app/src/main:bazel |
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
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | |
kotlin_version = "1.3.61" | |
kotlin_release_sha = "3901151ad5d94798a268d1771c6c0b7e305a608c2889fc98a674802500597b1c" | |
rules_kotlin_compiler_release = { | |
"urls": [ | |
"https://github.com/JetBrains/kotlin/releases/download/v{v}/kotlin-compiler-{v}.zip".format(v = kotlin_version), | |
], | |
"sha256": kotlin_release_sha, | |
} |
NewerOlder