Moves the creation of the TopBar livedata for lists into the AccountViewModel

This commit is contained in:
Vitor Pamplona
2023-08-12 21:33:29 -04:00
parent ceac61eb19
commit cb3b898e29
2 changed files with 22 additions and 12 deletions

View File

@@ -209,9 +209,7 @@ fun NoTopBar() {
@Composable @Composable
fun StoriesTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) { fun StoriesTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel -> GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel ->
val list by accountViewModel.accountLiveData.map { val list by accountViewModel.storiesListLiveData.observeAsState(GLOBAL_FOLLOWS)
it.account.defaultStoriesFollowList
}.observeAsState(GLOBAL_FOLLOWS)
FollowList( FollowList(
followLists, followLists,
@@ -226,9 +224,7 @@ fun StoriesTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState
@Composable @Composable
fun HomeTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) { fun HomeTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel -> GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel ->
val list by accountViewModel.accountLiveData.map { val list by accountViewModel.homeListLiveData.observeAsState(KIND3_FOLLOWS)
it.account.defaultHomeFollowList
}.observeAsState(KIND3_FOLLOWS)
FollowList( FollowList(
followLists, followLists,
@@ -243,9 +239,7 @@ fun HomeTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, a
@Composable @Composable
fun NotificationTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) { fun NotificationTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel -> GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel ->
val list by accountViewModel.accountLiveData.map { val list by accountViewModel.notificationListLiveData.observeAsState(GLOBAL_FOLLOWS)
it.account.defaultNotificationFollowList
}.observeAsState(GLOBAL_FOLLOWS)
FollowList( FollowList(
followLists, followLists,
@@ -260,9 +254,7 @@ fun NotificationTopBar(followLists: FollowListViewModel, scaffoldState: Scaffold
@Composable @Composable
fun DiscoveryTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) { fun DiscoveryTopBar(followLists: FollowListViewModel, scaffoldState: ScaffoldState, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel -> GenericTopBar(scaffoldState, accountViewModel, nav) { accountViewModel ->
val list by accountViewModel.accountLiveData.map { val list by accountViewModel.discoveryListLiveData.observeAsState(GLOBAL_FOLLOWS)
it.account.defaultDiscoveryFollowList
}.observeAsState(GLOBAL_FOLLOWS)
FollowList( FollowList(
followLists, followLists,

View File

@@ -4,10 +4,12 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.map import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
@@ -43,6 +45,22 @@ class AccountViewModel(val account: Account) : ViewModel() {
val userFollows: LiveData<UserState> = account.userProfile().live().follows.map { it } val userFollows: LiveData<UserState> = account.userProfile().live().follows.map { it }
val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it } val userRelays: LiveData<UserState> = account.userProfile().live().relays.map { it }
val discoveryListLiveData = accountLiveData.map {
it.account.defaultDiscoveryFollowList
}.distinctUntilChanged()
val homeListLiveData = accountLiveData.map {
it.account.defaultHomeFollowList
}.distinctUntilChanged()
val notificationListLiveData = accountLiveData.map {
it.account.defaultNotificationFollowList
}.distinctUntilChanged()
val storiesListLiveData = accountLiveData.map {
it.account.defaultStoriesFollowList
}.distinctUntilChanged()
fun updateAutomaticallyStartPlayback( fun updateAutomaticallyStartPlayback(
automaticallyStartPlayback: ConnectivityType automaticallyStartPlayback: ConnectivityType
) { ) {