From 2c3368e97184341cbb0622813e40a618b91c90d9 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 25 Sep 2023 16:31:58 +0200 Subject: [PATCH] Enable select media folder Signed-off-by: Milen Pivchev --- iOSClient/Media/NCMediaNew.swift | 70 ++++--------------- iOSClient/Media/NCMediaViewModel.swift | 20 ++++-- .../Media/UIWrapper/NCMediaUIKitWrapper.swift | 1 - .../en.lproj/Localizable.strings | 1 + 4 files changed, 32 insertions(+), 60 deletions(-) diff --git a/iOSClient/Media/NCMediaNew.swift b/iOSClient/Media/NCMediaNew.swift index 28bb1d7def..1052067133 100644 --- a/iOSClient/Media/NCMediaNew.swift +++ b/iOSClient/Media/NCMediaNew.swift @@ -81,7 +81,6 @@ struct NCMediaNew: View { toolbarColors = isScrolledToTop ? [.clear] : [.black.opacity(0.8), .black.opacity(0.0)] } } - } .refreshable { await vm.onPullToRefresh() @@ -130,19 +129,7 @@ struct NCMediaNew: View { Menu { Section { -// Button { -// vm.filterClassTypeImage = !vm.filterClassTypeImage -// vm.filterClassTypeVideo = false -// } label: { -// HStack { -// Image(systemName: "photo.fill") -// -// Spacer() -// Label(NSLocalizedString(vm.filterClassTypeImage ? "_media_viewimage_show_" : "_media_viewimage_hide_", comment: ""), systemImage: "photo.fill") -// } -// } - - Picker("View options", selection: $vm.filter) { + Picker(NSLocalizedString("_media_view_options_", comment: ""), selection: $vm.filter) { Label(NSLocalizedString("_media_viewimage_show_", comment: ""), systemImage: "photo.fill").tag(Filter.onlyPhotos) Label(NSLocalizedString("_media_viewvideo_show_", comment: ""), systemImage: "video.fill").tag(Filter.onlyVideos) @@ -150,47 +137,8 @@ struct NCMediaNew: View { Text(NSLocalizedString("_media_show_all_", comment: "")).tag(Filter.all) }.pickerStyle(.menu) -// Toggle(isOn: $vm.showImages) { -// Label(NSLocalizedString("_media_viewimage_show_", comment: ""), systemImage: "photo.fill") -// } -// .onChange(of: vm.showImages) { _ in -// vm.showVideo = true -// } -// .onTapGesture { -//// vm.showImages = !vm.showImages -// vm.showVideo = true -// } - -// Toggle(isOn: $vm.showVideo) { -// Label(NSLocalizedString("_media_viewvideo_show_", comment: ""), systemImage: "video.fill") -// } -// .onChange(of: vm.showVideo) { _ in -// vm.showImages = true -// } - -// .onTapGesture { -//// vm.showVideo = !vm.showVideo -// vm.showImages = true -// } - -// Button { -// vm.filterClassTypeVideo = !vm.filterClassTypeVideo -// vm.filterClassTypeImage = false -// } label: { -// Label(NSLocalizedString(vm.filterClassTypeVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""), systemImage: "video.fill") -// } - Button { - guard let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController, - let viewController = navigationController.topViewController as? NCSelect - else { return } - -// viewController.delegate = self - viewController.typeOfCommandView = .select - viewController.type = "mediaFolder" -// viewController.selectIndexPath = self.selectIndexPath - - parent.present(navigationController, animated: true, completion: nil) + selectMediaFolder() } label: { Label(NSLocalizedString("_select_media_folder_", comment: ""), systemImage: "folder") } @@ -228,13 +176,25 @@ struct NCMediaNew: View { } } - func cellVisibilityDidChange(_ id: String, change: VisibilityChange, tracker: VisibilityTracker) { + private func cellVisibilityDidChange(_ id: String, change: VisibilityChange, tracker: VisibilityTracker) { DispatchQueue.main.async { if let date = tracker.topVisibleView, !date.isEmpty { title = date } } } + + private func selectMediaFolder() { + guard let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController, + let viewController = navigationController.topViewController as? NCSelect + else { return } + + viewController.delegate = vm + viewController.typeOfCommandView = .select + viewController.type = "mediaFolder" + + parent.present(navigationController, animated: true, completion: nil) + } } struct ToolbarCircularButton: View { diff --git a/iOSClient/Media/NCMediaViewModel.swift b/iOSClient/Media/NCMediaViewModel.swift index afa28adb13..50a650acb0 100644 --- a/iOSClient/Media/NCMediaViewModel.swift +++ b/iOSClient/Media/NCMediaViewModel.swift @@ -22,9 +22,6 @@ import Combine private var predicate: NSPredicate? private let appDelegate = UIApplication.shared.delegate as? AppDelegate -// @Published internal var showImages = true -// @Published internal var showVideo = true - private var cancellables: Set = [] @Published internal var needsLoadingMoreItems = true @@ -229,7 +226,7 @@ extension NCMediaViewModel { account = appDelegate.account } - self.queryDB(isForced: true, showImages: showPhotos, showVideos: showVideos) + self.queryDB(isForced: true, showPhotos: showPhotos, showVideos: showVideos) } private func loadOldMedia(value: Int = -30, limit: Int = 300) { @@ -325,6 +322,21 @@ extension NCMediaViewModel { } } +extension NCMediaViewModel: NCSelectDelegate { + func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], indexPath: [IndexPath], overwrite: Bool, copy: Bool, move: Bool) { + guard let serverUrl = serverUrl, let appDelegate else { return } + + let path = CCUtility.returnPathfromServerUrl(serverUrl, urlBase: appDelegate.urlBase, userId: appDelegate.userId, account: appDelegate.account) ?? "" + NCManageDatabase.shared.setAccountMediaPath(path, account: appDelegate.account) + + self.loadMediaFromDB() + + Task { + await loadNewMedia() + } + } +} + enum Filter { case onlyPhotos, onlyVideos, all } diff --git a/iOSClient/Media/UIWrapper/NCMediaUIKitWrapper.swift b/iOSClient/Media/UIWrapper/NCMediaUIKitWrapper.swift index 41344f0f21..a2ce81d20b 100644 --- a/iOSClient/Media/UIWrapper/NCMediaUIKitWrapper.swift +++ b/iOSClient/Media/UIWrapper/NCMediaUIKitWrapper.swift @@ -31,7 +31,6 @@ class NCMediaUIKitWrapper: UIViewController, ObservableObject { view.addSubview(controller.view) controller.didMove(toParent: self) - NSLayoutConstraint.activate([ controller.view.widthAnchor.constraint(equalTo: view.widthAnchor), controller.view.heightAnchor.constraint(equalTo: view.heightAnchor), diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 84c976b44e..9eebb73516 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -588,6 +588,7 @@ "_media_viewimage_show_" = "Show only images"; "_media_viewvideo_show_" = "Show only videos"; "_media_show_all_" = "Show both"; +"_media_view_options_" = "View options"; "_media_by_created_date_" = "Sort by created date"; "_media_by_upload_date_" = "Sort by upload date"; "_media_by_modified_date_" = "Sort by modified date";