Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.repeatOnLifecycle
import cc.wordview.app.R
import cc.wordview.app.components.ui.BackTopAppBar
import cc.wordview.app.components.ui.OneTimeEffect
import cc.wordview.app.database.RoomAccess
import cc.wordview.app.database.entity.ViewedVideo
import cc.wordview.app.components.extensions.openActivity
Expand All @@ -51,9 +54,8 @@ import com.composegears.tiamat.compose.navDestination
import com.composegears.tiamat.navigation.NavDestination
import com.gigamole.composefadingedges.verticalFadingEdges
import kotlin.uuid.Uuid
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.uuid.ExperimentalUuidApi

@OptIn(ExperimentalUuidApi::class)
Expand All @@ -62,13 +64,16 @@ val HistoryScreen: NavDestination<Unit> by navDestination {
val listState = rememberLazyListState()

val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

var history = remember { mutableStateListOf<ViewedVideo>() }

OneTimeEffect {
CoroutineScope(Dispatchers.IO).launch {
LaunchedEffect(lifecycleOwner) {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
val database = RoomAccess.getDatabase()
history.addAll(database.viewedVideoDao().getAll())
val videos = withContext(Dispatchers.IO) { database.viewedVideoDao().getAll() }
history.clear()
history.addAll(videos)
}
}

Expand Down Expand Up @@ -118,4 +123,4 @@ val HistoryScreen: NavDestination<Unit> by navDestination {
item { Spacer(Modifier.size(128.dp)) }
}
}
}
}
Loading