Skip to content

Commit

Permalink
Merge pull request #21 from yale-swe/tracy_dev
Browse files Browse the repository at this point in the history
implement screenshot, bubble v2, more frontend styling
  • Loading branch information
sophiayk20 authored Dec 7, 2023
2 parents 46b5c23 + 9458027 commit a93a5e4
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 54 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified app/.DS_Store
Binary file not shown.
Binary file modified app/newHere1/.DS_Store
Binary file not shown.
49 changes: 40 additions & 9 deletions app/newHere1/newHere.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
158392332AFC72F3007A53C7 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 158392322AFC72F3007A53C7 /* LoginView.swift */; };
158392352AFC730B007A53C7 /* Registration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 158392342AFC730B007A53C7 /* Registration.swift */; };
15F1CC9C2B05C36A00A34A19 /* LoginViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F1CC9B2B05C36A00A34A19 /* LoginViewTests.swift */; };
7194CFD42B2153D30094BE56 /* PhotoLibraryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7194CFD32B2153D30094BE56 /* PhotoLibraryManager.swift */; };
7194CFD62B2153DA0094BE56 /* ScreenshotUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7194CFD52B2153DA0094BE56 /* ScreenshotUtility.swift */; };
7194CFDC2B2154740094BE56 /* ShareSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7194CFDB2B2154740094BE56 /* ShareSheet.swift */; };
71D79DA22B1570E4009A054C /* BubbleAnimation.atlas in Resources */ = {isa = PBXBuildFile; fileRef = 71D79DA12B1570E4009A054C /* BubbleAnimation.atlas */; };
FE32AC982B159A650056B003 /* PostTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE32AC972B159A650056B003 /* PostTest.swift */; };
FE32AC9A2B159A9E0056B003 /* MockMessageState.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE32AC992B159A9E0056B003 /* MockMessageState.swift */; };
Expand Down Expand Up @@ -83,6 +86,9 @@
158392322AFC72F3007A53C7 /* LoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
158392342AFC730B007A53C7 /* Registration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Registration.swift; sourceTree = "<group>"; };
15F1CC9B2B05C36A00A34A19 /* LoginViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewTests.swift; sourceTree = "<group>"; };
7194CFD32B2153D30094BE56 /* PhotoLibraryManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoLibraryManager.swift; sourceTree = "<group>"; };
7194CFD52B2153DA0094BE56 /* ScreenshotUtility.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScreenshotUtility.swift; sourceTree = "<group>"; };
7194CFDB2B2154740094BE56 /* ShareSheet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareSheet.swift; sourceTree = "<group>"; };
71D79DA12B1570E4009A054C /* BubbleAnimation.atlas */ = {isa = PBXFileReference; lastKnownFileType = folder.skatlas; path = BubbleAnimation.atlas; sourceTree = "<group>"; };
FE32AC972B159A650056B003 /* PostTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PostTest.swift; path = newHereTests/PostTest.swift; sourceTree = SOURCE_ROOT; };
FE32AC992B159A9E0056B003 /* MockMessageState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMessageState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -191,6 +197,14 @@
path = newHereUITests;
sourceTree = "<group>";
};
7194CFDA2B21546C0094BE56 /* ShareSheet */ = {
isa = PBXGroup;
children = (
7194CFDB2B2154740094BE56 /* ShareSheet.swift */,
);
path = ShareSheet;
sourceTree = "<group>";
};
71D79DA42B15757E009A054C /* Home */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -226,6 +240,7 @@
71D79DA82B15767C009A054C /* Views */ = {
isa = PBXGroup;
children = (
7194CFDA2B21546C0094BE56 /* ShareSheet */,
71D79DAE2B15793E009A054C /* FriendsView */,
71D79DAC2B157721009A054C /* ARView */,
1531A8DF2AED95FD009F644E /* ContentView.swift */,
Expand Down Expand Up @@ -258,6 +273,8 @@
71D79DAB2B1576DA009A054C /* Utils */ = {
isa = PBXGroup;
children = (
7194CFD32B2153D30094BE56 /* PhotoLibraryManager.swift */,
7194CFD52B2153DA0094BE56 /* ScreenshotUtility.swift */,
1583922C2AFC72CF007A53C7 /* api_call.swift */,
);
path = Utils;
Expand Down Expand Up @@ -454,10 +471,13 @@
1531A8E02AED95FD009F644E /* ContentView.swift in Sources */,
158392352AFC730B007A53C7 /* Registration.swift in Sources */,
1531A90B2AED964A009F644E /* Profile.swift in Sources */,
7194CFDC2B2154740094BE56 /* ShareSheet.swift in Sources */,
7194CFD62B2153DA0094BE56 /* ScreenshotUtility.swift in Sources */,
15582E392AFB2659003910A2 /* Friends.swift in Sources */,
1583922D2AFC72CF007A53C7 /* api_call.swift in Sources */,
1531A90D2AED9663009F644E /* Messages.swift in Sources */,
158392302AFC72D3007A53C7 /* CustomARViewRepresentable.swift in Sources */,
7194CFD42B2153D30094BE56 /* PhotoLibraryManager.swift in Sources */,
1531A90F2AED9917009F644E /* Post.swift in Sources */,
1531A9152AEDCADB009F644E /* Message.swift in Sources */,
1531A9092AED9618009F644E /* Home.swift in Sources */,
Expand Down Expand Up @@ -648,7 +668,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"newHere/Preview Content\"";
DEVELOPMENT_TEAM = A7X36A78B2;
DEVELOPMENT_TEAM = W23Y365YR7;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -675,7 +695,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -689,10 +709,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = newHere/newHere.entitlements;
CODE_SIGN_STYLE = Manual;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"newHere/Preview Content\"";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = W23Y365YR7;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -719,7 +740,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -746,7 +767,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.eric.newHereTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -771,7 +793,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.eric.newHereTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -795,7 +818,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.eric.newHereUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -817,7 +841,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.eric.newHereUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -839,6 +864,9 @@
PRODUCT_BUNDLE_IDENTIFIER = "here.newHereTests-v2";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
Expand All @@ -861,6 +889,9 @@
PRODUCT_BUNDLE_IDENTIFIER = "here.newHereTests-v2";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
Expand Down
47 changes: 47 additions & 0 deletions app/newHere1/newHere/Utils/PhotoLibraryManager.swift
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")
}
}
}

