-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scan QR code from static image #1566
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Fri, Sep 29, 2023 at 11:04:48PM -0600, ericholguin wrote:
Closes: #1566
---
damus/Views/Images/ImageContextMenuModifier.swift | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/damus/Views/Images/ImageContextMenuModifier.swift b/damus/Views/Images/ImageContextMenuModifier.swift
index 7bf5bc509..e7633bfbf 100644
--- a/damus/Views/Images/ImageContextMenuModifier.swift
+++ b/damus/Views/Images/ImageContextMenuModifier.swift
@@ -47,7 +47,9 @@ struct ImageContextMenuModifier: ViewModifier {
let features = detector.features(in: ciImage)
if let qrfeatures = features as? [CIQRCodeFeature] {
for feature in qrfeatures {
- qrCodeLink += feature.messageString!
+ if let msgStr = feature.messageString {
+ qrCodeLink += msgStr
+ }
This looks off to me. I think you meant this?
for feature in qrfeatures {
if let msgStr = feature.messageString {
qrCodeLink += msgStr
}
}
|
On Sat, Sep 30, 2023 at 08:39:28AM -0700, William Casarin wrote:
This looks off to me. I think you meant this?
for feature in qrfeatures {
if let msgStr = feature.messageString {
qrCodeLink += msgStr
}
}
disregard this, I misread the diff. blame lack of coffee.
|
On Tue, Sep 19, 2023 at 06:15:50PM -0600, ericholguin wrote:
+ Button {
+ qrCodeLink = ""
+ let detector:CIDetector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])!
+ let ciImage: CIImage = CIImage(image:someImage)!
please no !'s as they can crash. always use guard or if let instead:
guard let ciImage = CIImage(image:someImage) else {
return
}
you can just squash all your commits into one, they seem to be
re-touching the same files:
```
$ git rebase -i origin/master
# then mark everything under the first commit as `f`
# refresh the PR
$ git push -f
```
|
you prefer guard or are |
On Sat, Sep 30, 2023 at 10:35:00AM -0700, Eric Holguin wrote:
you prefer guard or are `if let` statements okay?
I prefer guard to not needlessly increase indentation level
|
ericholguin
force-pushed
the
scan-image-qr-2
branch
from
October 3, 2023 01:32
4677d66
to
282d0c7
Compare
Comments addressed |
On Wed, Oct 04, 2023 at 04:20:23PM -0700, Eric Holguin wrote:
Comments addressed
thanks! will take a look again
|
Reviewed-by: William Casarin ***@***.***>
…On Tue, Sep 19, 2023 at 06:15:50PM -0600, ericholguin wrote:
Closes: #1566
---
damus/Components/ImageCarousel.swift | 2 +-
damus/Views/Images/ImageContainerView.swift | 9 ++--
.../Images/ImageContextMenuModifier.swift | 48 +++++++++++++++++++
damus/Views/Images/ImageView.swift | 6 +--
damus/Views/Images/ProfilePicImageView.swift | 13 +++--
damus/Views/Profile/ProfileView.swift | 2 +-
6 files changed, 63 insertions(+), 17 deletions(-)
diff --git a/damus/Components/ImageCarousel.swift b/damus/Components/ImageCarousel.swift
index d7586b3a7..a586a4688 100644
--- a/damus/Components/ImageCarousel.swift
+++ b/damus/Components/ImageCarousel.swift
@@ -190,7 +190,7 @@ struct ImageCarousel: View {
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.fullScreenCover(isPresented: $open_sheet) {
- ImageView(video_controller: state.video, urls: urls, disable_animation: state.settings.disable_animation)
+ ImageView(video_controller: state.video, urls: urls, settings: state.settings)
}
.frame(height: height)
.onChange(of: selectedIndex) { value in
diff --git a/damus/Views/Images/ImageContainerView.swift b/damus/Views/Images/ImageContainerView.swift
index a0a740a4a..094d87533 100644
--- a/damus/Views/Images/ImageContainerView.swift
+++ b/damus/Views/Images/ImageContainerView.swift
@@ -12,12 +12,11 @@ import Kingfisher
struct ImageContainerView: View {
let video_controller: VideoController
let url: MediaUrl
+ let settings: UserSettingsStore
@State private var image: UIImage?
@State private var showShareSheet = false
- let disable_animation: Bool
-
private struct ImageHandler: ImageModifier {
@binding var handler: UIImage?
@@ -29,13 +28,13 @@ struct ImageContainerView: View {
func Img(url: URL) -> some View {
KFAnimatedImage(url)
- .imageContext(.note, disable_animation: disable_animation)
+ .imageContext(.note, disable_animation: settings.disable_animation)
.configure { view in
view.framePreloadCount = 3
}
.imageModifier(ImageHandler(handler: $image))
.clipped()
- .modifier(ImageContextMenuModifier(url: url, image: image, showShareSheet: $showShareSheet))
+ .modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
.sheet(isPresented: $showShareSheet) {
ShareSheet(activityItems: [url])
}
@@ -57,6 +56,6 @@ let test_image_url = URL(string: "https://jb55.com/red-me.jpg")!
struct ImageContainerView_Previews: PreviewProvider {
static var previews: some View {
- ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), disable_animation: false)
+ ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), settings: test_damus_state.settings)
}
}
diff --git a/damus/Views/Images/ImageContextMenuModifier.swift b/damus/Views/Images/ImageContextMenuModifier.swift
index a3090bb5f..167fce036 100644
--- a/damus/Views/Images/ImageContextMenuModifier.swift
+++ b/damus/Views/Images/ImageContextMenuModifier.swift
@@ -12,8 +12,16 @@ import UIKit
struct ImageContextMenuModifier: ViewModifier {
let url: URL?
let image: UIImage?
+ let settings: UserSettingsStore
+
+ @State var qrCodeLink: String = ""
+ @State var open_link_confirm: Bool = false
+ @State var no_link_found: Bool = false
+
@binding var showShareSheet: Bool
+ @Environment(\.openURL) var openURL
+
func body(content: Content) -> some View {
return content.contextMenu {
Button {
@@ -32,6 +40,35 @@ struct ImageContextMenuModifier: ViewModifier {
} label: {
Label(NSLocalizedString("Save Image", comment: "Context menu option to save an image."), image: "download")
}
+ Button {
+ qrCodeLink = ""
+ guard let detector:CIDetector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh]) else {
+ return
+ }
+ guard let ciImage = CIImage(image:someImage) else {
+ return
+ }
+ let features = detector.features(in: ciImage)
+ if let qrfeatures = features as? [CIQRCodeFeature] {
+ for feature in qrfeatures {
+ if let msgStr = feature.messageString {
+ qrCodeLink += msgStr
+ }
+ }
+ }
+
+ if qrCodeLink == "" {
+ no_link_found.toggle()
+ } else {
+ if qrCodeLink.contains("lnurl") {
+ open_with_wallet(wallet: settings.default_wallet.model, invoice: qrCodeLink)
+ } else if let _ = URL(string: qrCodeLink) {
+ open_link_confirm.toggle()
+ }
+ }
+ } label: {
+ Label(NSLocalizedString("Scan for QR Code", comment: "Context menu option to scan image for a QR Code."), image: "qr-code.fill")
+ }
}
Button {
showShareSheet = true
@@ -39,5 +76,16 @@ struct ImageContextMenuModifier: ViewModifier {
Label(NSLocalizedString("Share", comment: "Button to share an image."), image: "upload")
}
}
+ .alert(NSLocalizedString("Found \(qrCodeLink).\nOpen link?", comment: "Alert message asking if the user wants to open the link."), isPresented: $open_link_confirm) {
+ Button(NSLocalizedString("Open", comment: "Button to proceed with opening link."), role: .none) {
+ if let url = URL(string: qrCodeLink) {
+ openURL(url)
+ }
+ }
+ Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {}
+ }
+ .alert(NSLocalizedString("Unable to find a QR Code", comment: "Alert message letting user know a link was not found."), isPresented: $no_link_found) {
+ Button(NSLocalizedString("Dismiss", comment: "Button to dismiss alert"), role: .cancel) {}
+ }
}
}
diff --git a/damus/Views/Images/ImageView.swift b/damus/Views/Images/ImageView.swift
index efc797d5f..f8509e209 100644
--- a/damus/Views/Images/ImageView.swift
+++ b/damus/Views/Images/ImageView.swift
@@ -16,7 +16,7 @@ struct ImageView: View {
@State private var selectedIndex = 0
@State var showMenu = true
- let disable_animation: Bool
+ let settings: UserSettingsStore
var tabViewIndicator: some View {
HStack(spacing: 10) {
@@ -42,7 +42,7 @@ struct ImageView: View {
TabView(selection: $selectedIndex) {
ForEach(urls.indices, id: \.self) { index in
ZoomableScrollView {
- ImageContainerView(video_controller: video_controller, url: urls[index], disable_animation: disable_animation)
+ ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
@@ -85,6 +85,6 @@ struct ImageView: View {
struct ImageView_Previews: PreviewProvider {
static var previews: some View {
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
- ImageView(video_controller: test_damus_state.video, urls: [url], disable_animation: false)
+ ImageView(video_controller: test_damus_state.video, urls: [url], settings: test_damus_state.settings)
}
}
diff --git a/damus/Views/Images/ProfilePicImageView.swift b/damus/Views/Images/ProfilePicImageView.swift
index d36c181ee..b900813d5 100644
--- a/damus/Views/Images/ProfilePicImageView.swift
+++ b/damus/Views/Images/ProfilePicImageView.swift
@@ -9,12 +9,11 @@ import Kingfisher
struct ProfileImageContainerView: View {
let url: URL?
+ let settings: UserSettingsStore
@State private var image: UIImage?
@State private var showShareSheet = false
- let disable_animation: Bool
-
private struct ImageHandler: ImageModifier {
@binding var handler: UIImage?
@@ -27,13 +26,13 @@ struct ProfileImageContainerView: View {
var body: some View {
KFAnimatedImage(url)
- .imageContext(.pfp, disable_animation: disable_animation)
+ .imageContext(.pfp, disable_animation: settings.disable_animation)
.configure { view in
view.framePreloadCount = 3
}
.imageModifier(ImageHandler(handler: $image))
.clipShape(Circle())
- .modifier(ImageContextMenuModifier(url: url, image: image, showShareSheet: $showShareSheet))
+ .modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
.sheet(isPresented: $showShareSheet) {
ShareSheet(activityItems: [url])
}
@@ -64,7 +63,7 @@ struct NavDismissBarView: View {
struct ProfilePicImageView: View {
let pubkey: Pubkey
let profiles: Profiles
- let disable_animation: Bool
+ let settings: UserSettingsStore
@Environment(\.presentationMode) var presentationMode
@@ -74,7 +73,7 @@ struct ProfilePicImageView: View {
.ignoresSafeArea()
ZoomableScrollView {
- ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), disable_animation: disable_animation)
+ ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), settings: settings)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
@@ -94,7 +93,7 @@ struct ProfileZoomView_Previews: PreviewProvider {
ProfilePicImageView(
pubkey: test_pubkey,
profiles: make_preview_profiles(test_pubkey),
- disable_animation: false
+ settings: test_damus_state.settings
)
}
}
diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift
index 705a59a01..82ac00387 100644
--- a/damus/Views/Profile/ProfileView.swift
+++ b/damus/Views/Profile/ProfileView.swift
@@ -322,7 +322,7 @@ struct ProfileView: View {
is_zoomed.toggle()
}
.fullScreenCover(isPresented: $is_zoomed) {
- ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation)
+ ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, settings: damus_state.settings)
}
Spacer()
|
Merged in 5d90b49
Thanks!
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR'd this again cause it was just easier than figuring out my git issues.
This PR allows users to open the link in a QR Code if it exists. Detects if there is a qr code and extracts that info, if it is an lnurl it'll append the lightning prefix so it can be opened by a lightning wallet. If it is a regular link it'll open a dialog to ask the user if they want to open the link, with the link displayed. If there is no link it show a dialog that says no qr code found.
See these notes for video examples:
https://damus.io/note1mpc6y8ft80wpavmedsy7h08s7n2l95flm0d3tlqd6hfdd27ta38s4rusrj
https://damus.io/note1dw9y7lc09f3694avg2z2a82kc68yh479vkkur336g78w9svh3tfsp0yy5g