-
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.
- Loading branch information
1 parent
876084a
commit 8f7dcf9
Showing
12 changed files
with
870 additions
and
32 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
Instagram Clone/Assets.xcassets/instagram_logo.imageset/Contents.json
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,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "instagram_logo.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+4.33 KB
Instagram Clone/Assets.xcassets/instagram_logo.imageset/instagram_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,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) | ||
|
||
} | ||
|
||
} |
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,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 | ||
} | ||
|
||
} |
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,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 | ||
|
||
} | ||
|
||
|
||
|
||
} |
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,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. | ||
} | ||
*/ | ||
|
||
} |
Oops, something went wrong.