Skip to content

Commit

Permalink
Use existence of CalDAV/CardDAV service as condition for whether to s…
Browse files Browse the repository at this point in the history
…how the respective tab
  • Loading branch information
rfc2822 committed Jun 27, 2024
1 parent 5497e34 commit f56755e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -98,13 +97,15 @@ fun AccountScreen(
}
)

val addressBooksPager by model.addressBooksPager.collectAsState(null)
val cardDavService by model.cardDavSvc.collectAsStateWithLifecycle()
val addressBooksPager by model.addressBooksPager.collectAsStateWithLifecycle(null)
val addressBooks = addressBooksPager?.flow?.collectAsLazyPagingItems()

val calendarsPager by model.calendarsPager.collectAsState(null)
val calDavService by model.calDavSvc.collectAsStateWithLifecycle()
val calendarsPager by model.calendarsPager.collectAsStateWithLifecycle(null)
val calendars = calendarsPager?.flow?.collectAsLazyPagingItems()

val subscriptionsPager by model.webcalPager.collectAsState(null)
val subscriptionsPager by model.webcalPager.collectAsStateWithLifecycle(null)
val subscriptions = subscriptionsPager?.flow?.collectAsLazyPagingItems()

val context = LocalContext.current
Expand All @@ -117,11 +118,11 @@ fun AccountScreen(
initialValue = AccountSettings.ShowOnlyPersonal(onlyPersonal = false, locked = false)
).value,
onSetShowOnlyPersonal = model::setShowOnlyPersonal,
hasCardDav = addressBooks?.itemCount != 0,
hasCardDav = cardDavService != null,
canCreateAddressBook = model.canCreateAddressBook.collectAsStateWithLifecycle(false).value,
cardDavProgress = model.cardDavProgress.collectAsStateWithLifecycle(AccountProgress.Idle).value,
addressBooks = addressBooks,
hasCalDav = calendars?.itemCount != 0,
hasCalDav = calDavService != null,
canCreateCalendar = model.canCreateCalendar.collectAsStateWithLifecycle(false).value,
calDavProgress = model.calDavProgress.collectAsStateWithLifecycle(AccountProgress.Idle).value,
calendars = calendars,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AccountScreenModel @AssistedInject constructor(
refreshSettingsSignal.postValue(Unit)
}

private val cardDavSvc = serviceRepository
val cardDavSvc = serviceRepository
.getCardDavServiceFlow(account.name)
.stateIn(viewModelScope, initialValue = null, started = SharingStarted.Eagerly)
private val bindableAddressBookHomesets = getBindableHomesetsFromServiceUseCase(cardDavSvc)
Expand All @@ -93,7 +93,7 @@ class AccountScreenModel @AssistedInject constructor(
)
val addressBooksPager = getServiceCollectionPagerUseCase(cardDavSvc, Collection.TYPE_ADDRESSBOOK, showOnlyPersonal)

private val calDavSvc = serviceRepository
val calDavSvc = serviceRepository
.getCalDavServiceFlow(account.name)
.stateIn(viewModelScope, initialValue = null, started = SharingStarted.Eagerly)
private val bindableCalendarHomesets = getBindableHomesetsFromServiceUseCase(calDavSvc)
Expand Down

0 comments on commit f56755e

Please sign in to comment.