Browse Source

Attachment Page View improvements

master
Dwayne Harris 6 years ago
parent
commit
09ab2a7d50
  1. 5
      elpha-ios/AccountTableViewController.swift
  2. BIN
      elpha-ios/Assets.xcassets/Icons/Timelines.imageset/timelines.pdf
  3. 60
      elpha-ios/AttachmentManager.swift
  4. 29
      elpha-ios/AttachmentPageViewController.swift
  5. 4
      elpha-ios/AttachmentViewController.swift
  6. 26
      elpha-ios/Base.lproj/Main.storyboard
  7. 2
      elpha-ios/Info.plist
  8. 44
      elpha-ios/StatusTableViewController.swift
  9. 54
      elpha-ios/StatusView.swift
  10. 8
      elpha-ios/TimelineTableViewController.swift

5
elpha-ios/AccountTableViewController.swift

@ -382,11 +382,12 @@ extension AccountTableViewController: StatusViewDelegate {
}
}
func attachmentTapped(status: StatusMO) {
func attachmentTapped(status: StatusMO, index: Int) {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentPageViewController") as? AttachmentPageViewController {
controller.status = status
controller.attachmentIndex = index
self.navigationController?.pushViewController(controller, animated: true)
self.navigationController?.pushViewController(controller, animated: false)
}
}
}

BIN
elpha-ios/Assets.xcassets/Icons/Timelines.imageset/timelines.pdf

60
elpha-ios/AttachmentManager.swift

@ -9,8 +9,20 @@
import AlamofireImage
import UIKit
class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
static func setupAttachmentView(_ view: UIView, withAttachments attachments: NSOrderedSet?) {
protocol AttachmentManagerDelegate {
func attachmentTapped(index: Int)
}
class AttachmentManager: NSObject {
var delegate: AttachmentManagerDelegate? = nil
@objc func attachmentTapped(_ gestureRecognizer: UITapGestureRecognizer) {
if let delegate = delegate, let name = gestureRecognizer.name {
delegate.attachmentTapped(index: Int(name)!)
}
}
func setupAttachmentView(_ view: UIView, withAttachments attachments: NSOrderedSet?) {
guard let attachments = attachments, attachments.count > 0 else {
return
}
@ -30,6 +42,16 @@ class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
let attachment = attachments.firstObject as! AttachmentMO
let imageView = UIImageView()
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped))
tapGestureRecognizer.delegate = self
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.numberOfTouchesRequired = 1
tapGestureRecognizer.name = "0"
imageView.addGestureRecognizer(tapGestureRecognizer)
imageView.isUserInteractionEnabled = true
imageView.af_setImage(
withURL: attachment.url!,
filter: filter
@ -54,6 +76,16 @@ class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
for (index, imageView) in imageViews.enumerated() {
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped))
tapGestureRecognizer.delegate = self
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.numberOfTouchesRequired = 1
tapGestureRecognizer.name = String(index)
imageView.addGestureRecognizer(tapGestureRecognizer)
imageView.isUserInteractionEnabled = true
imageView.af_setImage(
withURL: (attachments[index] as! AttachmentMO).url!,
filter: filter
@ -85,6 +117,16 @@ class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
for (index, imageView) in imageViews.enumerated() {
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped))
tapGestureRecognizer.delegate = self
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.numberOfTouchesRequired = 1
tapGestureRecognizer.name = String(index)
imageView.addGestureRecognizer(tapGestureRecognizer)
imageView.isUserInteractionEnabled = true
imageView.af_setImage(
withURL: (attachments[index] as! AttachmentMO).url!,
filter: index == 0 ? primaryFilter : secondaryFilter
@ -125,6 +167,16 @@ class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
for (index, imageView) in imageViews.enumerated() {
imageView.contentMode = UIImageView.ContentMode.scaleAspectFill
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped))
tapGestureRecognizer.delegate = self
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.numberOfTouchesRequired = 1
tapGestureRecognizer.name = String(index)
imageView.addGestureRecognizer(tapGestureRecognizer)
imageView.isUserInteractionEnabled = true
imageView.af_setImage(
withURL: (attachments[index] as! AttachmentMO).url!,
filter: filter
@ -147,3 +199,7 @@ class AttachmentManager: NSObject, UIGestureRecognizerDelegate {
}
}
}
extension AttachmentManager: UIGestureRecognizerDelegate {
}

