NTP-64989 | concurrent modification exception crash fix at prepaid pl… (#16213)
This commit is contained in:
@@ -105,6 +105,7 @@ import com.navi.rr.utils.constants.OffersConstants.OS_TYPE
|
|||||||
import com.ramcosta.composedestinations.spec.Direction
|
import com.ramcosta.composedestinations.spec.Direction
|
||||||
import dagger.Lazy
|
import dagger.Lazy
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import java.util.Collections
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.take
|
import kotlin.collections.take
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
@@ -206,7 +207,7 @@ constructor(
|
|||||||
private val _refreshBillItemAndStatus = MutableStateFlow(RefreshBillState())
|
private val _refreshBillItemAndStatus = MutableStateFlow(RefreshBillState())
|
||||||
val refreshBillItemAndStatus = _refreshBillItemAndStatus.asStateFlow()
|
val refreshBillItemAndStatus = _refreshBillItemAndStatus.asStateFlow()
|
||||||
|
|
||||||
private val myAllBills = mutableListOf<MyBillEntity?>()
|
private val myAllBills = Collections.synchronizedList(mutableListOf<MyBillEntity?>())
|
||||||
|
|
||||||
var arcNudgeResponse: ArcNudgeResponse? = null
|
var arcNudgeResponse: ArcNudgeResponse? = null
|
||||||
|
|
||||||
@@ -590,7 +591,9 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTotalUnpaidBills(): List<MyBillEntity> {
|
private fun getTotalUnpaidBills(): List<MyBillEntity> {
|
||||||
return myAllBills.filterNotNull().filter { !it.isBillPaid }
|
synchronized(myAllBills) {
|
||||||
|
return myAllBills.filterNotNull().filter { !it.isBillPaid }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMyUnpaidBills() {
|
private fun updateMyUnpaidBills() {
|
||||||
|
|||||||
@@ -230,6 +230,9 @@ fun RenderPrepaidRechargeScreen(
|
|||||||
}
|
}
|
||||||
is RechargePlansState.Loaded -> {
|
is RechargePlansState.Loaded -> {
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
|
// Create a defensive copy to prevent ConcurrentModificationException
|
||||||
|
val planGroups = prepaidRechargeState.planGroups.toList()
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize().nestedScroll(nestedScrollConnection)
|
modifier = Modifier.fillMaxSize().nestedScroll(nestedScrollConnection)
|
||||||
) {
|
) {
|
||||||
@@ -255,9 +258,7 @@ fun RenderPrepaidRechargeScreen(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
prepaidRechargeState.planGroups.forEachIndexed {
|
planGroups.forEachIndexed { tabIndex, planGroup ->
|
||||||
tabIndex,
|
|
||||||
planGroup ->
|
|
||||||
Tab(
|
Tab(
|
||||||
modifier = Modifier.wrapContentSize(),
|
modifier = Modifier.wrapContentSize(),
|
||||||
selected = pagerState.currentPage == tabIndex,
|
selected = pagerState.currentPage == tabIndex,
|
||||||
@@ -315,14 +316,15 @@ fun RenderPrepaidRechargeScreen(
|
|||||||
ShadowStrip()
|
ShadowStrip()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Using the same defensive copy for the HorizontalPager
|
||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
count = prepaidRechargeState.planGroups.size,
|
count = planGroups.size,
|
||||||
flingBehavior =
|
flingBehavior =
|
||||||
flingBehavior(
|
flingBehavior(
|
||||||
pagerState = pagerState,
|
pagerState = pagerState,
|
||||||
noOfPages = prepaidRechargeState.planGroups.size,
|
noOfPages = planGroups.size,
|
||||||
minFlingDistance = 100,
|
minFlingDistance = 100,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
@@ -341,14 +343,9 @@ fun RenderPrepaidRechargeScreen(
|
|||||||
Modifier.fillMaxSize().padding(horizontal = 8.dp),
|
Modifier.fillMaxSize().padding(horizontal = 8.dp),
|
||||||
userScrollEnabled = !pagerState.isScrollInProgress,
|
userScrollEnabled = !pagerState.isScrollInProgress,
|
||||||
) {
|
) {
|
||||||
if (
|
if (pagerState.currentPage in planGroups.indices) {
|
||||||
pagerState.currentPage in
|
|
||||||
0 until prepaidRechargeState.planGroups.size
|
|
||||||
) {
|
|
||||||
val selectedTabPlans =
|
val selectedTabPlans =
|
||||||
prepaidRechargeState.planGroups[
|
planGroups[pagerState.currentPage].plans
|
||||||
pagerState.currentPage]
|
|
||||||
.plans
|
|
||||||
|
|
||||||
items(selectedTabPlans.size) { index ->
|
items(selectedTabPlans.size) { index ->
|
||||||
val plan = selectedTabPlans[index]
|
val plan = selectedTabPlans[index]
|
||||||
|
|||||||
Reference in New Issue
Block a user