Browse Source

Development

master
Dwayne Harris 6 years ago
parent
commit
3c0bb02df2
  1. 4
      elpha-ios.xcodeproj/project.pbxproj
  2. 357
      elpha-ios/AttachmentManager.swift
  3. 334
      elpha-ios/AttachmentsView.swift
  4. 3
      elpha-ios/Base.lproj/Main.storyboard
  5. 98
      elpha-ios/TimelineTableViewController.swift

4
elpha-ios.xcodeproj/project.pbxproj

@ -20,6 +20,7 @@
157405B42151A93E00EEAAEB /* InstancesDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 157405B32151A93E00EEAAEB /* InstancesDataManager.swift */; };
157405D1215890D700EEAAEB /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 157405C3215890BC00EEAAEB /* Alamofire.framework */; };
1574147321696DB400C841BD /* AttachmentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1574147221696DB400C841BD /* AttachmentsView.swift */; };
1574148D2169AD0100C841BD /* AttachmentManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1574148C2169AD0100C841BD /* AttachmentManager.swift */; };
159026AE2162CF5600D362DD /* TimelineTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159026AD2162CF5600D362DD /* TimelineTableViewCell.swift */; };
159026D02163069600D362DD /* Date+TimeAgo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159026CF2163069600D362DD /* Date+TimeAgo.swift */; };
159048AF214F5015004F4014 /* InstancesTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159048AE214F5015004F4014 /* InstancesTableViewCell.swift */; };
@ -282,6 +283,7 @@
157405B32151A93E00EEAAEB /* InstancesDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstancesDataManager.swift; sourceTree = "<group>"; };
157405B7215890BC00EEAAEB /* Alamofire.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Alamofire.xcodeproj; path = Frameworks/Alamofire/Alamofire.xcodeproj; sourceTree = "<group>"; };
1574147221696DB400C841BD /* AttachmentsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentsView.swift; sourceTree = "<group>"; };
1574148C2169AD0100C841BD /* AttachmentManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentManager.swift; sourceTree = "<group>"; };
159026AD2162CF5600D362DD /* TimelineTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineTableViewCell.swift; sourceTree = "<group>"; };
159026CF2163069600D362DD /* Date+TimeAgo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+TimeAgo.swift"; sourceTree = "<group>"; };
159048AE214F5015004F4014 /* InstancesTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstancesTableViewCell.swift; sourceTree = "<group>"; };
@ -354,6 +356,7 @@
151AD4AC2166DD0200F07403 /* Managers */ = {
isa = PBXGroup;
children = (
1574148C2169AD0100C841BD /* AttachmentManager.swift */,
15960E7B213272CD00C38CE9 /* AuthenticationManager.swift */,
15A79B42215EB959007A326E /* CoreDataManager.swift */,
157405B32151A93E00EEAAEB /* InstancesDataManager.swift */,
@ -795,6 +798,7 @@
15960E7321322BC700C38CE9 /* KeychainItemAccessibility.swift in Sources */,
159026D02163069600D362DD /* Date+TimeAgo.swift in Sources */,
15A79B43215EB959007A326E /* CoreDataManager.swift in Sources */,
1574148D2169AD0100C841BD /* AttachmentManager.swift in Sources */,
15960E822136668500C38CE9 /* TimelinesNavigationController.swift in Sources */,
159026AE2162CF5600D362DD /* TimelineTableViewCell.swift in Sources */,
1574147321696DB400C841BD /* AttachmentsView.swift in Sources */,

357
elpha-ios/AttachmentManager.swift

@ -0,0 +1,357 @@
//
// AttachmentManager.swift
// elpha-ios
//
// Created by Dwayne Harris on 10/6/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import AlamofireImage
import UIKit
class AttachmentManager {
static func setupAttachmentsView(_ view: AttachmentsView, withAttachments attachments: NSOrderedSet?) {
guard let attachments = attachments, attachments.count > 0 else {
return
}
let placeholderImage = UIImage(named: "Help")
switch attachments.count {
case 0:
return
case 1:
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: view.frame.width, height: view.frame.width))
let attachment = attachments.firstObject as! AttachmentMO
let imageView = UIImageView()
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
imageView.af_setImage(
withURL: attachment.url!,
placeholderImage: placeholderImage,
filter: filter
)
view.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
view.addConstraint(getLeadingConstraint(from: imageView, to: view))
view.addConstraint(getTrailingConstraint(from: imageView, to: view))
view.addConstraint(getTopConstraint(from: imageView, to: view))
view.addConstraint(getBottomConstraint(from: imageView, to: view))
view.addConstraint(getWidthConstraint(view: imageView, width: view.frame.width))
view.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width))
case 2:
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: (view.frame.width / 2) - 2, height: view.frame.width))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
[firstImageView, secondImageView].forEach { imageView in
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
}
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
view.addSubview(firstImageView)
view.addSubview(secondImageView)
[firstImageView, secondImageView].forEach { imageView in
view.addConstraint(getLeadingConstraint(from: imageView, to: view))
view.addConstraint(getTrailingConstraint(from: imageView, to: view))
view.addConstraint(getTopConstraint(from: imageView, to: view))
view.addConstraint(getBottomConstraint(from: imageView, to: view))
view.addConstraint(getHeightConstraint(view: imageView, height: view.frame.width))
view.addConstraint(getWidthConstraint(view: imageView, width: (view.frame.width / 2) - 2))
}
let betweenConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
view.addConstraint(betweenConstraint)
case 3:
let halfWidth = (view.frame.width / 2) - 2
let primaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: view.frame.width))
let secondaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
let thirdImageView = UIImageView()
[firstImageView, secondImageView, thirdImageView].forEach { imageView in
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
}
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: primaryFilter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: secondaryFilter
)
thirdImageView.af_setImage(
withURL: (attachments[2] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: secondaryFilter
)
view.addSubview(firstImageView)
view.addSubview(secondImageView)
view.addSubview(thirdImageView)
view.addConstraint(getLeadingConstraint(from: firstImageView, to: view))
view.addConstraint(getTopConstraint(from: firstImageView, to: view))
view.addConstraint(getBottomConstraint(from: firstImageView, to: view))
view.addConstraint(getHeightConstraint(view: firstImageView, height: view.frame.width))
view.addConstraint(getWidthConstraint(view: firstImageView, width: halfWidth))
view.addConstraint(getTopConstraint(from: secondImageView, to: view))
view.addConstraint(getBottomConstraint(from: thirdImageView, to: view))
[secondImageView, thirdImageView].forEach { imageView in
view.addConstraint(getTrailingConstraint(from: imageView, to: view))
view.addConstraint(getHeightConstraint(view: imageView, height: halfWidth))
view.addConstraint(getWidthConstraint(view: imageView, width: halfWidth))
}
let firstSecondConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let firstThirdConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let secondThirdConstraint = NSLayoutConstraint(
item: secondImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 4
)
view.addConstraints([firstSecondConstraint, firstThirdConstraint, secondThirdConstraint])
default:
let halfWidth = (view.frame.width / 2) - 2
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
let thirdImageView = UIImageView()
let fourthImageView = UIImageView()
[firstImageView, secondImageView, thirdImageView, fourthImageView].forEach { imageView in
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
}
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
thirdImageView.af_setImage(
withURL: (attachments[2] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
fourthImageView.af_setImage(
withURL: (attachments[3] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
view.addSubview(firstImageView)
view.addSubview(secondImageView)
view.addSubview(thirdImageView)
view.addSubview(fourthImageView)
[firstImageView, secondImageView, thirdImageView, fourthImageView].forEach { imageView in
view.addConstraint(getHeightConstraint(view: imageView, height: halfWidth))
view.addConstraint(getWidthConstraint(view: imageView, width: halfWidth))
}
[firstImageView, secondImageView].forEach { imageView in
view.addConstraint(getTopConstraint(from: imageView, to: view))
}
[thirdImageView, fourthImageView].forEach { imageView in
view.addConstraint(getBottomConstraint(from: imageView, to: view))
}
[firstImageView, thirdImageView].forEach { imageView in
view.addConstraint(getLeadingConstraint(from: imageView, to: view))
}
[secondImageView, fourthImageView].forEach { imageView in
view.addConstraint(getTrailingConstraint(from: imageView, to: view))
}
let firstBetweenConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let secondBetweenConstraint = NSLayoutConstraint(
item: secondImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: fourthImageView,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 4
)
let thirdBetweenConstraint = NSLayoutConstraint(
item: fourthImageView,
attribute: NSLayoutConstraint.Attribute.leading,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
multiplier: 1,
constant: 4
)
let fourthBetweenConstraint = NSLayoutConstraint(
item: thirdImageView,
attribute: NSLayoutConstraint.Attribute.top,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: firstImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
multiplier: 1,
constant: 4
)
view.addConstraints([
firstBetweenConstraint,
secondBetweenConstraint,
thirdBetweenConstraint,
fourthBetweenConstraint,
])
}
}
static func getTopConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.top,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 0
)
}
static func getBottomConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.bottom,
multiplier: 1,
constant: 0
)
}
static func getLeadingConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.leading,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 0
)
}
static func getTrailingConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.trailing,
multiplier: 1,
constant: 0
)
}
static func getWidthConstraint(view: UIView, width: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: view,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: width
)
}
static func getHeightConstraint(view: UIView, height: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: view,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: height
)
}
}

