Skip to content

Commit

Permalink
Image caching and InputTextView UI commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshtatekonda committed Nov 3, 2017
1 parent aeba503 commit da9ab3d
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension CarouselItem {
@NSManaged public var previewUrl: String?
@NSManaged public var title: String?
@NSManaged public var url: String?
@NSManaged public var mediaData: NSObject?
@NSManaged public var carousel: Carousel?
@NSManaged public var options: NSSet?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<entity name="CarouselItem" representedClassName=".CarouselItem" syncable="YES">
<attribute name="desc" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="index" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="mediaData" optional="YES" attributeType="Transformable" syncable="YES"/>
<attribute name="mediaType" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="mediaUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="previewUrl" optional="YES" attributeType="String" syncable="YES"/>
Expand Down Expand Up @@ -91,6 +92,7 @@
<relationship name="senderMessage" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Message" inverseName="sender" inverseEntity="Message" syncable="YES"/>
</entity>
<entity name="Simple" representedClassName=".Simple" parentEntity="Message" syncable="YES">
<attribute name="mediaData" optional="YES" attributeType="Transformable" syncable="YES"/>
<attribute name="mediaType" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
<attribute name="mediaUrl" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="previewUrl" optional="YES" attributeType="String" syncable="YES"/>
Expand All @@ -108,7 +110,7 @@
</entity>
<elements>
<element name="Carousel" positionX="-351" positionY="-769" width="128" height="90"/>
<element name="CarouselItem" positionX="-182" positionY="-898" width="128" height="178"/>
<element name="CarouselItem" positionX="-182" positionY="-898" width="128" height="195"/>
<element name="DateRange" positionX="162" positionY="-675" width="128" height="163"/>
<element name="External" positionX="-288" positionY="-697" width="128" height="58"/>
<element name="Input" positionX="-243" positionY="-594" width="128" height="88"/>
Expand All @@ -122,7 +124,7 @@
<element name="Message" positionX="-578" positionY="-751" width="128" height="210"/>
<element name="Options" positionX="-2" positionY="-954" width="128" height="135"/>
<element name="Participant" positionX="-560" positionY="-522" width="128" height="103"/>
<element name="Simple" positionX="-389" positionY="-522" width="128" height="103"/>
<element name="Simple" positionX="-389" positionY="-522" width="128" height="120"/>
<element name="TimeRange" positionX="162" positionY="-910" width="128" height="163"/>
</elements>
</model>
1 change: 1 addition & 0 deletions ANAChat/Classes/DBHelpers/Simple+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ extension Simple {
@NSManaged public var mediaUrl: String?
@NSManaged public var previewUrl: String?
@NSManaged public var text: String?
@NSManaged public var mediaData: NSObject?

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class ChatCarouselCollectionCell: UICollectionViewCell {
imageView.layer.masksToBounds = true
}

override func prepareForReuse() {
super.prepareForReuse()
self.imageView.image = nil
}

func configureCell(_ item:CarouselItem, showOptions : Bool){
self.playButton.isHidden = true
self.showOptions = showOptions
Expand All @@ -52,21 +57,42 @@ class ChatCarouselCollectionCell: UICollectionViewCell {
if item.mediaType == 0{
self.playButton.isHidden = true
if let url = item.mediaUrl{
ImageCache.sharedInstance.getImageFromURL(url as String, successBlock: { (data) in
self.imageView.image = UIImage(data: (data as NSData) as Data)
})
{ (error) in
if item.mediaData is UIImage{
self.imageView.image = item.mediaData as? UIImage
}else{
ImageCache.sharedInstance.getImageFromURL(url as String, successBlock: { (data) in
if url.hasSuffix("gif"){
self.imageView.image = ImageCache.sharedInstance.gifImageWithData(data)
item.mediaData = ImageCache.sharedInstance.gifImageWithData(data)
}else{
self.imageView.image = UIImage(data: (data as NSData) as Data)
item.mediaData = UIImage(data: (data as NSData) as Data)
}

})
{ (error) in
}
}
}
}else if item.mediaType == 2{
self.playButton.isHidden = false
if let previewUrl = item.previewUrl{
ImageCache.sharedInstance.getImageFromURL(previewUrl as String, successBlock: { (data) in
self.imageView.image = UIImage(data: (data as NSData) as Data)
})
{ (error) in
if item.mediaData is UIImage{
self.imageView.image = item.mediaData as? UIImage
}else{
ImageCache.sharedInstance.getImageFromURL(previewUrl as String, successBlock: { (data) in
if previewUrl.hasSuffix("gif"){
self.imageView.image = ImageCache.sharedInstance.gifImageWithData(data)
item.mediaData = ImageCache.sharedInstance.gifImageWithData(data)
}else{
self.imageView.image = UIImage(data: (data as NSData) as Data)
item.mediaData = UIImage(data: (data as NSData) as Data)
}

})
{ (error) in
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ class ChatReceiveCarouselCell: UITableViewCell ,ChatCarouselCollectionCellDelega
self.sortedItems = carousel.items?.sortedArray(using: [sortDescriptor])
self.collectionview.reloadData()
self.collectionview.scrollRectToVisible(CGRect.zero, animated: false)
/*
if (self.sortedItems?.count)! > 0{
self.collectionview.scrollToItem(at: IndexPath(item: 0, section: 0), at: .left, animated: false)
}
*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="ChatReceiveCarouselCell" customModule="NowFloats_iOSSDK" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="KGk-i7-Jjw" customClass="ChatReceiveCarouselCell" customModule="NowFloats_iOSSDK" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="340"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down
32 changes: 23 additions & 9 deletions ANAChat/Classes/UIComponents/Cells/ChatReceiverMediaCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class ChatReceiverMediaCell: UITableViewCell {
self.addTapGestureRecognizer()
}

override func prepareForReuse() {
super.prepareForReuse()
self.cellImage.image = nil
}

func addTapGestureRecognizer() {
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(sender:)))
tap.delegate = self
Expand Down Expand Up @@ -101,32 +106,41 @@ class ChatReceiverMediaCell: UITableViewCell {
self.mediaTypeImageView.backgroundColor = UIColor.clear
self.playButton.isHidden = true
if let url = simpleMessage.mediaUrl{
if simpleMessage.mediaData is UIImage{
self.cellImage.image = simpleMessage.mediaData as? UIImage
}else{
ImageCache.sharedInstance.getImageFromURL(url, successBlock: { (data) in
if url.hasSuffix("gif"){
self.cellImage.image = ImageCache.sharedInstance.gifImageWithData(data)
simpleMessage.mediaData = ImageCache.sharedInstance.gifImageWithData(data)
}else{
self.cellImage.image = UIImage(data: (data as NSData) as Data)
simpleMessage.mediaData = UIImage(data: (data as NSData) as Data)
}
})
{ (error) in
}
}
}
case Int16(MessageSimpleType.MessageSimpleTypeVideo.rawValue):
self.descriptionLabel.text = "Video"
self.mediaTypeImageView.image = CommonUtility.getImageFromBundle(name: "videoImage")
self.mediaTypeImageView.backgroundColor = UIColor.clear
self.playButton.isHidden = false
if let url = simpleMessage.previewUrl{
DispatchQueue.global(qos: .default).async {
do{
let imgData : Data = try Data(contentsOf: URL(string: url)!)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1){
self.cellImage.image = UIImage(data: (imgData as NSData) as Data)
myActivityIndicator.stopAnimating()
myActivityIndicator.removeFromSuperview()
if simpleMessage.mediaData is UIImage{
self.cellImage.image = simpleMessage.mediaData as? UIImage
}else{
ImageCache.sharedInstance.getImageFromURL(url, successBlock: { (data) in
if url.hasSuffix("gif"){
self.cellImage.image = ImageCache.sharedInstance.gifImageWithData(data)
simpleMessage.mediaData = ImageCache.sharedInstance.gifImageWithData(data)
}else{
self.cellImage.image = UIImage(data: (data as NSData) as Data)
simpleMessage.mediaData = UIImage(data: (data as NSData) as Data)
}
}
catch{
})
{ (error) in
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ import MobileCoreServices
self.textContainerView.addSubview(self.inputTextView!)
self.inputTextView.translatesAutoresizingMaskIntoConstraints = false

ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: 40, superView: self.textContainerView, subView: self.inputTextView)
ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: CGFloat(CellHeights.textInputViewHeight), superView: self.textContainerView, subView: self.inputTextView)

self.textContainerViewHeightConstraint.constant = 40
self.textContainerViewHeightConstraint.constant = CGFloat(CellHeights.textInputViewHeight)
}

self.inputOptionsView = CommonUtility.getFrameworkBundle().loadNibNamed("InputOptionsView", owner: self, options: nil)?[0] as? InputOptionsView
Expand Down Expand Up @@ -410,9 +410,9 @@ import MobileCoreServices
self.textContainerView.addSubview(self.inputTextView!)
self.inputTextView.translatesAutoresizingMaskIntoConstraints = false

ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: 40, superView: self.textContainerView, subView: self.inputTextView)
ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: CGFloat(CellHeights.textInputViewHeight), superView: self.textContainerView, subView: self.inputTextView)

self.textContainerViewHeightConstraint.constant = 40
self.textContainerViewHeightConstraint.constant = CGFloat(CellHeights.textInputViewHeight)
}

self.inputTypeButton = CommonUtility.getFrameworkBundle().loadNibNamed("InputTypeButton", owner: self, options: nil)?[0] as? InputTypeButton
Expand Down Expand Up @@ -454,9 +454,9 @@ import MobileCoreServices
self.textContainerView.addSubview(self.inputTextView!)
self.inputTextView.translatesAutoresizingMaskIntoConstraints = false

ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: 40, superView: self.textContainerView, subView: self.inputTextView)
ConstraintsHelper.addConstraints(0, trailing: 0, top: 0, height: CGFloat(CellHeights.textInputViewHeight), superView: self.textContainerView, subView: self.inputTextView)

self.textContainerViewHeightConstraint.constant = 40
self.textContainerViewHeightConstraint.constant = CGFloat(CellHeights.textInputViewHeight)
}

self.inputTypeButton = CommonUtility.getFrameworkBundle().loadNibNamed("InputTypeButton", owner: self, options: nil)?[0] as? InputTypeButton
Expand Down
5 changes: 3 additions & 2 deletions ANAChat/Classes/UIComponents/Views/InputTextFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class InputTextFieldView: UIView , UITextViewDelegate{
inputBtn.setImage(tintedImage, for: .normal)
inputBtn.imageEdgeInsets = UIEdgeInsetsMake(12, 10, 12, 14)
textView.tintColor = PreferencesManager.sharedInstance.getBaseThemeColor()
textView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 15)
}

public func configure(messageObject :Message?){
Expand Down Expand Up @@ -218,11 +219,11 @@ public class InputTextFieldView: UIView , UITextViewDelegate{
#if swift(>=4.0)
let rect: CGRect = totalText.boundingRect(with: CGSize(width: UIScreen.main.bounds.size.width - 90, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: PreferencesManager.sharedInstance.getContentFont(),NSAttributedStringKey.paragraphStyle:parastyle], context: nil)

self.delegate?.configureTextViewHeight?(max(min(rect.size.height + 23 , 113),CGFloat(CellHeights.textInputViewHeight)))
self.delegate?.configureTextViewHeight?(max(min(rect.size.height + 30 , 125),CGFloat(CellHeights.textInputViewHeight)))
#else
let rect: CGRect = totalText.boundingRect(with: CGSize(width: UIScreen.main.bounds.size.width - 90, height: CGFloat.greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: PreferencesManager.sharedInstance.getContentFont(),NSParagraphStyleAttributeName:parastyle], context: nil)

self.delegate?.configureTextViewHeight?(max(min(rect.size.height + 23 , 113),CGFloat(CellHeights.textInputViewHeight)))
self.delegate?.configureTextViewHeight?(max(min(rect.size.height + 30 , 125),CGFloat(CellHeights.textInputViewHeight)))
#endif

return true
Expand Down
Loading

0 comments on commit da9ab3d

Please sign in to comment.