16 changes: 16 additions & 0 deletions app/newHere1/newHere/Utils/ScreenshotUtility.swift
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)
}
}

49 changes: 49 additions & 0 deletions app/newHere1/newHere/Utils/api_call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,56 @@ func getFilteredMessages(userId: String, location: CLLocation, friendList: [Stri
}
}

func updateMetrics(completion: @escaping (Result<Bool, Error>) -> Void) {
let urlString = "https://here-swe.vercel.app/metrics/increment-clicks"

// URL validation
guard let url = URL(string: urlString) else {
completion(.failure(URLError(.badURL)))
return
}

// Setup request
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue(apiKey, forHTTPHeaderField: "X-API-Key")

// Prepare request body
let requestBody = ["metricsName": "metric-screenshot-icon3"]
do {
request.httpBody = try JSONSerialization.data(withJSONObject: requestBody, options: [])
} catch {
completion(.failure(error))
return
}

// Send request
let task = URLSession.shared.dataTask(with: request) { data, response, error in
// Check for errors
if let error = error {
completion(.failure(error))
return
}

// Check for valid HTTP response
guard let httpResponse = response as? HTTPURLResponse else {
completion(.failure(URLError(.badServerResponse)))
return
}

// Check for successful status code
guard (200...299).contains(httpResponse.statusCode) else {
completion(.failure(URLError(.badServerResponse)))
return
}

// Success
completion(.success(true))
}

task.resume()
}
//getAllUserFriends(userId: <#T##String#>, completion: <#T##(Result<[String : String], Error>) -> Void#>) { friendsList in
// guard let friendsList = friendsList else {
// print("Failed to fetch friends list.")
Expand Down
24 changes: 14 additions & 10 deletions app/newHere1/newHere/Views/FriendsView/Friends.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ struct Friends: View {
Button(action: {
isPresented.toggle() // Close the popup
}) {
Text("Close")
.font(.headline)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
Image(systemName: "xmark.circle")
.font(.system(size: 28))
.foregroundColor(Color.white)
.shadow(radius: 2.0)
}
.padding(.trailing, 20) // Adjust the position of the close button
}
}.padding(.vertical, 8)

// search bar and add friend button
HStack {
Expand Down Expand Up @@ -93,7 +91,7 @@ struct Friends: View {
Text("Add Friend")
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(Color.blue)
.background(Color.white.opacity(0.5))
.foregroundColor(.white)
.cornerRadius(8)
}
Expand Down Expand Up @@ -134,17 +132,22 @@ struct Friends: View {
}
}){
Image(systemName: "minus.circle")
.font(.system(size: 28))
.foregroundColor(Color.gray)
}
}
}
}.background(Color.gray)
}
}
.frame(width: 350, height: 600)
.padding(.top, 10)
.padding(.bottom, 10)
.onAppear {
// Fetch Friends List on Appear
getAllUserFriends(userId: userId) { result in
switch result {
case .success(let response):
print("Friends fetched successfully: \(response)")
print("Friends fetched successfully: \(response)")
self.friendsList = response.values.map { $0 }

case .failure(let error):
Expand All @@ -158,3 +161,4 @@ struct Friends: View {

// Make sure `getAllUserFriends` has a signature similar to this:
// func getAllUserFriends(userId: String, completion: @escaping (Result<[String], Error>) -> Void)

Loading

0 comments on commit a93a5e4

Please sign in to comment.