From 4a61b9397531f1454b1b9eca2338b008bece8721 Mon Sep 17 00:00:00 2001 From: ericholguin Date: Sat, 14 Oct 2023 16:46:58 -0600 Subject: [PATCH] ui: dont display images when users have collapse image setting enabled Changelog-Added: Add Collapse Images setting option to replace images with their links --- damus/Models/UserSettingsStore.swift | 3 ++ damus/Views/NoteContentView.swift | 48 ++++++++++++------- .../Settings/AppearanceSettingsView.swift | 3 ++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift index 2bab8c1e0..9e03a721f 100644 --- a/damus/Models/UserSettingsStore.swift +++ b/damus/Models/UserSettingsStore.swift @@ -110,6 +110,9 @@ class UserSettingsStore: ObservableObject { @Setting(key: "always_show_images", default_value: false) var always_show_images: Bool + @Setting(key: "collapse_images", default_value: false) + var collapse_images: Bool + @Setting(key: "hide_nsfw_tagged_content", default_value: false) var hide_nsfw_tagged_content: Bool diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift index 4842d2757..3e3351661 100644 --- a/damus/Views/NoteContentView.swift +++ b/damus/Views/NoteContentView.swift @@ -26,7 +26,7 @@ struct NoteContentView: View { let damus_state: DamusState let event: NostrEvent - @State var show_images: Bool + @State var blur_images: Bool let size: EventViewKind let preview_height: CGFloat? let options: EventViewOptions @@ -39,10 +39,10 @@ struct NoteContentView: View { return self.artifacts_model.state.artifacts ?? .separated(.just_content(event.get_content(damus_state.keypair))) } - init(damus_state: DamusState, event: NostrEvent, show_images: Bool, size: EventViewKind, options: EventViewOptions) { + init(damus_state: DamusState, event: NostrEvent, blur_images: Bool, size: EventViewKind, options: EventViewOptions) { self.damus_state = damus_state self.event = event - self.show_images = show_images + self.blur_images = blur_images self.size = size self.options = options self.preview_height = lookup_cached_preview_size(previews: damus_state.previews, evid: event.id) @@ -61,7 +61,7 @@ struct NoteContentView: View { } var preview: LinkViewRepresentable? { - guard show_images, + guard blur_images, case .loaded(let preview) = preview_model.state, case .value(let cached) = preview else { return nil @@ -92,7 +92,7 @@ struct NoteContentView: View { func previewView(links: [URL]) -> some View { Group { - if let preview = self.preview, show_images { + if let preview = self.preview, blur_images { if let preview_height { preview .frame(height: preview_height) @@ -133,17 +133,31 @@ struct NoteContentView: View { } } - if show_images && artifacts.media.count > 0 { - ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) - } else if !show_images && artifacts.media.count > 0 { - ZStack { - ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) - Blur() - .onTapGesture { - show_images = true + if damus_state.settings.collapse_images { + ForEach(artifacts.media.indices, id: \.self) { index in + switch artifacts.media[index] { + case .image(let url), .video(let url): + if with_padding { + truncatedText(content: url_str(url)) + .padding(.horizontal) + } else { + truncatedText(content: url_str(url)) } + } + } + } else { + if blur_images && artifacts.media.count > 0 { + ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) + } else if !blur_images && artifacts.media.count > 0 { + ZStack { + ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) + Blur() + .onTapGesture { + blur_images = true + } + } + //.cornerRadius(10) } - //.cornerRadius(10) } if artifacts.invoices.count > 0 { @@ -618,17 +632,17 @@ struct NoteContentView_Previews: PreviewProvider { Group { VStack { - NoteContentView(damus_state: state, event: test_note, show_images: true, size: .normal, options: []) + NoteContentView(damus_state: state, event: test_note, blur_images: true, size: .normal, options: []) } .previewDisplayName("Short note") VStack { - NoteContentView(damus_state: state, event: test_encoded_note_with_image!, show_images: true, size: .normal, options: []) + NoteContentView(damus_state: state, event: test_encoded_note_with_image!, blur_images: true, size: .normal, options: []) } .previewDisplayName("Note with image") VStack { - NoteContentView(damus_state: state2, event: test_longform_event.event, show_images: true, size: .normal, options: [.wide]) + NoteContentView(damus_state: state2, event: test_longform_event.event, blur_images: true, size: .normal, options: [.wide]) .border(Color.red) } .previewDisplayName("Long-form note") diff --git a/damus/Views/Settings/AppearanceSettingsView.swift b/damus/Views/Settings/AppearanceSettingsView.swift index 0ee6311b3..ba1208ffb 100644 --- a/damus/Views/Settings/AppearanceSettingsView.swift +++ b/damus/Views/Settings/AppearanceSettingsView.swift @@ -81,6 +81,9 @@ struct AppearanceSettingsView: View { Toggle(NSLocalizedString("Always show images", comment: "Setting to always show and never blur images"), isOn: $settings.always_show_images) .toggleStyle(.switch) + Toggle(NSLocalizedString("Collapse images", comment: "Setting to only show image links"), isOn: $settings.collapse_images) + .toggleStyle(.switch) + Picker(NSLocalizedString("Image uploader", comment: "Prompt selection of user's image uploader"), selection: $settings.default_media_uploader) { ForEach(MediaUploader.allCases, id: \.self) { uploader in