Moving the ThreadView to the same Model as Global: Only active when using this view.

This commit is contained in:
Vitor Pamplona
2023-02-12 21:53:22 -05:00
parent e5ee367761
commit 80bede648f
2 changed files with 24 additions and 3 deletions

View File

@@ -51,7 +51,7 @@ object ServiceManager {
NostrSingleEventDataSource.start() NostrSingleEventDataSource.start()
NostrSingleChannelDataSource.start() NostrSingleChannelDataSource.start()
NostrSingleUserDataSource.start() NostrSingleUserDataSource.start()
NostrThreadDataSource.start() //NostrThreadDataSource.start()
NostrChatroomListDataSource.start() NostrChatroomListDataSource.start()
} else { } else {
// if not logged in yet, start a basic service wit default relays // if not logged in yet, start a basic service wit default relays

View File

@@ -8,19 +8,40 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController import androidx.navigation.NavController
import com.vitorpamplona.amethyst.service.NostrThreadDataSource import com.vitorpamplona.amethyst.service.NostrThreadDataSource
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
import com.vitorpamplona.amethyst.service.NostrUserProfileFollowersDataSource
import com.vitorpamplona.amethyst.service.NostrUserProfileFollowsDataSource
import com.vitorpamplona.amethyst.service.NostrUserProfileZapsDataSource
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@Composable @Composable
fun ThreadScreen(noteId: String?, accountViewModel: AccountViewModel, navController: NavController) { fun ThreadScreen(noteId: String?, accountViewModel: AccountViewModel, navController: NavController) {
val account by accountViewModel.accountLiveData.observeAsState() val account by accountViewModel.accountLiveData.observeAsState()
DisposableEffect(account) { val lifeCycleOwner = LocalLifecycleOwner.current
DisposableEffect(accountViewModel) {
val observer = LifecycleEventObserver { source, event ->
if (event == Lifecycle.Event.ON_RESUME) {
println("Thread Start")
NostrThreadDataSource.start()
}
if (event == Lifecycle.Event.ON_PAUSE) {
println("Thread Stop")
NostrThreadDataSource.stop()
}
}
lifeCycleOwner.lifecycle.addObserver(observer)
onDispose { onDispose {
NostrThreadDataSource.stop() lifeCycleOwner.lifecycle.removeObserver(observer)
} }
} }