Skip to content

Commit fde005e

Browse files
Cache total duration calculation
1 parent a2ee1f1 commit fde005e

File tree

1 file changed

+7
-1
lines changed
  • app/src/main/java/org/schabi/newpipe/compose/playlist

1 file changed

+7
-1
lines changed

app/src/main/java/org/schabi/newpipe/compose/playlist/Playlist.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import androidx.compose.material3.MaterialTheme
1111
import androidx.compose.material3.Surface
1212
import androidx.compose.runtime.Composable
1313
import androidx.compose.runtime.collectAsState
14+
import androidx.compose.runtime.derivedStateOf
1415
import androidx.compose.runtime.getValue
16+
import androidx.compose.runtime.remember
1517
import androidx.compose.ui.platform.LocalContext
1618
import androidx.compose.ui.tooling.preview.Preview
1719
import androidx.compose.ui.unit.dp
@@ -40,7 +42,11 @@ import org.schabi.newpipe.viewmodels.PlaylistViewModel
4042
fun Playlist(playlistViewModel: PlaylistViewModel = viewModel()) {
4143
val playlistInfo by playlistViewModel.playlistInfo.collectAsState()
4244
val streams = playlistViewModel.streamItems.collectAsLazyPagingItems()
43-
val totalDuration = streams.itemSnapshotList.sumOf { it!!.duration }
45+
val totalDuration by remember {
46+
derivedStateOf {
47+
streams.itemSnapshotList.sumOf { it!!.duration }
48+
}
49+
}
4450

4551
val context = LocalContext.current
4652
val onClick = { stream: StreamInfoItem ->

0 commit comments

Comments
 (0)