29
elpha-ios/AttachmentPageViewController.swift

@ -17,7 +17,7 @@ class AttachmentPageViewController: UIPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
self.presentingViewController?.tabBarController?.tabBar.isHidden = true
self.delegate = self
self.dataSource = self
@ -31,12 +31,29 @@ class AttachmentPageViewController: UIPageViewController {
}
}
setViewControllers([controllers.first!], direction: .forward, animated: true, completion: nil)
setViewControllers([controllers[attachmentIndex]], direction: .forward, animated: true, completion: nil)
setNeedsStatusBarAppearanceUpdate()
}
func dismissController() {
self.navigationController?.isNavigationBarHidden = false
self.navigationController?.popViewController(animated: true)
self.presentingViewController?.tabBarController?.tabBar.isHidden = false
dismiss(animated: false)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
for view in view.subviews {
if view is UIScrollView {
view.frame = UIScreen.main.bounds
} else if view is UIPageControl {
view.backgroundColor = UIColor.clear
}
}
}
}
@ -45,6 +62,10 @@ extension AttachmentPageViewController: UIPageViewControllerDataSource, UIPageVi
return controllers.count
}
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
return attachmentIndex
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let index = controllers.index(of: viewController) else {
return nil

4
elpha-ios/AttachmentViewController.swift

@ -37,6 +37,10 @@ class AttachmentViewController: UIViewController {
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
@IBAction func imageSwiped(_ sender: Any) {
if let controller = self.parent as? AttachmentPageViewController {
controller.dismissController()

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

@ -741,7 +741,6 @@
<rect key="frame" x="0.0" y="44" width="375" height="96"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="barTintColor" name="Secondary"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</textAttributes>
@ -1222,7 +1221,7 @@
<!--Attachment Page View Controller-->
<scene sceneID="zGj-2x-VH5">
<objects>
<pageViewController storyboardIdentifier="AttachmentPageViewController" autoresizesArchivedViewToFullSize="NO" definesPresentationContext="YES" providesPresentationContextTransitionStyle="YES" modalPresentationStyle="overCurrentContext" hidesBottomBarWhenPushed="YES" transitionStyle="scroll" navigationOrientation="horizontal" spineLocation="none" id="Wmm-2l-ys2" customClass="AttachmentPageViewController" customModule="elpha_ios" customModuleProvider="target" sceneMemberID="viewController"/>
<pageViewController storyboardIdentifier="AttachmentPageViewController" definesPresentationContext="YES" providesPresentationContextTransitionStyle="YES" modalPresentationStyle="overCurrentContext" hidesBottomBarWhenPushed="YES" transitionStyle="scroll" navigationOrientation="horizontal" spineLocation="none" id="Wmm-2l-ys2" customClass="AttachmentPageViewController" customModule="elpha_ios" customModuleProvider="target" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="4hr-yC-hqj" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3614" y="-22"/>
@ -1241,8 +1240,9 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="LVW-zt-JUe">
<rect key="frame" x="0.0" y="0.0" width="375" height="662"/>
<imageView multipleTouchEnabled="YES" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="LVW-zt-JUe">
<rect key="frame" x="0.0" y="50" width="375" height="527"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<gestureRecognizers/>
<connections>
<outletCollection property="gestureRecognizers" destination="jGp-MJ-Wqo" appends="YES" id="T0x-sN-qnj"/>
@ -1250,18 +1250,22 @@
</connections>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Image Caption" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uOb-Wh-Ew6">
<rect key="frame" x="8" y="677" width="359" height="127"/>
<rect key="frame" x="8" y="592" width="359" height="200"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="200" id="96X-fO-fxQ"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" name="Background Primary"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.5" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="uOb-Wh-Ew6" firstAttribute="top" secondItem="LVW-zt-JUe" secondAttribute="bottom" constant="15" id="01E-pt-r18"/>
<constraint firstItem="LVW-zt-JUe" firstAttribute="top" secondItem="D1u-Lt-W0l" secondAttribute="top" id="1M4-gv-0KW"/>
<constraint firstItem="LVW-zt-JUe" firstAttribute="top" secondItem="D1u-Lt-W0l" secondAttribute="top" constant="50" id="2Tm-qW-RZD"/>
<constraint firstAttribute="trailing" secondItem="LVW-zt-JUe" secondAttribute="trailing" id="B6e-nm-1KT"/>
<constraint firstAttribute="bottom" secondItem="uOb-Wh-Ew6" secondAttribute="bottom" constant="8" id="BW9-Uf-nL7"/>
<constraint firstAttribute="bottom" secondItem="LVW-zt-JUe" secondAttribute="bottom" constant="150" id="SyJ-A5-Bpw"/>
<constraint firstAttribute="bottom" secondItem="uOb-Wh-Ew6" secondAttribute="bottom" constant="20" id="BW9-Uf-nL7"/>
<constraint firstAttribute="trailing" secondItem="uOb-Wh-Ew6" secondAttribute="trailing" constant="8" id="TRF-Oj-j11"/>
<constraint firstItem="LVW-zt-JUe" firstAttribute="leading" secondItem="D1u-Lt-W0l" secondAttribute="leading" id="ojo-i9-sB4"/>
<constraint firstItem="uOb-Wh-Ew6" firstAttribute="leading" secondItem="D1u-Lt-W0l" secondAttribute="leading" constant="8" id="yN9-W0-tng"/>
@ -1296,7 +1300,7 @@
</connections>
</swipeGestureRecognizer>
</objects>
<point key="canvasLocation" x="4367" y="-22"/>
<point key="canvasLocation" x="4365.6000000000004" y="-22.167487684729064"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="UVY-Um-jQm">
@ -1307,7 +1311,6 @@
<rect key="frame" x="0.0" y="44" width="375" height="96"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="barTintColor" name="Secondary"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</textAttributes>
@ -1334,7 +1337,6 @@
<rect key="frame" x="0.0" y="44" width="375" height="96"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="barTintColor" name="Secondary"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</textAttributes>
@ -1361,7 +1363,7 @@
<image name="Logo" width="400" height="400"/>
<image name="Message" width="20" height="20"/>
<image name="Star Regular" width="22" height="22"/>
<image name="Timelines" width="15" height="16"/>
<image name="Timelines" width="20" height="21"/>
<namedColor name="Background Primary">
<color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>

2
elpha-ios/Info.plist

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>

44
elpha-ios/StatusTableViewController.swift

@ -114,10 +114,6 @@ class StatusTableViewController: UITableViewController, UIGestureRecognizerDeleg
}
}
@objc func attachmentTappedSelf() {
self.attachmentTapped(status: status!)
}
func fetchStatuses(completion: @escaping (Error?) -> Void) {
if let status = status {
loading = true
@ -287,12 +283,9 @@ extension StatusTableViewController {
cell.attachmentsView.isHidden = false
cell.attachmentsView.isUserInteractionEnabled = true
AttachmentManager.setupAttachmentView(cell.attachmentsView, withAttachments: attachments)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTappedSelf))
cell.attachmentsView.addGestureRecognizer(tapGestureRecognizer)
tapGestureRecognizer.delegate = self
let attachmentManager = AttachmentManager()
attachmentManager.delegate = self
attachmentManager.setupAttachmentView(cell.attachmentsView, withAttachments: attachments)
}
let dateFormatter = DateFormatter()
@ -360,15 +353,34 @@ extension StatusTableViewController: StatusViewDelegate {
}
}
func loadMoreTapped(status: StatusMO, direction: PaginationDirection) {
}
func attachmentTapped(status: StatusMO) {
func attachmentTapped(status: StatusMO, index: Int) {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentPageViewController") as? AttachmentPageViewController {
controller.status = status
controller.attachmentIndex = index
self.navigationController?.pushViewController(controller, animated: true)
self.navigationController?.pushViewController(controller, animated: false)
}
}
func boostTapped() {
loadStatuses()
}
func favoriteTapped() {
loadStatuses()
}
func revealTapped() {
loadStatuses()
}
func hideTapped() {
loadStatuses()
}
}
extension StatusTableViewController: AttachmentManagerDelegate {
func attachmentTapped(index: Int) {
self.attachmentTapped(status: status!, index: index)
}
}

