Skip to content

Commit

Permalink
Show CalDAV/CardDAV/Webcal tab when there's at least one item (#839)
Browse files Browse the repository at this point in the history
Show CalDAV/CardDAV/Webcal tab when there's at least one time
  • Loading branch information
rfc2822 authored Jun 8, 2024
1 parent a3ccdc2 commit 25daa57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ fun AccountScreen(
)

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

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

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

val context = LocalContext.current
AccountScreen(
Expand All @@ -112,16 +117,16 @@ fun AccountScreen(
initialValue = AccountSettings.ShowOnlyPersonal(onlyPersonal = false, locked = false)
).value,
onSetShowOnlyPersonal = model::setShowOnlyPersonal,
hasCardDav = model.hasCardDav.collectAsStateWithLifecycle(false).value,
hasCardDav = addressBooks?.itemCount != 0,
canCreateAddressBook = model.canCreateAddressBook.collectAsStateWithLifecycle(false).value,
cardDavProgress = model.cardDavProgress.collectAsStateWithLifecycle(AccountProgress.Idle).value,
addressBooks = addressBooksPager?.flow?.collectAsLazyPagingItems(),
hasCalDav = model.hasCalDav.collectAsStateWithLifecycle(initialValue = false).value,
addressBooks = addressBooks,
hasCalDav = calendars?.itemCount != 0,
canCreateCalendar = model.canCreateCalendar.collectAsStateWithLifecycle(false).value,
calDavProgress = model.calDavProgress.collectAsStateWithLifecycle(AccountProgress.Idle).value,
calendars = calendarsPager?.flow?.collectAsLazyPagingItems(),
hasWebcal = model.hasWebcal.collectAsStateWithLifecycle(false).value,
subscriptions = subscriptionsPager?.flow?.collectAsLazyPagingItems(),
calendars = calendars,
hasWebcal = subscriptions?.itemCount != 0,
subscriptions = subscriptions,
onUpdateCollectionSync = model::setCollectionSync,
onSubscribe = { collection ->
// subscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class AccountScreenModel @AssistedInject constructor(
private val cardDavSvc = serviceRepository
.getCardDavServiceFlow(account.name)
.stateIn(viewModelScope, initialValue = null, started = SharingStarted.Eagerly)
val hasCardDav = cardDavSvc.map { it != null }
val bindableAddressBookHomesets = getBindableHomesetsFromServiceUseCase(cardDavSvc)
private val bindableAddressBookHomesets = getBindableHomesetsFromServiceUseCase(cardDavSvc)
val canCreateAddressBook = bindableAddressBookHomesets.map { homeSets ->
homeSets.isNotEmpty()
}
Expand All @@ -97,8 +96,7 @@ class AccountScreenModel @AssistedInject constructor(
private val calDavSvc = serviceRepository
.getCalDavServiceFlow(account.name)
.stateIn(viewModelScope, initialValue = null, started = SharingStarted.Eagerly)
val hasCalDav = calDavSvc.map { it != null }
val bindableCalendarHomesets = getBindableHomesetsFromServiceUseCase(calDavSvc)
private val bindableCalendarHomesets = getBindableHomesetsFromServiceUseCase(calDavSvc)
val canCreateCalendar = bindableCalendarHomesets.map { homeSets ->
homeSets.isNotEmpty()
}
Expand All @@ -112,12 +110,6 @@ class AccountScreenModel @AssistedInject constructor(
authoritiesFlow = calDavAuthorities
)
val calendarsPager = getServiceCollectionPagerUseCase(calDavSvc, Collection.TYPE_CALENDAR, showOnlyPersonal)
val hasWebcal = calDavSvc.map { service ->
if (service != null)
collectionRepository.anyWebcal(service.id)
else
false
}
val webcalPager = getServiceCollectionPagerUseCase(calDavSvc, Collection.TYPE_WEBCAL, showOnlyPersonal)


Expand Down

0 comments on commit 25daa57

Please sign in to comment.