334
elpha-ios/AttachmentsView.swift

@ -6,341 +6,7 @@
// Copyright © 2018 Elpha. All rights reserved.
//
import AlamofireImage
import UIKit
func getTopConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.top,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 0
)
}
func getBottomConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.bottom,
multiplier: 1,
constant: 0
)
}
func getLeadingConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.leading,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 0
)
}
func getTrailingConstraint(from: UIView, to: UIView) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: from,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: to,
attribute: NSLayoutConstraint.Attribute.trailing,
multiplier: 1,
constant: 0
)
}
func getWidthConstraint(view: UIView, width: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: view,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: width
)
}
func getHeightConstraint(view: UIView, height: CGFloat) -> NSLayoutConstraint {
return NSLayoutConstraint(
item: view,
attribute: NSLayoutConstraint.Attribute.height,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: height
)
}
class AttachmentsView: UIView {
public var attachments: NSOrderedSet? = nil {
didSet {
if let attachments = attachments {
let placeholderImage = UIImage(named: "Help")
print("attachments: \(attachments.count)")
switch attachments.count {
case 0:
self.isHidden = true
case 1:
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: self.frame.width, height: self.frame.width))
let attachment = attachments.firstObject as! AttachmentMO
let imageView = UIImageView()
imageView.af_setImage(
withURL: attachment.url!,
placeholderImage: placeholderImage,
filter: filter
)
self.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
self.addConstraint(getLeadingConstraint(from: imageView, to: self))
self.addConstraint(getTrailingConstraint(from: imageView, to: self))
self.addConstraint(getTopConstraint(from: imageView, to: self))
self.addConstraint(getBottomConstraint(from: imageView, to: self))
self.addConstraint(getWidthConstraint(view: imageView, width: self.frame.width))
self.addConstraint(getHeightConstraint(view: imageView, height: self.frame.width))
case 2:
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: (self.frame.width / 2) - 2, height: self.frame.width))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
self.addSubview(firstImageView)
self.addSubview(secondImageView)
[firstImageView, secondImageView].forEach { imageView in
self.addConstraint(getLeadingConstraint(from: imageView, to: self))
self.addConstraint(getTrailingConstraint(from: imageView, to: self))
self.addConstraint(getTopConstraint(from: imageView, to: self))
self.addConstraint(getBottomConstraint(from: imageView, to: self))
self.addConstraint(getHeightConstraint(view: imageView, height: self.frame.width))
self.addConstraint(getWidthConstraint(view: imageView, width: (self.frame.width / 2) - 2))
}
let betweenConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
self.addConstraint(betweenConstraint)
case 3:
let halfWidth = (self.frame.width / 2) - 2
let primaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: self.frame.width))
let secondaryFilter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
let thirdImageView = UIImageView()
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: primaryFilter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: secondaryFilter
)
thirdImageView.af_setImage(
withURL: (attachments[2] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: secondaryFilter
)
self.addSubview(firstImageView)
self.addSubview(secondImageView)
self.addSubview(thirdImageView)
self.addConstraint(getLeadingConstraint(from: firstImageView, to: self))
self.addConstraint(getTopConstraint(from: firstImageView, to: self))
self.addConstraint(getBottomConstraint(from: firstImageView, to: self))
self.addConstraint(getHeightConstraint(view: firstImageView, height: self.frame.width))
self.addConstraint(getWidthConstraint(view: firstImageView, width: halfWidth))
self.addConstraint(getTopConstraint(from: secondImageView, to: self))
self.addConstraint(getBottomConstraint(from: thirdImageView, to: self))
[secondImageView, thirdImageView].forEach { imageView in
self.addConstraint(getTrailingConstraint(from: imageView, to: self))
self.addConstraint(getHeightConstraint(view: imageView, height: halfWidth))
self.addConstraint(getWidthConstraint(view: imageView, width: halfWidth))
}
let firstSecondConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let firstThirdConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let secondThirdConstraint = NSLayoutConstraint(
item: secondImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 4
)
self.addConstraints([firstSecondConstraint, firstThirdConstraint, secondThirdConstraint])
default:
let halfWidth = (self.frame.width / 2) - 2
let filter = AspectScaledToFillSizeFilter(size: CGSize(width: halfWidth, height: halfWidth))
let firstImageView = UIImageView()
let secondImageView = UIImageView()
let thirdImageView = UIImageView()
let fourthImageView = UIImageView()
firstImageView.af_setImage(
withURL: (attachments[0] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
secondImageView.af_setImage(
withURL: (attachments[1] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
thirdImageView.af_setImage(
withURL: (attachments[2] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
fourthImageView.af_setImage(
withURL: (attachments[3] as! AttachmentMO).url!,
placeholderImage: placeholderImage,
filter: filter
)
self.addSubview(firstImageView)
self.addSubview(secondImageView)
self.addSubview(thirdImageView)
self.addSubview(fourthImageView)
[firstImageView, secondImageView, thirdImageView, fourthImageView].forEach { imageView in
self.addConstraint(getHeightConstraint(view: imageView, height: halfWidth))
self.addConstraint(getWidthConstraint(view: imageView, width: halfWidth))
}
[firstImageView, secondImageView].forEach { imageView in
self.addConstraint(getTopConstraint(from: imageView, to: self))
}
[thirdImageView, fourthImageView].forEach { imageView in
self.addConstraint(getBottomConstraint(from: imageView, to: self))
}
[firstImageView, thirdImageView].forEach { imageView in
self.addConstraint(getLeadingConstraint(from: imageView, to: self))
}
[secondImageView, fourthImageView].forEach { imageView in
self.addConstraint(getTrailingConstraint(from: imageView, to: self))
}
let firstBetweenConstraint = NSLayoutConstraint(
item: firstImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: secondImageView,
attribute: NSLayoutConstraint.Attribute.leading,
multiplier: 1,
constant: 4
)
let secondBetweenConstraint = NSLayoutConstraint(
item: secondImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: fourthImageView,
attribute: NSLayoutConstraint.Attribute.top,
multiplier: 1,
constant: 4
)
let thirdBetweenConstraint = NSLayoutConstraint(
item: fourthImageView,
attribute: NSLayoutConstraint.Attribute.leading,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: thirdImageView,
attribute: NSLayoutConstraint.Attribute.trailing,
multiplier: 1,
constant: 4
)
let fourthBetweenConstraint = NSLayoutConstraint(
item: thirdImageView,
attribute: NSLayoutConstraint.Attribute.top,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: firstImageView,
attribute: NSLayoutConstraint.Attribute.bottom,
multiplier: 1,
constant: 4
)
self.addConstraints([
firstBetweenConstraint,
secondBetweenConstraint,
thirdBetweenConstraint,
fourthBetweenConstraint,
])
}
}
}
}
}

3
elpha-ios/Base.lproj/Main.storyboard

@ -775,6 +775,9 @@
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="249" text="Content" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VmZ-Cs-XbK">
<rect key="frame" x="8" y="78" width="398" height="43"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="THV-62-aTc"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>

98
elpha-ios/TimelineTableViewController.swift

@ -136,6 +136,19 @@ class TimelineTableViewController: UITableViewController {
}
}
let request = NSFetchRequest<TimelineMO>(entityName: "Timeline")
request.predicate = NSPredicate(format: "name == %@", "Federated")
do {
let results = try CoreDataManager.shared.getContext().fetch(request)
session.selectedTimeline = results.first
CoreDataManager.shared.saveContext()
navigationItem.title = "Federated"
} catch {
print("\(error)")
}
loading = true
if let selectedTimeline = session.selectedTimeline {
@ -274,29 +287,61 @@ class TimelineTableViewController: UITableViewController {
}
}
func setupAttachmentView(attachments: NSOrderedSet?) {
if let attachments = attachments, attachments.count < 0 {
func setStatusContent(_ status: StatusMO) {
if let account = status.account {
cell.avatarImageView.af_setImage(withURL: account.avatarURL!, filter: avatarFilter)
cell.displayNameLabel.text = account.displayName
cell.usernameLabel.text = account.acct
}
if let attachments = status.attachments, attachments.count > 0 {
cell.attachmentsView.isHidden = false
cell.attachmentsView.attachments = attachments
AttachmentManager.setupAttachmentsView(cell.attachmentsView, withAttachments: attachments)
}
if let content = status.content {
do {
let styledContent = "<style>html * { font-size: 15px; color: #170c49; font-family: -apple-system } p { margin: 0; padding: 0 }</style> \(content)"
let attributedText = try NSAttributedString(
data: styledContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
cell.contentLabel.attributedText = attributedText
} catch {
print("\(error)")
}
}
cell.timestampLabel.text = status.createdAt!.timeAgo()
cell.repliesLabel.text = "0"
cell.boostsLabel.text = NumberFormatter.localizedString(from: NSNumber(value: status.reblogsCount), number: .decimal)
cell.favoritesLabel.text = NumberFormatter.localizedString(from: NSNumber(value: status.favouritesCount), number: .decimal)
if status.reblogged {
cell.boostsImageView.image = UIImage(named: "Boost Bold")
} else {
cell.boostsImageView.image = UIImage(named: "Boost Regular")
}
if status.favourited {
cell.favoritesImageView.image = UIImage(named: "Star Filled")
} else {
cell.favoritesImageView.image = UIImage(named: "Star Regular")
}
}
if let reblog = status.reblog {
cell.boostView.isHidden = false
if let account = reblog.account {
cell.avatarImageView.af_setImage(withURL: account.avatarURL!, filter: avatarFilter)
cell.displayNameLabel.text = account.displayName
cell.usernameLabel.text = account.acct
}
if let account = status.account {
cell.boostAvatarImageView.af_setImage(withURL: account.avatarURL!, filter: avatarFilter)
cell.boostDisplayNameLabel.text = account.displayName
cell.boostUsernameLabel.text = account.acct
}
setupAttachmentView(attachments: reblog.attachments)
setStatusContent(reblog)
} else {
if let account = status.account {
cell.avatarImageView.af_setImage(withURL: account.avatarURL!, filter: avatarFilter)
@ -304,7 +349,7 @@ class TimelineTableViewController: UITableViewController {
cell.usernameLabel.text = account.acct
}
setupAttachmentView(attachments: status.attachments)
setStatusContent(status)
}
if let replyAccountID = status.inReplyToAccountID {
@ -316,37 +361,6 @@ class TimelineTableViewController: UITableViewController {
}
}
if let content = status.content {
do {
let styledContent = "<style>html * { font-size: 15px; color: #170c49; font-family: -apple-system } p { margin: 0; padding: 0 }</style> \(content)"
let attributedText = try NSAttributedString(
data: styledContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
cell.contentLabel.attributedText = attributedText
} catch {
print("\(error)")
}
}
cell.timestampLabel.text = status.createdAt!.timeAgo()
cell.repliesLabel.text = "0"
cell.boostsLabel.text = NumberFormatter.localizedString(from: NSNumber(value: status.reblogsCount), number: .decimal)
cell.favoritesLabel.text = NumberFormatter.localizedString(from: NSNumber(value: status.favouritesCount), number: .decimal)
if status.reblogged {
cell.boostsImageView.image = UIImage(named: "Boost Bold")
} else {
cell.boostsImageView.image = UIImage(named: "Boost Regular")
}
if status.favourited {
cell.favoritesImageView.image = UIImage(named: "Star Filled")
} else {
cell.favoritesImageView.image = UIImage(named: "Star Regular")
}
if indexPath.row == statuses.count - 1 && !loading {
fetchTimeline(withRange: .max(id: status.id!, limit: fetchLimit))

Loading…
Cancel
Save