Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions iOSClient/Media/NCMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ class NCMedia: UIViewController {
pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture(_:)))
collectionView.addGestureRecognizer(pinchGesture)

Task {
await loadDataSource()
}

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: global.notificationCenterChangeUser), object: nil, queue: nil) { [weak self] notification in
guard let self else {
return
Expand All @@ -196,6 +200,7 @@ class NCMedia: UIViewController {
self.dataSource.clearCompactMetadatas()
self.setTitleDate()

await self.loadDataSource(forced: true)
await self.searchMediaUI(true)
}
}
Expand Down Expand Up @@ -247,7 +252,7 @@ class NCMedia: UIViewController {
return
}

await self.loadDataSource()
self.searchNewMedia()

guard !Task.isCancelled else {
return
Expand All @@ -263,8 +268,6 @@ class NCMedia: UIViewController {
super.viewDidAppear(animated)

NotificationCenter.default.addObserver(self, selector: #selector(enterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)

searchNewMedia()
}

override func viewDidDisappear(_ animated: Bool) {
Expand Down
46 changes: 37 additions & 9 deletions iOSClient/Media/NCMediaDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NextcloudKit
import RealmSwift

extension NCMedia {
func loadDataSource() async {
func loadDataSource(forced: Bool = false) async {
let account = self.session.account

guard !Task.isCancelled else {
Expand Down Expand Up @@ -56,10 +56,12 @@ extension NCMedia {
}

let shouldContinue = await MainActor.run {
self.isViewActived &&
self.session.account == account &&
self.view.window != nil &&
self.tabBarController?.selectedViewController === self.navigationController
forced || (
self.isViewActived &&
self.session.account == account &&
self.view.window != nil &&
self.tabBarController?.selectedViewController === self.navigationController
)
}

guard shouldContinue,
Expand All @@ -77,10 +79,16 @@ extension NCMedia {

await MainActor.run {
guard !Task.isCancelled,
self.isViewActived,
self.session.account == account,
self.view.window != nil,
self.tabBarController?.selectedViewController === self.navigationController else {
forced || (
self.isViewActived &&
self.session.account == account &&
self.view.window != nil &&
self.tabBarController?.selectedViewController === self.navigationController
) else {
return
}

guard !self.dataSource.hasSameContent(as: dataSource) else {
return
}

Expand Down Expand Up @@ -729,6 +737,26 @@ public class NCMediaDataSource: NSObject {

// MARK: -

func hasSameContent(as otherDataSource: NCMediaDataSource) -> Bool {
guard compactMetadatas.count == otherDataSource.compactMetadatas.count else {
return false
}

for (currentMetadata, otherMetadata) in zip(
compactMetadatas,
otherDataSource.compactMetadatas
) {
guard currentMetadata.ocId == otherMetadata.ocId,
currentMetadata.etag == otherMetadata.etag,
currentMetadata.date == otherMetadata.date,
currentMetadata.isLivePhoto == otherMetadata.isLivePhoto else {
return false
}
}

return true
}

func clearCompactMetadatas() {
compactMetadatas.removeAll()
sections.removeAll()
Expand Down
Loading