1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-24 07:56:57 +00:00

Cache total duration calculation

This commit is contained in:
Isira Seneviratne 2024-07-03 05:17:12 +05:30
parent 72bbe0ea1c
commit 37e4064533

View File

@ -11,7 +11,9 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -40,7 +42,11 @@ import org.schabi.newpipe.viewmodels.PlaylistViewModel
fun Playlist(playlistViewModel: PlaylistViewModel = viewModel()) { fun Playlist(playlistViewModel: PlaylistViewModel = viewModel()) {
val playlistInfo by playlistViewModel.playlistInfo.collectAsState() val playlistInfo by playlistViewModel.playlistInfo.collectAsState()
val streams = playlistViewModel.streamItems.collectAsLazyPagingItems() val streams = playlistViewModel.streamItems.collectAsLazyPagingItems()
val totalDuration = streams.itemSnapshotList.sumOf { it!!.duration } val totalDuration by remember {
derivedStateOf {
streams.itemSnapshotList.sumOf { it!!.duration }
}
}
val context = LocalContext.current val context = LocalContext.current
val onClick = { stream: StreamInfoItem -> val onClick = { stream: StreamInfoItem ->