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