Skip to content

Commit

Permalink
fixed some bugs in ChatVC
Browse files Browse the repository at this point in the history
  • Loading branch information
csujedihy committed Apr 26, 2016
1 parent 46faebc commit 03fd6ee
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dine/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand Down
23 changes: 17 additions & 6 deletions Dine/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class ChatViewController: UITableViewController, UIImagePickerControllerDelegate
self.view.backgroundColor = UIColor(red: 237, green: 237, blue: 237, alpha: 1)
tableView.registerNib(UINib(nibName: "MemberMessageCell", bundle: nil), forCellReuseIdentifier: "MemberMessageCell")
tableView.registerNib(UINib(nibName: "SelfMessageCell", bundle: nil), forCellReuseIdentifier: "SelfMessageCell")
tableView.estimatedRowHeight = 98
tableView.rowHeight = UITableViewAutomaticDimension

let onTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ChatViewController.handleTap(_:)))
onTapGesture.delegate = self
self.view.addGestureRecognizer(onTapGesture)
Expand Down Expand Up @@ -137,17 +136,29 @@ class ChatViewController: UITableViewController, UIImagePickerControllerDelegate


func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
guard let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage else {
return
}

let originalSize = editedImage.size
let expectedSize = CGSize(width: 640, height: 480)
let resizedImage: UIImage?

if originalSize.width <= expectedSize.width && originalSize.height <= expectedSize.height {
resizedImage = editedImage
} else {
resizedImage = editedImage.getResizedImage(CGSize(width: 640, height: 480))
}

let editedImage = info[UIImagePickerControllerEditedImage] as! UIImage
let resizedImage = resize(editedImage, newSize: CGSize(width: 100, height: 100))
dismissViewControllerAnimated(true, completion: {
// MARK: send picture
let senderId = User.currentUser?.userId
let screenName = User.currentUser?.screenName
let avatarPFFile = User.currentUser?.avatarImagePFFile
let media = getPFFileFromImage(resizedImage)
let media = getPFFileFromImage(resizedImage)
let message = Message(activityId: Activity.current_activity?.activityId, senderId: senderId, screenName: screenName, content: "MediaRes", avatarPFFile: avatarPFFile, mediaPFFile: media, mediaType: "Photo")
message.saveToBackend({

message.saveToBackend({
self.fetchData()
}, failureHandler: { (error: NSError?) in
Log.error(error?.localizedDescription)
Expand Down
3 changes: 3 additions & 0 deletions Dine/DetailProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class DetailProfileViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var imageView: UIImageView!

var user: User?
weak var imageToShow: UIImage?


override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
scrollView.backgroundColor = UIColor.blackColor()



if let file = user?.pfUser!["avatar"]{
file.getDataInBackgroundWithBlock({ (result, error) in
if result != nil && error == nil{
Expand Down
13 changes: 0 additions & 13 deletions Dine/UserProfile.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="female" translatesAutoresizingMaskIntoConstraints="NO" id="4vU-CI-T3b">
<rect key="frame" x="155" y="12.5" width="23" height="16"/>
<constraints>
<constraint firstAttribute="height" constant="16" id="bD1-bk-1GK"/>
<constraint firstAttribute="width" constant="23" id="h7g-jU-qLF"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="[email protected]" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XH6-JJ-22H">
<rect key="frame" x="96" y="36" width="107" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
Expand All @@ -52,8 +45,6 @@
</subviews>
<constraints>
<constraint firstItem="XH6-JJ-22H" firstAttribute="leading" secondItem="f5T-cD-Fev" secondAttribute="leading" id="0JZ-vq-HkN"/>
<constraint firstItem="4vU-CI-T3b" firstAttribute="leading" secondItem="f5T-cD-Fev" secondAttribute="trailing" constant="2" id="Dcq-Ao-1Ui"/>
<constraint firstItem="4vU-CI-T3b" firstAttribute="centerY" secondItem="f5T-cD-Fev" secondAttribute="centerY" id="KhD-aV-xOR"/>
<constraint firstItem="XH6-JJ-22H" firstAttribute="top" secondItem="f5T-cD-Fev" secondAttribute="bottom" constant="5" id="VIO-AN-USl"/>
<constraint firstItem="sye-SS-ibj" firstAttribute="centerY" secondItem="KpB-Je-0dT" secondAttribute="centerY" id="jHX-Gm-VAT"/>
<constraint firstItem="f5T-cD-Fev" firstAttribute="top" secondItem="sye-SS-ibj" secondAttribute="top" id="pQ0-ua-tJY"/>
Expand Down Expand Up @@ -139,7 +130,6 @@
<outlet property="addButtonCell" destination="Sxc-Vu-BTB" id="FoX-qC-tlS"/>
<outlet property="descriptionCell" destination="t1Z-92-72g" id="5dy-0g-uiS"/>
<outlet property="descriptionLabel" destination="Qti-jO-BZk" id="MJS-nL-XAX"/>
<outlet property="genderImageView" destination="4vU-CI-T3b" id="upg-IQ-Hdw"/>
<outlet property="headerCell" destination="jJ8-wC-Wng" id="v5j-pb-vrv"/>
<outlet property="profileImageView" destination="sye-SS-ibj" id="jvQ-B2-WmD"/>
<outlet property="screenNameLabel" destination="f5T-cD-Fev" id="KMu-EN-3tp"/>
Expand Down Expand Up @@ -200,7 +190,4 @@
<point key="canvasLocation" x="1176" y="-1458"/>
</scene>
</scenes>
<resources>
<image name="female" width="64" height="64"/>
</resources>
</document>
2 changes: 0 additions & 2 deletions Dine/UserProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class UserProfileViewController: UITableViewController {

@IBOutlet weak var screenNameLabel: UILabel!

@IBOutlet weak var genderImageView: UIImageView!

@IBOutlet weak var usernameLabel: UILabel!

@IBOutlet weak var descriptionLabel: UILabel!
Expand Down
17 changes: 17 additions & 0 deletions Dine/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
import Foundation
import MBProgressHUD


// MARK: There is a lot of things to do to resize image in a certain size
extension UIImage {
func getResizedImage(size: CGSize) -> UIImage {
let resizeImageView = UIImageView(frame: CGRectMake(0, 0, size.width, size.height))
resizeImageView.contentMode = UIViewContentMode.ScaleAspectFill
resizeImageView.image = self

UIGraphicsBeginImageContext(resizeImageView.frame.size)
resizeImageView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
}


func resize(image: UIImage, newSize: CGSize) -> UIImage {
let resizeImageView = UIImageView(frame: CGRectMake(0, 0, newSize.width, newSize.height))
resizeImageView.contentMode = UIViewContentMode.ScaleAspectFill
Expand Down
Binary file added icon.psd
Binary file not shown.

0 comments on commit 03fd6ee

Please sign in to comment.