Last active
October 4, 2021 08:40
-
-
Save VictorAlbertos/0d4ef7571003f57a5c5cc691f1406f30 to your computer and use it in GitHub Desktop.
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
fun onViewEvent(sampleViewEvents: SampleViewEvents) { | |
modificationEvents.value += sampleViewEvents | |
} | |
private fun applyEvents(paging: PagingData<SampleEntity>, sampleViewEvents: SampleViewEvents): PagingData<SampleEntity> { | |
return when (sampleViewEvents) { | |
is SampleViewEvents.Remove -> { | |
paging | |
.filter { sampleViewEvents.sampleEntity.id != it.id } | |
} | |
is SampleViewEvents.Edit -> { | |
paging | |
.map { | |
if (sampleViewEvents.sampleEntity.id == it.id) return@map it.copy(name = "${it.name} (updated)") | |
else return@map it | |
} | |
} | |
SampleViewEvents.InsertItemHeader -> { | |
paging.insertHeaderItem( | |
item = SampleEntity( | |
id = Random.nextInt(0, 1000), | |
name = "New item added at the top" | |
) | |
) | |
} | |
SampleViewEvents.InsertItemFooter -> { | |
paging.insertFooterItem( | |
item = SampleEntity( | |
id = Random.nextInt(0, 1000), | |
name = "New item added at the bottom" | |
) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment