Skip to content

Instantly share code, notes, and snippets.

@IlyaGulya
Created May 21, 2018 12:04
Show Gist options
  • Save IlyaGulya/40eaa11b1078adfcaa14dd8844ba5a51 to your computer and use it in GitHub Desktop.
Save IlyaGulya/40eaa11b1078adfcaa14dd8844ba5a51 to your computer and use it in GitHub Desktop.
Delegated View Controller for Paginator
abstract class DelegatedViewController<T> : ViewController<T> {
fun invokeAction(action: DelegatingViewController.DelegatedAction<T>) {
action.invoke(this)
}
}
abstract class DelegatingViewController<T> : ViewController<T> {
abstract fun emitAction(action: DelegatedAction<T>)
override fun showData(show: Boolean, data: List<T>) {
emitAction(ShowDataAction(show, data))
}
override fun showEmptyProgress(show: Boolean) {
emitAction(ShowEmptyProgressAction(show))
}
override fun showEmptyError(show: Boolean, error: Throwable?) {
emitAction(ShowEmptyErrorAction(show, error))
}
override fun showEmptyView(show: Boolean) {
emitAction(ShowEmptyViewAction(show))
}
override fun showErrorMessage(error: Throwable) {
emitAction(ShowErrorMessageAction(error))
}
override fun showRefreshProgress(show: Boolean) {
emitAction(ShowRefreshProgressAction(show))
}
override fun showPageProgress(show: Boolean) {
emitAction(ShowPageProgressAction(show))
}
abstract class DelegatedAction<T> {
abstract fun invoke(viewController: ViewController<T>)
}
open class ShowDataAction<T>(
val show: Boolean,
val data: List<T>
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showData(show, data)
}
}
open class ShowEmptyProgressAction<T>(
val show: Boolean
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showEmptyProgress(show)
}
}
open class ShowEmptyErrorAction<T>(
val show: Boolean,
val error: Throwable?
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showEmptyError(show, error)
}
}
open class ShowEmptyViewAction<T>(
val show: Boolean
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showEmptyView(show)
}
}
open class ShowErrorMessageAction<T>(
val error: Throwable
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showErrorMessage(error)
}
}
open class ShowRefreshProgressAction<T>(
val show: Boolean
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showRefreshProgress(show)
}
}
open class ShowPageProgressAction<T>(
val show: Boolean
) : DelegatedAction<T>() {
override fun invoke(viewController: ViewController<T>) {
viewController.showPageProgress(show)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment