Skip to content

Commit

Permalink
Enable select media folder
Browse files Browse the repository at this point in the history
Signed-off-by: Milen Pivchev <[email protected]>
  • Loading branch information
mpivchev committed Sep 25, 2023
1 parent 5137790 commit 2c3368e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 60 deletions.
70 changes: 15 additions & 55 deletions iOSClient/Media/NCMediaNew.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ struct NCMediaNew: View {
toolbarColors = isScrolledToTop ? [.clear] : [.black.opacity(0.8), .black.opacity(0.0)]
}
}

}
.refreshable {
await vm.onPullToRefresh()
Expand Down Expand Up @@ -130,67 +129,16 @@ 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)

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")
}
Expand Down Expand Up @@ -228,13 +176,25 @@ struct NCMediaNew: View {
}
}

func cellVisibilityDidChange(_ id: String, change: VisibilityChange, tracker: VisibilityTracker<String>) {
private func cellVisibilityDidChange(_ id: String, change: VisibilityChange, tracker: VisibilityTracker<String>) {
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 {
Expand Down
20 changes: 16 additions & 4 deletions iOSClient/Media/NCMediaViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyCancellable> = []

@Published internal var needsLoadingMoreItems = true
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion iOSClient/Media/UIWrapper/NCMediaUIKitWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions iOSClient/Supporting Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 2c3368e

Please sign in to comment.