-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from yale-swe/tracy_dev
implement screenshot, bubble v2, more frontend styling
- Loading branch information
Showing
12 changed files
with
303 additions
and
54 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// PhotoLibraryManager.swift | ||
// newHere | ||
// | ||
// Created by TRACY LI on 2023/12/2. | ||
// | ||
|
||
import UIKit | ||
import Photos | ||
|
||
class ImageSaver: NSObject { | ||
var completion: ((Bool, Error?) -> Void)? | ||
|
||
func saveImageToAlbum(image: UIImage, completion: @escaping (Bool, Error?) -> Void) { | ||
self.completion = completion | ||
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil) | ||
} | ||
|
||
@objc private func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { | ||
if let error = error { | ||
completion?(false, error) | ||
} else { | ||
completion?(true, nil) | ||
} | ||
} | ||
} | ||
|
||
struct PhotoLibraryManager { | ||
static func checkPhotoLibraryPermission(completion: @escaping (Bool) -> Void) { | ||
let status = PHPhotoLibrary.authorizationStatus() | ||
switch status { | ||
case .authorized: | ||
completion(true) | ||
case .denied, .restricted: | ||
completion(false) | ||
case .notDetermined: | ||
PHPhotoLibrary.requestAuthorization { newStatus in | ||
DispatchQueue.main.async { | ||
completion(newStatus == .authorized) | ||
} | ||
} | ||
@unknown default: | ||
fatalError("Unknown photo library authorization status") | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// ScreenshotUtility.swift | ||
// newHere | ||
// | ||
// Created by TRACY LI on 2023/12/2. | ||
// | ||
|
||
import UIKit | ||
|
||
func captureScreenshot(of view: UIView) -> UIImage? { | ||
let renderer = UIGraphicsImageRenderer(size: view.bounds.size) | ||
return renderer.image { ctx in | ||
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true) | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.