Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
lexypaul13 committed Mar 27, 2021
1 parent 876084a commit 8f7dcf9
Show file tree
Hide file tree
Showing 12 changed files with 870 additions and 32 deletions.
180 changes: 175 additions & 5 deletions Instagram Clone.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>Instagram Clone.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>9</integer>
</dict>
</dict>
</dict>
Expand Down
17 changes: 16 additions & 1 deletion Instagram Clone/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@
//

import UIKit

import Parse
@main
class AppDelegate: UIResponder, UIApplicationDelegate {


var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Parse.initialize(with: ParseClientConfiguration(block: { (configuration: ParseMutableClientConfiguration) in
configuration.applicationId = "CpPfypBNGum7YmGM2PpKYBcRH6KiZby4xEvu8Vbx"
configuration.clientKey = "imNdVKZjsY4hFTOkGETUb5nRuo3Bl3sDfDEtisYo"
configuration.server = "https://parseapi.back4app.com/"
}))


if PFUser.current() != nil{
let main = UIStoryboard(name: "Main", bundle: nil)
let feedNavigationController = main.instantiateViewController(withIdentifier: "FeedNavigationController")

window?.rootViewController = feedNavigationController
}

return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "instagram_logo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
313 changes: 307 additions & 6 deletions Instagram Clone/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions Instagram Clone/CameraViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// CameraViewController.swift
// Instagram Clone
//
// Created by Alex Paul on 3/26/21.
//

import UIKit
import Parse
import AlamofireImage
class CameraViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var imageView: UIImageView!

@IBOutlet weak var commentTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

@IBAction func onSubmit(_ sender: Any) {
let post = PFObject(className: "Parstagram")

post["caption"] = commentTextField.text!
post["author"] = PFUser.current()!

let imageData = imageView.image!.pngData()
let file = PFFileObject(data: imageData!)

post["image"] = file

post.saveInBackground{ (success,error) in
if success {
self.dismiss(animated: true, completion: nil)
print("Saved!")
}else{
print("Error!")
}

}


}

@IBAction func cameraButton(_ sender: Any) {
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = true

if UIImagePickerController.isSourceTypeAvailable(.camera){
picker.sourceType = .camera
}else{
picker.sourceType = .photoLibrary
}
present(picker,animated: true,completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[.editedImage] as! UIImage
let size = CGSize(width: 300, height: 300)
let scaledImage = image.af_imageScaled(to: size)
imageView.image = scaledImage
dismiss(animated: true, completion: nil)

}

}
25 changes: 25 additions & 0 deletions Instagram Clone/CommentTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CommentTableViewCell.swift
// Instagram Clone
//
// Created by Alex Paul on 3/27/21.
//

import UIKit

class CommentTableViewCell: UITableViewCell {

@IBOutlet weak var name: UILabel!
@IBOutlet weak var comment: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}
162 changes: 162 additions & 0 deletions Instagram Clone/FeedViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
//
// FeedViewController.swift
// Instagram Clone
//
// Created by Alex Paul on 3/25/21.
//

import UIKit
import Parse
import MessageInputBar
class FeedViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MessageInputBarDelegate {

let commentBar = MessageInputBar()
var posts = [PFObject]()
var selectedPost:PFObject!
var showComments = false

@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
commentBar.inputTextView.placeholder = "Add a comment..."
commentBar.sendButton.title = "Post"
commentBar.delegate = self

tableView.delegate = self
tableView.dataSource = self
tableView.keyboardDismissMode = .interactive
let center = NotificationCenter.default
center.addObserver(self, selector: #selector(keyboardWillBeHidden(note:)), name: UIResponder.keyboardWillHideNotification, object: nil)
// Do any additional setup after loading the view.
}
@objc func keyboardWillBeHidden(note: Notification) {
commentBar.inputTextView.text = nil
showComments = false; becomeFirstResponder()

}

override var inputAccessoryView: UIView? {
return commentBar
}

override var canBecomeFirstResponder: Bool {
return showComments
}



override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let query = PFQuery(className: "Parstagram")
query.includeKeys(["author", "comments", "comments.author"])
query.limit = 20
query.findObjectsInBackground { (posts, error) in
if posts != nil {
self.posts = posts!
self.tableView.reloadData()
}
}

}
func messageInputBar(_ inputBar: MessageInputBar, didPressSendButtonWith text: String) {
let comment = PFObject(className: "Comments")
comment["text"] = text
comment["post"] = selectedPost
comment["author"] = PFUser.current()!

selectedPost.add(comment, forKey: "comments")

selectedPost.saveInBackground { (success, error) in
if success{
print("comment saved")
} else {
print("Error saving comment")
}
}

tableView.reloadData()
commentBar.inputTextView.text = nil
showComments = false
becomeFirstResponder()
commentBar.inputTextView.resignFirstResponder()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let post = posts[section]
let comments = (post["comments"]as? [PFObject]) ?? []

return comments.count+1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
let comments = (post["comments"]as? [PFObject]) ?? []
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "postCell") as! PostTableViewCell
let user = post["author"] as! PFUser
cell.userName.text = user.username
cell.captionLabel.text = post["caption"] as? String
let imageFile = post["image"] as! PFFileObject
let urlString = imageFile.url!
let url = URL(string: urlString)!
cell.pictures.af_setImage(withURL: url)
return cell
}
else if indexPath.row <= comments.count {
let cell = tableView.dequeueReusableCell(withIdentifier: "CommentCell") as! CommentTableViewCell
let comment = comments[indexPath.row - 1]
cell.comment.text = comment["text"] as? String
let user = comment["author"] as! PFUser
cell.name.text = user.username
return cell

} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "AddCommentCell")!

return cell
}

}

func numberOfSections(in tableView: UITableView) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let post = posts[indexPath.row]
let comment = (post["comments"] as? [PFObject]) ?? []

if indexPath.row == comment.count + 1{
showComments = true
becomeFirstResponder()
commentBar.inputTextView.becomeFirstResponder()
selectedPost = post
}
// comment["text"] = "This is a random"
// comment["post"] = post
// comment["author"] = PFUser.current()!
//
// post.add(comment, forKey: "comments")
// post.saveInBackground { (succes, error) in
// if succes{
// print("Comment saved")
// }
// else{
// print("Error saved")
//
// }
// }

}

@IBAction func logOut(_ sender: Any) {
PFUser.logOut()
let main = UIStoryboard(name: "Main", bundle: nil)
let loginViewController = main.instantiateViewController(identifier: "LoginViewController")
let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.window?.rootViewController = loginViewController

}



}
67 changes: 67 additions & 0 deletions Instagram Clone/LoginViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// LoginViewController.swift
// Instagram Clone
//
// Created by Alex Paul on 3/25/21.
//

import UIKit
import Parse

class LoginViewController: UIViewController {

@IBOutlet weak var userNameField: UITextField!
@IBOutlet weak var passwordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

@IBAction func signUp(_ sender: Any) {
let user = PFUser()
user.username = userNameField.text
user.password = passwordField.text

user.signUpInBackground{(success,error) in
if success{
self.performSegue(withIdentifier: "loginSegue", sender: nil)
}else{
print("Error: \(error?.localizedDescription)")
}


}
}

@IBAction func signIn(_ sender: Any) {
let username = userNameField.text!
let password = passwordField.text!

PFUser.logInWithUsername(inBackground: username, password: password){
(user,error) in
if user != nil{
self.performSegue(withIdentifier: "loginSegue", sender: nil)

}else{
print("Error: \(error?.localizedDescription)")

}
}


}



/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/

}
Loading

0 comments on commit 8f7dcf9

Please sign in to comment.