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
sealed class Action | |
sealed class UpdateAction : Action() { | |
data class ReorderItemsAction(val items: List<Item>) : UpdateAction() | |
data class UpdateItemAction(val localId: String, | |
val text: String, | |
val color: Color) : UpdateAction() | |
} |
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 class ViewActivity<T : ControllerView> : AppCompatActivity() { | |
lateinit var controllerView: T | |
override fun onStart() { | |
super.onStart() | |
controllerView.onStart() | |
} | |
override fun onPause() { |
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 class ViewActivity<T : ControllerView> : AppCompatActivity() { | |
lateinit var controllerView: T | |
override fun onStart() { | |
super.onStart() | |
controllerView.onStart() | |
} | |
//^^ We will do the same with every activity/fragment |
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
interface Subscriber<in T> { | |
fun onNext(data: T) | |
} | |
abstract class Dispatcher<T> { | |
private val subscriptions = ArrayList<Subscriber<T>>() | |
fun subscribe(subscriber: Subscriber<T>): Boolean = | |
subscriptions.add(subscriber) |
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 class ControllerView( | |
protected val actionDispatcher: ActionDispatcher, | |
protected val stateDispatcher: StateDispatcher, | |
private val handleStateDifferentThread: ThreadExecutor? = null) | |
: LifecycleCallbacks, Subscriber<State> { | |
protected fun <T : Action> dispatch(action: T) { | |
actionDispatcher.dispatch(action) | |
} |
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 StoreActionSubscriber(actionDispatcher: ActionDispatcher, | |
actionThread: ThreadExecutor? = null, | |
val stateDispatcher: StateDispatcher) | |
: ActionSubscriber(actionDispatcher, actionThread) { | |
override fun reduce(action: Action) { | |
val currentState = stateDispatcher.state | |
val newState = when (action) { | |
is CreationAction -> CreationReducer.reduce(action, currentState) | |
is UpdateAction -> UpdateReducer.reduce(action, currentState) |
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 ItemsActivity : ViewActivity<ItemsControllerView>(), ItemsViewCallback { | |
//--- We set up the ControllerView --- // | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.items_layout) | |
setupControllerView() | |
bindViews() | |
} |
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 class ControllerView( | |
val store: Store, | |
mainThread: ThreadExecutor? = null) | |
: LifecycleCallbacks, StateHandler(mainThread) { | |
override fun onStart() { | |
store.stateHandlers.add(this) | |
} | |
override fun onDestroy() { |
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 ItemsControllerView( | |
val itemsViewCallback: WeakReference<ItemsViewCallback>, | |
store: Store, | |
mainThread: ThreadExecutor? = null) | |
: ControllerView(store, mainThread) { | |
fun fetchItems() = | |
store.dispatch(FetchItemsAction()) | |
fun toEditItemScreen(item: Item) = |
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
sealed class Action | |
sealed class NavigationAction : Action() { | |
data class EditItemScreenAction(val item: Item) : NavigationAction() | |
class ItemsScreenAction : NavigationAction() | |
} | |
sealed class ReadAction : Action() { | |
class FetchItemsAction : ReadAction() | |
data class ItemsLoadedAction(val items: List<Item>) : ReadAction() |
OlderNewer