Add thread list empty view

This commit is contained in:
ismailgulek
2021-11-22 16:16:15 +03:00
parent 2f34603f1c
commit 70346b827d
12 changed files with 305 additions and 5 deletions

View File

@@ -54,6 +54,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
}
deinit {
session.threadingService.removeDelegate(self)
self.cancelOperations()
}
@@ -113,6 +114,25 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
roomDisplayName: room.displayName)
}
private var emptyViewModel: ThreadListEmptyViewModel {
switch selectedFilterType {
case .all:
return ThreadListEmptyViewModel(icon: Asset.Images.roomContextMenuReplyInThread.image,
title: VectorL10n.threadsEmptyTitle,
info: VectorL10n.threadsEmptyInfoAll,
tip: VectorL10n.threadsEmptyTip,
showAllThreadsButtonTitle: VectorL10n.threadsEmptyShowAllThreads,
showAllThreadsButtonHidden: true)
case .myThreads:
return ThreadListEmptyViewModel(icon: Asset.Images.roomContextMenuReplyInThread.image,
title: VectorL10n.threadsEmptyTitle,
info: VectorL10n.threadsEmptyInfoMy,
tip: VectorL10n.threadsEmptyTip,
showAllThreadsButtonTitle: VectorL10n.threadsEmptyShowAllThreads,
showAllThreadsButtonHidden: false)
}
}
// MARK: - Private
private func viewModel(forThread thread: MXThread) -> ThreadViewModel {
@@ -195,9 +215,11 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
)
}
private func loadData() {
private func loadData(showLoading: Bool = true) {
viewState = .loading
if showLoading {
viewState = .loading
}
switch selectedFilterType {
case .all:
@@ -206,6 +228,11 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
threads = session.threadingService.participatedThreads(inRoom: roomId)
}
if threads.isEmpty {
viewState = .empty(emptyViewModel)
return
}
threadsLoaded()
}
@@ -244,8 +271,7 @@ final class ThreadListViewModel: ThreadListViewModelProtocol {
extension ThreadListViewModel: MXThreadingServiceDelegate {
func threadingServiceDidUpdateThreads(_ service: MXThreadingService) {
threads = service.threads(inRoom: roomId)
viewState = .loaded
loadData(showLoading: false)
}
}