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) liveData.postValue(streamCluster)
} else { } else {
Log.i(TAG, "End of Cluster") Log.i(TAG, "End of Cluster")
postClusterEnd()
} }
} catch (_: Exception) { } 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())) liveData.postValue(ViewState.Success(stash.toMap()))
} else { } else {
Log.i(TAG, "End of cluster ${streamCluster.id}") stashMutex.withLock {
postClusterEnd(category, streamCluster.id)
}
liveData.postValue(ViewState.Success(stash.toMap()))
} }
} catch (e: Exception) { } catch (e: Exception) {
liveData.postValue(ViewState.Error(e.message)) liveData.postValue(ViewState.Error(e.message))
@@ -142,6 +146,18 @@ class StreamViewModel @Inject constructor(
stash[category] = bundle.copy(streamClusters = updatedClusters) 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 { private fun targetBundle(category: StreamContract.Category): StreamBundle {
return stash.getOrPut(category) { StreamBundle() } return stash.getOrPut(category) { StreamBundle() }
} }