Skip to content

Commit

Permalink
QueryFileListTableViewController (#1134)
Browse files Browse the repository at this point in the history
- add category to OCCoreConnectionStatus to quickly determine offline-like states
- fix bug #1130 where the folder contents wasn't shown when offline
  • Loading branch information
felix-schwarz authored Aug 1, 2022
1 parent 069c5ce commit c1f857e
Showing 1 changed file with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public extension OCQueryState {
}
}

public extension OCCoreConnectionStatus {
var isOffline: Bool {
switch self {
case .offline, .unavailable:
return true
default:
return false
}
}
}

public protocol MultiSelectSupport {
func setupMultiselection()
func enterMultiselection()
Expand Down Expand Up @@ -296,32 +307,37 @@ open class QueryFileListTableViewController: FileListTableViewController, SortBa
self.actionContext = ActionContext(viewController: self, core: core, query: query, items: [OCItem](), location: actionsLocation)
}

switch query.state {
case .contentsFromCache, .idle, .waitingForServerReply:
if previousItemCount == 0, self.items.count == 0, query.state == .waitingForServerReply {
break
}

if query.state.isFinal {
if self.items.count == 0 {
if self.searchController?.searchBar.text != "" {
self.messageView?.message(show: true, with: UIEdgeInsets(top: sortBar?.frame.size.height ?? 0, left: 0, bottom: 0, right: 0), imageName: "icon-search", title: "No matches".localized, message: "There is no results for this search".localized)
} else {
self.messageView?.message(show: true, imageName: "folder", title: "Empty folder".localized, message: "This folder contains no files or folders.".localized)
}
} else {
self.messageView?.message(show: false)
}

self.reloadTableData()
}
case .targetRemoved:
self.messageView?.message(show: true, imageName: "folder", title: "Folder removed".localized, message: "This folder no longer exists on the server.".localized)
self.reloadTableData()

default:
self.messageView?.message(show: false)
}
switch query.state {
case .contentsFromCache, .idle, .waitingForServerReply:
let latestItemCount = self.items.count

if previousItemCount == 0, latestItemCount == 0, query.state == .waitingForServerReply {
break
}

// Refresh on:
if (previousItemCount != latestItemCount) || // - item count change
query.state.isFinal || // - query state is final (== anything but .waitingForServerReply and .started)
((query.state == .waitingForServerReply) && (core?.connectionStatus.isOffline == true)) { // - when waiting for a server reply while the connection is offline
if latestItemCount == 0 {
if self.searchController?.searchBar.text != "" {
self.messageView?.message(show: true, with: UIEdgeInsets(top: sortBar?.frame.size.height ?? 0, left: 0, bottom: 0, right: 0), imageName: "icon-search", title: "No matches".localized, message: "There is no results for this search".localized)
} else {
self.messageView?.message(show: true, imageName: "folder", title: "Empty folder".localized, message: "This folder contains no files or folders.".localized)
}
} else {
self.messageView?.message(show: false)
}

self.reloadTableData()
}
case .targetRemoved:
self.messageView?.message(show: true, imageName: "folder", title: "Folder removed".localized, message: "This folder no longer exists on the server.".localized)
self.reloadTableData()

default:
self.messageView?.message(show: false)
}
}

// MARK: - Themeable
Expand Down

0 comments on commit c1f857e

Please sign in to comment.