Skip to content

Commit

Permalink
✨ Feature: Settings stuff (Not auth related)
Browse files Browse the repository at this point in the history
  • Loading branch information
N3v1 committed Nov 4, 2023
1 parent 867cf92 commit 9e94596
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 54 deletions.
34 changes: 17 additions & 17 deletions ScribbleLab.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@
38AE9CB12AD0751100B761E8 /* ScribbleLabTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38AE9CB02AD0751100B761E8 /* ScribbleLabTests.swift */; };
38AE9CBB2AD0751100B761E8 /* ScribbleLabUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38AE9CBA2AD0751100B761E8 /* ScribbleLabUITests.swift */; };
38AE9CBD2AD0751100B761E8 /* ScribbleLabUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38AE9CBC2AD0751100B761E8 /* ScribbleLabUITestsLaunchTests.swift */; };
38D56F062AF59A0000CE3781 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D56F052AF59A0000CE3781 /* ImagePicker.swift */; };
38D5C68B2AD28B9D00D943A5 /* SLDarkmodeSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D5C68A2AD28B9D00D943A5 /* SLDarkmodeSettingsView.swift */; };
38D5C68D2AD28D6F00D943A5 /* SLUpdateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D5C68C2AD28D6F00D943A5 /* SLUpdateView.swift */; };
38D5C6952AD2CAA100D943A5 /* SLContributorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D5C6942AD2CAA100D943A5 /* SLContributorModel.swift */; };
38D5C6972AD2CC6200D943A5 /* SLContributorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38D5C6962AD2CC6200D943A5 /* SLContributorView.swift */; };
38E304702AF639F300103D71 /* Crop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E3046F2AF639F300103D71 /* Crop.swift */; };
38E5BBB42AE41F2900FFFE7C /* Updates in Frameworks */ = {isa = PBXBuildFile; productRef = 38E5BBB32AE41F2900FFFE7C /* Updates */; };
38E5BBB72AE4244600FFFE7C /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E5BBB62AE4244600FFFE7C /* User.swift */; };
38EFBE1D2AD6965C00CF0ECD /* PackageLicense.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38EFBE1C2AD6965C00CF0ECD /* PackageLicense.swift */; };
Expand Down Expand Up @@ -258,10 +260,12 @@
38AE9CB62AD0751100B761E8 /* ScribbleLabUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ScribbleLabUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
38AE9CBA2AD0751100B761E8 /* ScribbleLabUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScribbleLabUITests.swift; sourceTree = "<group>"; };
38AE9CBC2AD0751100B761E8 /* ScribbleLabUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScribbleLabUITestsLaunchTests.swift; sourceTree = "<group>"; };
38D56F052AF59A0000CE3781 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
38D5C68A2AD28B9D00D943A5 /* SLDarkmodeSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SLDarkmodeSettingsView.swift; sourceTree = "<group>"; };
38D5C68C2AD28D6F00D943A5 /* SLUpdateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SLUpdateView.swift; sourceTree = "<group>"; };
38D5C6942AD2CAA100D943A5 /* SLContributorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SLContributorModel.swift; sourceTree = "<group>"; };
38D5C6962AD2CC6200D943A5 /* SLContributorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SLContributorView.swift; sourceTree = "<group>"; };
38E3046F2AF639F300103D71 /* Crop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Crop.swift; sourceTree = "<group>"; };
38E5BBB62AE4244600FFFE7C /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
38EFBE1C2AD6965C00CF0ECD /* PackageLicense.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageLicense.swift; sourceTree = "<group>"; };
38EFBE1F2AD6D1A400CF0ECD /* RedemtionSheetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedemtionSheetView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -432,21 +436,6 @@
path = Tags;
sourceTree = "<group>";
};
3836C2972AF1BB69008F475F /* Model */ = {
isa = PBXGroup;
children = (
3836C2992AF1BB86008F475F /* EditProfileViewModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
3836C2982AF1BB75008F475F /* View */ = {
isa = PBXGroup;
children = (
);
path = View;
sourceTree = "<group>";
};
3836C2A02AF29CBF008F475F /* ScribbleLab AppClip */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -651,10 +640,9 @@
3868A3E12AD2FCC300D4CAEC /* Profile */ = {
isa = PBXGroup;
children = (
3836C2982AF1BB75008F475F /* View */,
3836C2972AF1BB69008F475F /* Model */,
3868A3E22AD2FE6600D4CAEC /* ProfileView.swift */,
38EFBE1F2AD6D1A400CF0ECD /* RedemtionSheetView.swift */,
38E3046F2AF639F300103D71 /* Crop.swift */,
);
path = Profile;
sourceTree = "<group>";
Expand Down Expand Up @@ -742,6 +730,7 @@
3886B2DC2AD19F2A002EF30E /* Model */ = {
isa = PBXGroup;
children = (
38D56F042AF599EA00CE3781 /* Profile */,
3889688A2AF143C700F67F08 /* SettingsViewModel.swift */,
);
path = Model;
Expand Down Expand Up @@ -835,6 +824,15 @@
path = ScribbleLabUITests;
sourceTree = "<group>";
};
38D56F042AF599EA00CE3781 /* Profile */ = {
isa = PBXGroup;
children = (
3836C2992AF1BB86008F475F /* EditProfileViewModel.swift */,
38D56F052AF59A0000CE3781 /* ImagePicker.swift */,
);
path = Profile;
sourceTree = "<group>";
};
38D5C67E2AD1C0FA00D943A5 /* Timer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1305,9 +1303,11 @@
38140A642AE3F6D200753FB6 /* LoginViewModel.swift in Sources */,
381F1F132AD72DD6001B3B10 /* TestView.swift in Sources */,
38140A622AE3F61000753FB6 /* SLAuthService.swift in Sources */,
38E304702AF639F300103D71 /* Crop.swift in Sources */,
38A24C712AED15B600F81F07 /* ImageUploader.swift in Sources */,
382520E52AEE678A002ECED2 /* OTPTextField.swift in Sources */,
38FFF9452AE3CA6F006719E2 /* Application_utility.swift in Sources */,
38D56F062AF59A0000CE3781 /* ImagePicker.swift in Sources */,
3868A3E02AD2E2F800D4CAEC /* SLLicenseView.swift in Sources */,
38D5C6972AD2CC6200D943A5 /* SLContributorView.swift in Sources */,
38140A6C2AE3FB6F00753FB6 /* ContentViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<key>text-context</key>
<dict>
<key>focused</key>
<string> .environmentObject(RegistrationViewModel())
<string>// .environmentObject(RegistrationViewModel())
</string>
<key>leading</key>
<string> .environmentObject(ContentViewModel())
// SignUpView()
//</string>
</string>
<key>trailing</key>
<string>// .environmentObject(SignInWithGoogleModel())
.preferredColorScheme(isDarkMode ? .dark : .light)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<key>ScribbleLab AppClip.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>6</integer>
<integer>3</integer>
</dict>
<key>ScribbleLab-WidgetsExtension.xcscheme_^#shared#^_</key>
<dict>
Expand Down
10 changes: 9 additions & 1 deletion ScribbleLab/App/ScribbleLabApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI
import FirebaseCore
import GoogleSignIn

/// An App Delegate that is responsible for the Firebase configuration and GIDSignIn
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
Expand All @@ -29,7 +30,14 @@ struct ScribbleLabApp: App {
// register app delegate for Firebase setup
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

// Check if darkmode is enabled
// Check if darkmode is enabled:
/// A property of type Boolean that stores a boolean value that indicates the current state of the applications color scheme
/// Possible values:
/// - false: Dark mode isn't enabled
/// - true: Dark mode is enabled
///
/// To call the darkmode state add the @AppStorage property at the top in your Struct
/// then call the declared isDarkMode argument.
@AppStorage("isDarkMode") private var isDarkMode = false

var body: some Scene {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import Firebase

@MainActor
class EditProfileViewModel: ObservableObject {

}
35 changes: 35 additions & 0 deletions ScribbleLab/Core/Settings/Model/Profile/ImagePicker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ImagePicker.swift
// ScribbleLab
//
// Created by Nevio Hirani on 03.11.23.
//

import SwiftUI
import PhotosUI

@MainActor
class ImagePicker: ObservableObject {
@Published var image: Image?
@Published var imageSelection: PhotosPickerItem? {
didSet {
if let imageSelection {
Task { try await loadTransferable(from: imageSelection) }
}
}
}

func loadTransferable(from imageSelection: PhotosPickerItem?) async throws {
print("DEBUG: \(Image.transferRepresentation)")
do {
if let data = try await imageSelection?.loadTransferable(type: Data.self) {
if let uiImage = UIImage(data: data) {
self.image = Image(uiImage: uiImage)
}
}
} catch {
print("DEBUG: Profile picture selection and loading failed with error:\(error.localizedDescription)")
image = nil
}
}
}
4 changes: 4 additions & 0 deletions ScribbleLab/Core/Settings/Model/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import Foundation

/// A Class that is responsible for all general setting options:
/// Tasks:
/// - Fetch the user's account data (Username, Email, Password)
/// - Store those data in ProfileViewModel
class SettingsViewModel: ObservableObject {
func fetchUser() async throws {
try await SLAuthService.shared.loadUserData()
Expand Down
57 changes: 57 additions & 0 deletions ScribbleLab/Core/Settings/View/Profile/Crop.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// CropView.swift
// ScribbleLab
//
// Created by Nevio Hirani on 04.11.23.
// Copyright © 2023 - 2024 ScribbleLabApp. All rights reserved.
// Restricted use for ScribbleLab only.
//

import SwiftUI

// MARK: Crop config
/// An enum that is used for croping images and has 4 diffrent cases:
/// - Circle: Circular cropping **for Profile Images**
/// - Rectangle: For Rectangular cropping e.g. normal img in the editor, ...
/// - square: For squareable cropping
/// - custom: A CGSize is needed to use this case
///
/// In order to use the custom modifier you have to declare cGSize as a let first:
/// ```swift
/// switch self {
/// case .custom(let cGSize):
/// }
/// ```
///
/// The enum is reusable and can be used everywhere in this application where you work with ImagePickerItems.
///
/// The crop config enum uses two functions:
/// - ```name()```
/// - ```size()```
///
enum Crop: Equatable {
case circle
case rectangle
case square
case custom(CGSize)

/// A function that returns a String value which contains the name of the case which will be displayed in an action everytime you select an image.
func name() -> String {
switch self {
case .circle: return "Cricle"
case .rectangle: return "Rectangle"
case .square: return "Square"
case .custom(let cGSize): return "Custom \(Int(cGSize.width)) x \(Int(cGSize.height))"
}
}

/// A function that returns a CGSize value which contains the size of the case. It's needed for the actual cropping of the image
func size() -> CGSize {
switch self {
case .circle: return .init(width: 150, height: 150)
case .rectangle: return .init(width: 300, height: 500)
case .square: return.init(width: 300, height: 300)
case .custom(let cGSize): return cGSize
}
}
}
80 changes: 60 additions & 20 deletions ScribbleLab/Core/Settings/View/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,71 @@ import SwiftUI
import PhotosUI

struct ProfileView: View {
/// - View Properties
@StateObject var imagePicker = ImagePicker()

/// - Action Properties:
@State private var signOutWarningIsPresented = false

var body: some View {
NavigationStack {
Text("Hello TEST USER")
.navigationTitle("Profile")
.navigationBarTitleDisplayMode(.inline)

List {
Section {
Button {
signOutWarningIsPresented.toggle()
} label: {
Text("Sign Out")
.foregroundStyle(.red)
}
.alert(isPresented: $signOutWarningIsPresented) {
Alert(title: Text("Important message"), message: Text("Do you really want to sign out? You'll be not able to use this app without signing in"), primaryButton: .default(Text("Cancel"), action: {}), secondaryButton: .destructive(Text("Confirm").fontWeight(.semibold), action: {
// TODO: Call the to factory setting func
SLAuthService.shared.signOut()
}))
VStack {
// MARK: Profile headder
VStack {
PhotosPicker(selection: $imagePicker.imageSelection, matching: .images, photoLibrary: .shared()) {
if let image = imagePicker.image {
image
.resizable()
.scaledToFill()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
} else {
Image(systemName: "person.circle.fill")
.resizable()
.scaledToFill()
.frame(width: 150, height: 150)
.clipShape(Circle())
.padding()
}
} header: {

} footer: {
}
Text("Test User")
.font(.title2).bold()

Text("test@gmail.com")
.tint(Color(.darkGray))
}

// MARK: Options
// List {
// Section {
// Button {
// signOutWarningIsPresented.toggle()
// } label: {
// Text("Sign Out")
// .foregroundStyle(.red)
// }
// .alert(isPresented: $signOutWarningIsPresented) {
// Alert(title: Text("Important message"), message: Text("Do you really want to sign out? You'll be not able to use this app without signing in"), primaryButton: .default(Text("Cancel"), action: {}), secondaryButton: .destructive(Text("Confirm").fontWeight(.semibold), action: {
// // TODO: Call the to factory setting func
// SLAuthService.shared.signOut()
// }))
// }
// } header: {
//
// } footer: {
//
// }
// }
}
.navigationTitle("Profile")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Edit") {

}
.tint(.black).bold()
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions ScribbleLab/Core/Tour/TourViewBeginning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import SwiftUI
struct TourViewBeginning: View {
var body: some View {
NavigationStack {
Text("Welcome to Scribble Lab")
.navigationTitle("Get started with Scribble Lab")
.navigationBarTitleDisplayMode(.inline)
VStack {
Text("Welcome to Scribble Lab")
}
.navigationTitle("Get started with Scribble Lab")
.navigationBarTitleDisplayMode(.inline)
}
}
}
Expand Down
Loading

0 comments on commit 9e94596

Please sign in to comment.