Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a365c92

Browse files
Add "key" for Lazy Row&Column for every single item divide by id
1 parent 89e7af6 commit a365c92

File tree

10 files changed

+47
-18
lines changed

10 files changed

+47
-18
lines changed

‎core/src/main/java/com/example/core/presentation/StateAndEventViewModel.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
66
import kotlinx.coroutines.flow.MutableStateFlow
77
import kotlinx.coroutines.flow.StateFlow
88
import kotlinx.coroutines.flow.asStateFlow
9+
import kotlinx.coroutines.flow.update
910
import kotlinx.coroutines.launch
1011

1112
abstract class StateAndEventViewModel<UiState, Event>(initialState: UiState) : ViewModel() {
@@ -25,7 +26,7 @@ abstract class StateAndEventViewModel<UiState, Event>(initialState: UiState) : V
2526
protected abstract suspend fun handleEvent(event: Event)
2627

2728
protected fun updateUiState(update: UiState.() -> UiState) {
28-
_uiState.value = _uiState.value.update()
29+
_uiState.update { _uiState.value.update() }
2930
}
3031

3132
fun onEvent(event: Event) {

‎home/src/main/java/com/example/home/data/api/model/HomeResponse.kt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ data class Section(
1111
@SerializedName("sectionData")
1212
val sectionData: List<HomeSection>,
1313
val sectionTitle: String? = null,
14-
val type: Int
14+
val type: Int,
15+
val id: Int
1516
)
1617

1718
data class HomeSection(
1819
val icon: String? = null,
1920
val image: String,
20-
val navigationData: String? = null,
21-
val productId: String? = null,
21+
val navigationData: String = "ND_49581L",
22+
val productId: String = "PI_845481EI",
2223
val productImage: String,
2324
val questions: String? = null,
2425
val rating: String? = null,

‎home/src/main/java/com/example/home/data/domainimpl/mapper/HomeSectionsMapper.kt‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ fun HomeResponse.mapToHomeSections(): HomeSections {
2323
viewType = viewType,
2424
bannerItem = section.sectionData.map { banner ->
2525
mapHomeSectionToBannerItem(banner)
26-
}
26+
},
27+
id = section.id
2728
)
2829

2930
HomeSectionAdapterItem.VIEW_TYPE_SLIDABLE_PRODUCTS -> HomeSectionAdapterItem.SlidableProducts(
3031
viewType = viewType,
3132
productItem = section.sectionData.map { product ->
3233
mapToProductItem(product)
3334
},
34-
sectionTitle = section.sectionTitle ?: ""
35+
sectionTitle = section.sectionTitle ?: "",
36+
id = section.id
3537
)
3638

3739
HomeSectionAdapterItem.VIEW_TYPE_VERTICAL_PRODUCTS -> HomeSectionAdapterItem.VerticalProducts(
3840
viewType = viewType,
3941
productItem = section.sectionData.map { product ->
4042
mapToProductItem(product)
4143
},
42-
sectionTitle = section.sectionTitle ?: ""
44+
sectionTitle = section.sectionTitle ?: "",
45+
id = section.type
4346
)
4447

4548
else -> null
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package com.example.home.domain.model
22

3-
data class BannerItem(val image: String, val navigationData: String?)
3+
data class BannerItem(val image: String, val navigationData: String)

‎home/src/main/java/com/example/home/domain/model/HomeSections.kt‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
package com.example.home.domain.model
22

3+
import androidx.compose.runtime.Immutable
4+
5+
@Immutable
36
data class HomeSections(
47
var sections: List<HomeSectionAdapterItem>
58
)
69

710
sealed class HomeSectionAdapterItem {
811
abstract val viewType: Int
912

13+
@Immutable
1014
data class Banner(
1115
override val viewType: Int = VIEW_TYPE_BANNER,
1216
val bannerItem: List<BannerItem>,
17+
val id: Int
1318
) : HomeSectionAdapterItem()
1419

20+
@Immutable
1521
data class SlidableProducts(
1622
override val viewType: Int = VIEW_TYPE_SLIDABLE_PRODUCTS,
1723
val productItem: List<ProductItem>,
18-
val sectionTitle: String
24+
val sectionTitle: String,
25+
val id: Int
1926
) : HomeSectionAdapterItem()
2027

21-
28+
@Immutable
2229
data class VerticalProducts(
2330
override val viewType: Int = VIEW_TYPE_VERTICAL_PRODUCTS,
2431
val productItem: List<ProductItem>,
25-
val sectionTitle: String
32+
val sectionTitle: String,
33+
val id: Int
2634
) : HomeSectionAdapterItem()
2735

2836

‎home/src/main/java/com/example/home/domain/model/ProductItem.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.example.home.domain.model
22

33
data class ProductItem(
4-
val productId: String?,
4+
val productId: String,
55
val productImage: String,
66
val text: String?,
77
val subText: String?,

‎home/src/main/java/com/example/home/presentation/components/SectionList.kt‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ import com.example.home.presentation.uievent.HomeUIEvent
1313
fun SectionList(sections: List<HomeSectionAdapterItem>?, onEvent: (HomeUIEvent) -> Unit) {
1414
sections?.let {
1515
LazyColumn {
16-
items(sections) { section ->
16+
items(items = sections, key = { section ->
17+
when (section) {
18+
is HomeSectionAdapterItem.Banner -> {
19+
"Banner-" + section.bannerItem.joinToString("-") { it.navigationData }
20+
}
21+
is HomeSectionAdapterItem.SlidableProducts -> "Slidable-${section.id}"
22+
is HomeSectionAdapterItem.VerticalProducts -> "Vertical-${section.sectionTitle}"
23+
}
24+
}) { section ->
1725
when (section) {
1826
is HomeSectionAdapterItem.Banner -> BannerSection(
1927
section.bannerItem,
@@ -32,7 +40,8 @@ fun SectionList(sections: List<HomeSectionAdapterItem>?, onEvent: (HomeUIEvent)
3240
VerticalItemCard(
3341
productItem,
3442
onProductClick = {
35-
onEvent(HomeUIEvent.OnVerticalProductClicked(productItem)
43+
onEvent(
44+
HomeUIEvent.OnVerticalProductClicked(productItem)
3645
)
3746
}
3847
)

‎home/src/main/java/com/example/home/presentation/sections/SlidableSection.kt‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ fun SlidableSection(
3232
Column {
3333
SectionTitle(title = sectionTitle)
3434
LazyRow {
35-
items(productItems) { product ->
36-
HorizontalCard(product.productImage, product.text, product.subText,
35+
items(items = productItems, key = { product ->
36+
product.productId
37+
}) { product ->
38+
HorizontalCard(
39+
product.productImage,
40+
product.text,
41+
product.subText,
3742
onClick = { onProductClick(HomeUIEvent.OnProductClicked) })
3843
}
3944
}

‎list/src/main/java/com/example/list/domain/model/ListData.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.example.list.domain.model
33
data class ListData(
44
val productList: List<ListProductsModel>?,
55
val productLimit: Int?,
6-
val totalCount: Int?
6+
val totalCount: Int?
77
)
88

99
data class ListProductsModel(

‎list/src/main/java/com/example/list/presentation/components/ListContent.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ fun ListContent(productList: List<ListProductsModel>) {
4040
contentPadding = PaddingValues(all = 8.dp),
4141
modifier = Modifier.padding(8.dp)
4242
) {
43-
items(productList) { product ->
43+
items(items = productList, key = { product ->
44+
product.productId
45+
}) {product ->
4446
ProductCard(product)
4547
}
4648
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /