Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
af5cb93
Add firebase to project
juliaplatova Dec 4, 2021
4a1ab4c
Add task and user services
juliaplatova Dec 6, 2021
59e7e3e
Add fetching followers and following
juliaplatova Dec 6, 2021
727f102
Add image uploader && little fixes
juliaplatova Dec 6, 2021
a2589ad
Merge branch 'develop' into feature/network
rikine Dec 13, 2021
11eda69
A LOT OF CONFLICTS, CONFLICTS EVERYWHERE
rikine Dec 13, 2021
4972334
nothing
rikine Dec 14, 2021
acd9791
users vm
rikine Dec 14, 2021
0ef2a4b
fix profile image
rikine Dec 14, 2021
62f7191
nothing
danil-ivanov Dec 14, 2021
5272ac5
Merge branch 'feature/network' of https://github.com/DoIt-Project/DoI…
danil-ivanov Dec 14, 2021
ccf27fa
Add updating profile picture
juliaplatova Dec 14, 2021
f30241b
Add updating task image
juliaplatova Dec 14, 2021
4cc64c1
Network is done, but nothing works
juliaplatova Dec 14, 2021
8f43c36
Remove unnecessary file
juliaplatova Dec 14, 2021
1e714f8
Add extension that sets UIImage from URL
juliaplatova Dec 14, 2021
bf6e70b
fixes
juliaplatova Dec 14, 2021
1baee80
Add convertation hex -> color && color -> hex
juliaplatova Dec 15, 2021
05f647a
.
juliaplatova Dec 15, 2021
707ba89
Doinf viewmodels
danil-ivanov Dec 15, 2021
69346ff
Merge branch 'feature/network' of https://github.com/DoIt-Project/DoI…
danil-ivanov Dec 15, 2021
51fdd7e
signupviewmodel
danil-ivanov Dec 15, 2021
81296cf
change firebase and images download/upload
rikine Dec 15, 2021
2352899
Merge remote-tracking branch 'refs/remotes/origin/feature/network'
rikine Dec 15, 2021
9bb56a6
remove dynamic
rikine Dec 15, 2021
d1d5fcd
just something
danil-ivanov Dec 15, 2021
aa8ae79
Merge branch 'feature/network' of https://github.com/DoIt-Project/DoI…
danil-ivanov Dec 15, 2021
eb2ea88
Sign In Up works
danil-ivanov Dec 15, 2021
a53cb32
remove useless and image cacher
rikine Dec 15, 2021
e0adef0
add user name
rikine Dec 15, 2021
1f7b7b8
hotfix
juliaplatova Dec 15, 2021
b8fe2e6
fb fix
rikine Dec 15, 2021
b6b4dce
profile edit network
rikine Dec 16, 2021
f33757c
Merge pull request #14 from DoIt-Project/feature/network
blackplayerten Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 71 additions & 11 deletions DoIt.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions DoIt/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
//

import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
// Override point for customization after application launch.
return true
}
Expand Down
21 changes: 20 additions & 1 deletion DoIt/Extensions/UIColorsExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,23 @@ extension UIColor {
static let brown: UIColor = .brown
}
}

extension UIColor {

func ColorFromHex(rgbValue: Int) -> UIColor {
let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}

func HexFromColor(color: UIColor) -> Int {
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
color.getRed(&r, green: &g, blue: &b, alpha: &a)
let hex = (Int(r * 255) << 16) | (Int(g * 255) << 8) | (Int(g * 255))
return hex
}
}
1 change: 1 addition & 0 deletions DoIt/Extensions/UIImageExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import Firebase

extension UIImage {
struct AuthIcons {
Expand Down
36 changes: 36 additions & 0 deletions DoIt/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>562011549386-m8uaj5enlra65cq7qlrg3jk91mv66fk5.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.562011549386-m8uaj5enlra65cq7qlrg3jk91mv66fk5</string>
<key>API_KEY</key>
<string>AIzaSyC6JYyF7IDY-kw3AH9Hl6v9E4b7L7Gj-Is</string>
<key>GCM_SENDER_ID</key>
<string>562011549386</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.vkproj.doIt</string>
<key>PROJECT_ID</key>
<string>doit-b9c45</string>
<key>STORAGE_BUCKET</key>
<string>doit-b9c45.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false/>
<key>IS_ANALYTICS_ENABLED</key>
<false/>
<key>IS_APPINVITE_ENABLED</key>
<true/>
<key>IS_GCM_ENABLED</key>
<true/>
<key>IS_SIGNIN_ENABLED</key>
<true/>
<key>DATABASE_URL</key>
<string>https://doit-b9c45-default-rtdb.firebaseio.com/</string>
<key>GOOGLE_APP_ID</key>
<string>1:562011549386:ios:6fcfaa37eaad2ceab88e33</string>
</dict>
</plist>
2 changes: 2 additions & 0 deletions DoIt/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FirebaseAutomaticScreenReportingEnabled</key>
<false/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
40 changes: 40 additions & 0 deletions DoIt/Models/AuthResultsModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// AuthModel.swift
// DoIt
//
// Created by Y u l i a on 04.12.2021.
//

import Foundation
import Firebase

struct AuthCredentials {
let email: String
let password: String
let username: String
}

enum AuthError {
case invalidEmail
case unknownError
case serverError
}

extension AuthError: LocalizedError {
var errorDescription: String? {
switch self {
case .invalidEmail:
return NSLocalizedString("email_is_not_valid", comment: "")
case .unknownError:
return NSLocalizedString("server_error", comment: "")
case .serverError:
return NSLocalizedString("server_error", comment: "")

}
}
}

enum AuthResult {
case success
case failure(Error)
}
59 changes: 59 additions & 0 deletions DoIt/Models/AuthService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// AuthService.swift
// DoIt
//
// Created by Y u l i a on 06.12.2021.
//

import Firebase

final class AuthService {

static let shared = AuthService()

func signIn(email: String?, password: String?, completion: @escaping (AuthResult) -> Void) {
guard let email = email, let password = password else {
completion(.failure(AuthError.unknownError))
return
}

Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
guard let result = result else {
completion(.failure(error!))
return
}

let uid = result.user.uid

UserDefaults.standard.set(uid, forKey: "current_user")

completion(.success)
}
}

func signUp(email: String?, username: String?, password: String?, completion: @escaping (AuthResult) -> Void) {

guard let email = email, let username = username, let password = password else {
completion(.failure(AuthError.unknownError))
return
}

Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
guard let result = result else {
completion(.failure(error!))
return
}

let uid = result.user.uid

UserDefaults.standard.set(uid, forKey: "current_user")

let values = ["email": email,
"username": username]

let usersReferense = Database.database().reference().child("users")
usersReferense.child(uid).updateChildValues(values)
completion(.success)
}
}
}
22 changes: 22 additions & 0 deletions DoIt/Models/FirebaseConstants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FirebaseConstants.swift
// DoIt
//
// Created by Yulia on 04.12.2021.
//

