Last active
July 9, 2022 19:21
-
-
Save yoloroy/fa900165ae9982850f5e6d5bf1ac739b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| object Presenter { // presentation layer | |
| fun loadDataForList() { | |
| val dataToShow: List<UiDataShort> = DataStore.retrieveDataList() | |
| } | |
| fun loadDataForDetailedView(clickedData: UiDataShort) { | |
| val dataToShow: UIDataDetailed = DataStore.getDetails(clickedData) | |
| } | |
| } | |
| interface UiDataShort { // some list items | |
| val title: String | |
| val authorName: String | |
| val authorIconUrl: String | |
| } | |
| interface UIDataDetailed { // data for some full page | |
| val title: String | |
| val headerImage: String | |
| val authorName: String | |
| val authorIconUrl: String | |
| val content: String | |
| } | |
| object DataStore { // data payer | |
| private val someData = List(10) { // data layer has access to full data | |
| DataEntity(-1, "title", "header img url", "author", "author ic url", "content", false) | |
| } | |
| fun retrieveDataList(): List<UiDataShort> { | |
| return someData.map { it.ProxyShort() } | |
| } | |
| fun getDetails(short: UiDataShort): UIDataDetailed { | |
| require(short is DataEntity.Inner) // otherwise, this data was not created in the data layer | |
| return short.entity.ProxyDetailed() | |
| } | |
| } | |
| class DataEntity( | |
| val id: Int, | |
| val title: String, | |
| val headerImage: String, | |
| val authorName: String, | |
| val authorIconUrl: String, | |
| val content: String, | |
| val isLast: Boolean | |
| ) { | |
| abstract class Inner(val entity: DataEntity) | |
| inner class ProxyShort : Inner(this@DataEntity), UiDataShort { | |
| override val title: String get() = this@DataEntity.title | |
| override val authorName: String get() = this@DataEntity.authorName | |
| override val authorIconUrl: String get() = this@DataEntity.authorIconUrl | |
| } | |
| inner class ProxyDetailed : Inner(this@DataEntity), UIDataDetailed { | |
| override val title: String get() = this@DataEntity.title | |
| override val headerImage: String get() = this@DataEntity.headerImage | |
| override val authorName: String get() = this@DataEntity.authorName | |
| override val authorIconUrl: String get() = this@DataEntity.authorIconUrl | |
| override val content: String get() = this@DataEntity.content | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment