Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only display in gallery items that can be displayed without refreshing File entity #1240

Merged
merged 5 commits into from
Jul 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ final class PhotoListViewController: FileListViewController {
}
}

@objc override func forceRefresh() {
Task {
driveFileManager.removeLocalFiles(root: DriveFileManager.lastPicturesRootFile)
super.forceRefresh()
}
}

override static func instantiate(viewModel: FileListViewModel) -> Self {
let viewController = Storyboard.menu
.instantiateViewController(withIdentifier: "PhotoListViewController") as! PhotoListViewController
Expand Down
10 changes: 8 additions & 2 deletions kDrive/UI/Controller/Menu/PhotoList/PhotoListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class PhotoListViewModel: FileListViewModel {
private static let emptySections = [Section(model: Group(referenceDate: Date(), sortMode: .day), elements: [])]

var sections = emptySections
private var moreComing = false
private var moreComing: Bool {
nextCursor != nil
}

private var nextCursor: String?
private var sortMode: PhotoSortMode = UserDefaults.shared.photoSortMode {
didSet { sortingChanged() }
Expand All @@ -73,7 +76,10 @@ class PhotoListViewModel: FileListViewModel {
currentDirectory: DriveFileManager.lastPicturesRootFile)

let fetchedFiles = driveFileManager.database.fetchResults(ofType: File.self) { lazyCollection in
lazyCollection.filter("extensionType IN %@", [ConvertedType.image.rawValue, ConvertedType.video.rawValue])
lazyCollection
.filter("ANY parentLink.id == %@", DriveFileManager.lastPicturesRootFile.id)
.filter("extensionType IN %@", [ConvertedType.image.rawValue, ConvertedType.video.rawValue])
.filter("ANY supportedBy CONTAINS %@", FileSupportedBy.thumbnail.rawValue)
.sorted(by: [SortType.newer.value.sortDescriptor])
}

Expand Down
17 changes: 17 additions & 0 deletions kDriveCore/Data/Cache/DriveFileManager/DriveFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,23 @@ public final class DriveFileManager {
}
}

/// Remove all children of to a root File with a transaction
public func removeLocalFiles(root: File) {
try? database.writeTransaction { writableRealm in
guard let lastPicturesRootInContext = writableRealm
.objects(File.self)
.filter("id == %@", DriveFileManager.lastPicturesRootFile.id)
.first else {
return
}

for child in lastPicturesRootInContext.children {
removeFileInDatabase(fileUid: child.uid, cascade: false, writableRealm: writableRealm)
}
writableRealm.add(lastPicturesRootInContext, update: .modified)
}
}

public func lastModifiedFiles(cursor: String? = nil) async throws -> (files: [File], nextCursor: String?) {
do {
let lastModifiedFilesResponse = try await apiFetcher.lastModifiedFiles(drive: drive, cursor: cursor)
Expand Down
Loading