From 27632c6924110d6b9401b349bbd0217e3406e3b8 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 30 Oct 2023 18:44:13 +0800 Subject: [PATCH] Some scaffolding for multiselect --- .../Share/Views/ShareExtensionView.swift | 3 +- .../Components/FeedCardNavigationLink.swift | 2 +- .../App/Views/Home/HomeFeedViewIOS.swift | 152 ++++++++++-------- .../App/Views/Home/HomeFeedViewModel.swift | 1 + .../Views/FeedItem/LibraryItemCard.swift | 15 ++ 5 files changed, 107 insertions(+), 66 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift index 5d46fea5c..715db6ea5 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift @@ -34,7 +34,8 @@ public struct ShareExtensionView: View { public init(viewModel: ShareExtensionViewModel, labelsViewModel: LabelsViewModel, - extensionContext: NSExtensionContext?) { + extensionContext: NSExtensionContext?) + { _viewModel = StateObject(wrappedValue: viewModel) _labelsViewModel = StateObject(wrappedValue: labelsViewModel) self.extensionContext = extensionContext diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 37865d853..ad02df3d8 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -32,7 +32,7 @@ struct FeedCardNavigationLink: View { @EnvironmentObject var audioController: AudioController let item: LinkedItem - + let isInMultiSelectMode: Bool @ObservedObject var viewModel: HomeFeedViewModel var body: some View { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index dba244997..7a79983f4 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -86,70 +86,7 @@ struct AnimatingCellHeight: AnimatableModifier { } // .navigationBarTitleDisplayMode(.inline) .toolbar { - ToolbarItem(placement: .barLeading) { - VStack(alignment: .leading) { - let title = (LinkedItemFilter(rawValue: viewModel.appliedFilter) ?? LinkedItemFilter.inbox).displayName - - Text(title) - .font(Font.system(size: isListScrolled ? 10 : 18, weight: .semibold)) - - if prefersListLayout, isListScrolled { - Text(listTitle) - .font(Font.system(size: 15, weight: .regular)) - .foregroundColor(Color.appGrayText) - } - }.frame(maxWidth: .infinity, alignment: .leading) - } - ToolbarItem(placement: .barTrailing) { - Button("", action: {}) - .disabled(true) - .overlay { - if viewModel.isLoading, !prefersListLayout, enableGrid { - ProgressView() - } - } - } - ToolbarItem(placement: UIDevice.isIPhone ? .barLeading : .barTrailing) { - if enableGrid { - Button( - action: { prefersListLayout.toggle() }, - label: { - Label("Toggle Feed Layout", systemImage: prefersListLayout ? "square.grid.2x2" : "list.bullet") - } - ) - } else { - EmptyView() - } - } - ToolbarItem(placement: .barTrailing) { - Button( - action: { searchPresented = true }, - label: { - Image(systemName: "magnifyingglass") - .resizable() - .frame(width: 18, height: 18) - .padding(.vertical) - .foregroundColor(.appGrayTextContrast) - } - ) - } - ToolbarItem(placement: .barTrailing) { - if UIDevice.isIPhone { - Menu(content: { - Button(action: { settingsPresented = true }, label: { - Label(LocalText.genericProfile, systemImage: "person.circle") - }) - Button(action: { addLinkPresented = true }, label: { - Label("Add Link", systemImage: "plus.circle") - }) - }, label: { - Image.utilityMenu - }) - .foregroundColor(.appGrayTextContrast) - } else { - EmptyView() - } - } + toolbarItems } .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in loadItems(isRefresh: false) @@ -215,6 +152,92 @@ struct AnimatingCellHeight: AnimatableModifier { } } } + + var toolbarItems: some ToolbarContent { + Group { + ToolbarItem(placement: .barLeading) { + VStack(alignment: .leading) { + let title = (LinkedItemFilter(rawValue: viewModel.appliedFilter) ?? LinkedItemFilter.inbox).displayName + + Text(title) + .font(Font.system(size: isListScrolled ? 10 : 18, weight: .semibold)) + + if prefersListLayout, isListScrolled { + Text(listTitle) + .font(Font.system(size: 15, weight: .regular)) + .foregroundColor(Color.appGrayText) + } + }.frame(maxWidth: .infinity, alignment: .leading) + } + ToolbarItem(placement: .barTrailing) { + Button("", action: {}) + .disabled(true) + .overlay { + if viewModel.isLoading, !prefersListLayout, enableGrid { + ProgressView() + } + } + } + ToolbarItem(placement: UIDevice.isIPhone ? .barLeading : .barTrailing) { + if enableGrid { + Button( + action: { prefersListLayout.toggle() }, + label: { + Label("Toggle Feed Layout", systemImage: prefersListLayout ? "square.grid.2x2" : "list.bullet") + } + ) + } else { + EmptyView() + } + } + ToolbarItem(placement: .barTrailing) { + Button( + action: { searchPresented = true }, + label: { + Image(systemName: "magnifyingglass") + .resizable() + .frame(width: 18, height: 18) + .padding(.vertical) + .foregroundColor(.appGrayTextContrast) + } + ) + } + ToolbarItem(placement: .barTrailing) { + if UIDevice.isIPhone { + Menu(content: { +// Button(action: { +// // withAnimation { +// viewModel.isInMultiSelectMode.toggle() +// // } +// }, label: { +// Label(viewModel.isInMultiSelectMode ? "End Multiselect" : "Select Multiple", systemImage: "checkmark.circle") +// }) + Button(action: { addLinkPresented = true }, label: { + Label("Add Link", systemImage: "plus.circle") + }) + Button(action: { settingsPresented = true }, label: { + Label(LocalText.genericProfile, systemImage: "person.circle") + }) + + }, label: { + Image.utilityMenu + }) + .foregroundColor(.appGrayTextContrast) + } else { + EmptyView() + } + } +// if viewModel.isInMultiSelectMode { +// ToolbarItemGroup(placement: .bottomBar) { +// Button(action: {}, label: { Image(systemName: "archivebox") }) +// Button(action: {}, label: { Image(systemName: "trash") }) +// Button(action: {}, label: { Image.label }) +// Spacer() +// Button(action: { viewModel.isInMultiSelectMode = false }, label: { Text("Cancel") }) +// } +// } + } + } } @MainActor @@ -531,6 +554,7 @@ struct AnimatingCellHeight: AnimatableModifier { ForEach(viewModel.items) { item in FeedCardNavigationLink( item: item, + isInMultiSelectMode: viewModel.isInMultiSelectMode, viewModel: viewModel ) .background(GeometryReader { geometry in diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift index c39745961..d1ba61cbc 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewModel.swift @@ -24,6 +24,7 @@ import Views @Published var itemToSnoozeID: String? @Published var linkRequest: LinkRequest? @Published var showLoadingBar = false + @Published var isInMultiSelectMode = false @Published var appliedSort = LinkedItemSort.newest.rawValue @Published var selectedLinkItem: NSManagedObjectID? // used by mac app only diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift index 83350cd70..47b41f3cf 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift @@ -281,3 +281,18 @@ public struct LibraryItemCard: View { LabelsFlowLayout(labels: nonFlairLabels) } } + +struct CircleCheckboxToggleStyle: ToggleStyle { + func makeBody(configuration: Configuration) -> some View { + Button(action: { + configuration.isOn.toggle() + }, label: { + HStack { + Image(systemName: configuration.isOn ? "checkmark.circle" : "circle") + .font(Font.system(size: 18)) + .foregroundColor(configuration.isOn ? Color.blue : Color.appGrayTextContrast) + } + }) + .buttonStyle(.plain) + } +}