Fix infinite cluster load animation

This commit is contained in:
Rahul Patel
2025-05-27 18:06:29 +05:30
parent a505f6f644
commit d91d988e0e
2 changed files with 25 additions and 1 deletions

View File

@@ -60,9 +60,17 @@ class StreamBrowseViewModel @Inject constructor(
liveData.postValue(streamCluster)
} else {
Log.i(TAG, "End of Cluster")
postClusterEnd()
}
} catch (_: Exception) {
}
}
}
fun postClusterEnd() {
streamCluster = streamCluster.copy(
clusterNextPageUrl = ""
)
liveData.postValue(streamCluster)
}
}

View File

@@ -114,7 +114,11 @@ class StreamViewModel @Inject constructor(
liveData.postValue(ViewState.Success(stash.toMap()))
} else {
Log.i(TAG, "End of cluster ${streamCluster.id}")
stashMutex.withLock {
postClusterEnd(category, streamCluster.id)
}
liveData.postValue(ViewState.Success(stash.toMap()))
}
} catch (e: Exception) {
liveData.postValue(ViewState.Error(e.message))
@@ -142,6 +146,18 @@ class StreamViewModel @Inject constructor(
stash[category] = bundle.copy(streamClusters = updatedClusters)
}
private fun postClusterEnd(category: StreamContract.Category, clusterID: Int) {
val bundle = stash[category] ?: return
val oldCluster = bundle.streamClusters[clusterID] ?: return
val updatedCluster = oldCluster.copy(clusterNextPageUrl = "")
val updatedClusters = bundle.streamClusters.toMutableMap().apply {
this[clusterID] = updatedCluster
}
stash[category] = bundle.copy(streamClusters = updatedClusters)
}
private fun targetBundle(category: StreamContract.Category): StreamBundle {
return stash.getOrPut(category) { StreamBundle() }
}