import Firebase

let STORAGE_REF = Storage.storage().reference()

let STORAGE_PROFILE_IMAGES = STORAGE_REF.child("profile_images")
let STORAGE_TASK_IMAGES = STORAGE_REF.child("task_images")

let DB_REF = Database.database().reference()

let REF_USERS = DB_REF.child("users")
let REF_TASKS = DB_REF.child("tasks")
let REF_USER_TASKS = DB_REF.child("user-tasks")
let REF_USER_FOLLOWERS = DB_REF.child("user-followers")
let REF_USER_FOLLOWING = DB_REF.child("user-following")

40 changes: 40 additions & 0 deletions DoIt/Models/ImageChacher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// ImageChacher.swift
// DoIt
//
// Created by Шестаков Никита on 15.12.2021.
//

import Foundation
import UIKit

class ImageCache {
private let cache = NSCache<NSString, UIImage>()
private var observer: NSObjectProtocol?

static let shared = ImageCache()

private init() {
observer = NotificationCenter.default.addObserver(
forName: UIApplication.didReceiveMemoryWarningNotification,
object: nil, queue: nil) { [weak self] notification in
self?.cache.removeAllObjects()
}
}

deinit {
guard let observer = observer else {
return
}

NotificationCenter.default.removeObserver(observer)
}

func getImage(forKey key: String) -> UIImage? {
return cache.object(forKey: key as NSString)
}

func save(image: UIImage, forKey key: String) {
cache.setObject(image, forKey: key as NSString)
}
}
26 changes: 0 additions & 26 deletions DoIt/Models/Structures.swift

This file was deleted.

74 changes: 74 additions & 0 deletions DoIt/Models/TaskModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Structures.swift
// DoIt
//
// Created by Данил Иванов on 07.11.2021.
//

import UIKit
import Firebase

final class Task {
let taskId: String
let image: URL?
let title: String
let description: String?
let deadline: Date?
let isDone: Bool
let uid: String
let color: UIColor
let chapterId: Int
let creationTime: Date

var isMyTask: Bool {
return Auth.auth().currentUser?.uid == uid
}

init(id: String, dictionary: [String: AnyObject]) {
taskId = id
if let profileImageUrlString = dictionary["userPhotoUrl"] as? String {
image = URL(string: profileImageUrlString)
} else {
image = nil
}
title = dictionary["title"] as? String ?? ""
description = dictionary["description"] as? String ?? ""
if let deadlineTimestamp = dictionary["deadline"] as? Double {
deadline = Date(timeIntervalSince1970: deadlineTimestamp)
} else {
deadline = nil
}
isDone = dictionary["is_done"] as? Bool ?? false
uid = dictionary["uid"] as? String ?? ""
if let colorHex = dictionary["color"] as? Int {
color = UIColor().ColorFromHex(rgbValue: colorHex)
} else {
color = .clear
}
if let creationTimestamp = dictionary["timestamp"] as? Double {
creationTime = Date(timeIntervalSince1970: creationTimestamp)
} else {
creationTime = Date(timeIntervalSince1970: 0)
}
chapterId = dictionary["chapter_id"] as? Int ?? 0
}

// TODO: - FIX IT

// init(image: UIImage?, title: String, description: String?, deadline: Date?, isDone: Bool, color: UIColor, uid: String = "") {
// self.image = image
// self.title = title
// self.description = description
// self.deadline = deadline
// self.isDone = isDone
// self.uid = ""
// self.color = color
// self.creationTime = Date()
// self.chapterId = 0
// }
}

struct Chapter {
let title: String
let color: UIColor
}
Loading