54
elpha-ios/StatusView.swift

@ -13,10 +13,22 @@ protocol StatusViewDelegate {
func accountTapped(account: AccountMO)
func statusTapped(status: StatusMO)
func loadMoreTapped(status: StatusMO, direction: PaginationDirection)
func attachmentTapped(status: StatusMO)
func attachmentTapped(status: StatusMO, index: Int)
func boostTapped()
func favoriteTapped()
func revealTapped()
func hideTapped()
}
class StatusView: UIView, UIGestureRecognizerDelegate {
extension StatusViewDelegate {
func loadMoreTapped(status: StatusMO, direction: PaginationDirection) {}
func boostTapped() {}
func favoriteTapped() {}
func revealTapped() {}
func hideTapped() {}
}
class StatusView: UIView {
@IBOutlet var contentView: UIView!
@IBOutlet var boostView: UIView!
@IBOutlet var boostAvatarImageView: UIImageView!
@ -49,6 +61,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
var status: StatusMO? = nil
var delegate: StatusViewDelegate? = nil
var spoilerView: UIVisualEffectView? = nil
var attachmentManager: AttachmentManager = AttachmentManager()
@IBAction func boostViewTapped(_ sender: Any) {
if let delegate = delegate, let status = status {
@ -89,6 +102,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
if let status = status {
status.hidden = true
CoreDataManager.shared.saveContext()
delegate?.hideTapped()
}
}
@ -133,6 +147,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
}
CoreDataManager.shared.saveContext()
delegate?.boostTapped()
}
}
@ -165,6 +180,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
}
CoreDataManager.shared.saveContext()
delegate?.favoriteTapped()
}
}
@ -173,16 +189,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
if let status = status {
status.hidden = false
CoreDataManager.shared.saveContext()
}
}
@objc func attachmentTapped() {
if let delegate = delegate, let status = status {
if let reblog = status.reblog {
delegate.attachmentTapped(status: reblog)
} else {
delegate.attachmentTapped(status: status)
}
delegate?.revealTapped()
}
}
@ -200,6 +207,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
Bundle.main.loadNibNamed("StatusView", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
attachmentManager.delegate = self
}
public func update(withStatus status: StatusMO) {
@ -230,14 +238,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
if let attachments = status.attachments, attachments.count > 0 {
attachmentsView.isHidden = false
attachmentsView.isUserInteractionEnabled = true
AttachmentManager.setupAttachmentView(attachmentsView, withAttachments: attachments)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped))
attachmentsView.addGestureRecognizer(tapGestureRecognizer)
tapGestureRecognizer.delegate = self
attachmentManager.setupAttachmentView(attachmentsView, withAttachments: attachments)
}
if let content = status.content {
@ -257,6 +258,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
spoilerText.font = UIFont.systemFont(ofSize: 15, weight: .bold)
spoilerText.textAlignment = .center
spoilerText.text = status.spoilerText
spoilerText.numberOfLines = 0
spoilerText.translatesAutoresizingMaskIntoConstraints = false
let blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffect.Style.light))
@ -349,3 +351,15 @@ class StatusView: UIView, UIGestureRecognizerDelegate {
}
}
}
extension StatusView: AttachmentManagerDelegate {
func attachmentTapped(index: Int) {
if let delegate = delegate, let status = status {
if let reblog = status.reblog {
delegate.attachmentTapped(status: reblog, index: index)
} else {
delegate.attachmentTapped(status: status, index: index)
}
}
}
}

8
elpha-ios/TimelineTableViewController.swift

@ -79,7 +79,7 @@ class TimelineTableViewController: UITableViewController {
}
@objc func compose() {
AlertManager.shared.show(message: "Much much much longer test message. This is a test.")
AlertManager.shared.show(message: "We'll get the compose screen working one day.")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
@ -413,10 +413,12 @@ extension TimelineTableViewController: StatusViewDelegate {
}
}
func attachmentTapped(status: StatusMO) {
func attachmentTapped(status: StatusMO, index: Int) {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentPageViewController") as? AttachmentPageViewController {
controller.status = status
self.navigationController?.pushViewController(controller, animated: true)
controller.attachmentIndex = index
present(controller, animated: false)
}
}
}
Loading…
Cancel
Save