settings: add media previews setting
Closes: https://github.com/damus-io/damus/pull/1757 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
6daa4f7e13
commit
a80ddc08ec
@@ -110,6 +110,9 @@ class UserSettingsStore: ObservableObject {
|
|||||||
@Setting(key: "always_show_images", default_value: false)
|
@Setting(key: "always_show_images", default_value: false)
|
||||||
var always_show_images: Bool
|
var always_show_images: Bool
|
||||||
|
|
||||||
|
@Setting(key: "media_previews", default_value: true)
|
||||||
|
var media_previews: Bool
|
||||||
|
|
||||||
@Setting(key: "hide_nsfw_tagged_content", default_value: false)
|
@Setting(key: "hide_nsfw_tagged_content", default_value: false)
|
||||||
var hide_nsfw_tagged_content: Bool
|
var hide_nsfw_tagged_content: Bool
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct NoteContentView: View {
|
|||||||
let damus_state: DamusState
|
let damus_state: DamusState
|
||||||
let event: NostrEvent
|
let event: NostrEvent
|
||||||
@State var show_images: Bool
|
@State var show_images: Bool
|
||||||
|
@State var load_media: Bool = false
|
||||||
let size: EventViewKind
|
let size: EventViewKind
|
||||||
let preview_height: CGFloat?
|
let preview_height: CGFloat?
|
||||||
let options: EventViewOptions
|
let options: EventViewOptions
|
||||||
@@ -133,17 +134,20 @@ struct NoteContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_images && artifacts.media.count > 0 {
|
if artifacts.media.count > 0 {
|
||||||
ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
|
if !damus_state.settings.media_previews && !load_media {
|
||||||
} else if !show_images && artifacts.media.count > 0 {
|
loadMediaButton(artifacts: artifacts)
|
||||||
ZStack {
|
} else if show_images || (show_images && !damus_state.settings.media_previews && load_media) {
|
||||||
ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
|
ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
|
||||||
Blur()
|
} else if !show_images || (!show_images && !damus_state.settings.media_previews && load_media) {
|
||||||
.onTapGesture {
|
ZStack {
|
||||||
show_images = true
|
ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media)
|
||||||
}
|
Blur()
|
||||||
|
.onTapGesture {
|
||||||
|
show_images = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//.cornerRadius(10)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if artifacts.invoices.count > 0 {
|
if artifacts.invoices.count > 0 {
|
||||||
@@ -155,15 +159,54 @@ struct NoteContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if with_padding {
|
if damus_state.settings.media_previews {
|
||||||
previewView(links: artifacts.links).padding(.horizontal)
|
if with_padding {
|
||||||
} else {
|
previewView(links: artifacts.links).padding(.horizontal)
|
||||||
previewView(links: artifacts.links)
|
} else {
|
||||||
|
previewView(links: artifacts.links)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadMediaButton(artifacts: NoteArtifactsSeparated) -> some View {
|
||||||
|
Button(action: {
|
||||||
|
load_media = true
|
||||||
|
}, label: {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
HStack {
|
||||||
|
Image("images")
|
||||||
|
Text("Load media", comment: "Button to show media in note.")
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
|
||||||
|
}
|
||||||
|
.padding(EdgeInsets(top: 5, leading: 10, bottom: 0, trailing: 10))
|
||||||
|
|
||||||
|
ForEach(artifacts.media.indices, id: \.self) { index in
|
||||||
|
Divider()
|
||||||
|
.frame(height: 1)
|
||||||
|
switch artifacts.media[index] {
|
||||||
|
case .image(let url), .video(let url):
|
||||||
|
Text("\(url)")
|
||||||
|
.font(eventviewsize_to_font(size, font_size: damus_state.settings.font_size))
|
||||||
|
.foregroundStyle(DamusColors.neutral6)
|
||||||
|
.multilineTextAlignment(.leading)
|
||||||
|
.padding(EdgeInsets(top: 0, leading: 10, bottom: 5, trailing: 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background(DamusColors.neutral1)
|
||||||
|
.frame(minWidth: 300, maxWidth: .infinity, alignment: .center)
|
||||||
|
.cornerRadius(8)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.stroke(DamusColors.neutral3, lineWidth: 1)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
|
||||||
func load(force_artifacts: Bool = false) {
|
func load(force_artifacts: Bool = false) {
|
||||||
// always reload artifacts on load
|
// always reload artifacts on load
|
||||||
let plan = get_preload_plan(evcache: damus_state.events, ev: event, our_keypair: damus_state.keypair, settings: damus_state.settings)
|
let plan = get_preload_plan(evcache: damus_state.events, ev: event, our_keypair: damus_state.keypair, settings: damus_state.settings)
|
||||||
|
|||||||
@@ -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)
|
Toggle(NSLocalizedString("Always show images", comment: "Setting to always show and never blur images"), isOn: $settings.always_show_images)
|
||||||
.toggleStyle(.switch)
|
.toggleStyle(.switch)
|
||||||
|
|
||||||
|
Toggle(NSLocalizedString("Media previews", comment: "Setting to show media"), isOn: $settings.media_previews)
|
||||||
|
.toggleStyle(.switch)
|
||||||
|
|
||||||
Picker(NSLocalizedString("Image uploader", comment: "Prompt selection of user's image uploader"),
|
Picker(NSLocalizedString("Image uploader", comment: "Prompt selection of user's image uploader"),
|
||||||
selection: $settings.default_media_uploader) {
|
selection: $settings.default_media_uploader) {
|
||||||
ForEach(MediaUploader.allCases, id: \.self) { uploader in
|
ForEach(MediaUploader.allCases, id: \.self) { uploader in
|
||||||
|
|||||||
Reference in New Issue
Block a user