Dwayne Harris
6 years ago
17 changed files with 558 additions and 222 deletions
-
16elpha-ios.xcodeproj/project.pbxproj
-
97elpha-ios/AccountTableViewController.swift
-
6elpha-ios/AlertManager.swift
-
2elpha-ios/AlertView.xib
-
BINelpha-ios/Assets.xcassets/Icons/Timelines.imageset/timelines.pdf
-
5elpha-ios/AttachmentManager.swift
-
79elpha-ios/AttachmentPageViewController.swift
-
45elpha-ios/AttachmentViewController.swift
-
30elpha-ios/AuthenticateViewController.swift
-
106elpha-ios/Base.lproj/Main.storyboard
-
6elpha-ios/InstanceViewController.swift
-
20elpha-ios/InstancesTableViewController.swift
-
22elpha-ios/MastodonAPI.swift
-
129elpha-ios/StatusTableViewController.swift
-
84elpha-ios/StatusView.swift
-
81elpha-ios/TimelineTableViewController.swift
-
52elpha-ios/TimelinesViewController.swift
@ -0,0 +1,79 @@ |
|||
// |
|||
// AttachmentPageViewController.swift |
|||
// elpha-ios |
|||
// |
|||
// Created by Dwayne Harris on 11/1/18. |
|||
// Copyright © 2018 Elpha. All rights reserved. |
|||
// |
|||
|
|||
import AlamofireImage |
|||
import UIKit |
|||
|
|||
class AttachmentPageViewController: UIPageViewController { |
|||
var status: StatusMO? = nil |
|||
var controllers: [UIViewController] = [] |
|||
var attachmentIndex = 0 |
|||
|
|||
override func viewDidLoad() { |
|||
super.viewDidLoad() |
|||
|
|||
self.navigationController?.isNavigationBarHidden = true |
|||
|
|||
self.delegate = self |
|||
self.dataSource = self |
|||
|
|||
if let status = status, let attachments = status.attachments { |
|||
attachments.forEach { attachment in |
|||
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentViewController") as? AttachmentViewController { |
|||
controller.attachment = attachment as? AttachmentMO |
|||
controllers.append(controller) |
|||
} |
|||
} |
|||
} |
|||
|
|||
setViewControllers([controllers.first!], direction: .forward, animated: true, completion: nil) |
|||
} |
|||
|
|||
func dismissController() { |
|||
self.navigationController?.isNavigationBarHidden = false |
|||
self.navigationController?.popViewController(animated: true) |
|||
} |
|||
} |
|||
|
|||
extension AttachmentPageViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate { |
|||
func presentationCount(for pageViewController: UIPageViewController) -> Int { |
|||
return controllers.count |
|||
} |
|||
|
|||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { |
|||
guard let index = controllers.index(of: viewController) else { |
|||
return nil |
|||
} |
|||
|
|||
if controllers.count == 1 { |
|||
return nil |
|||
} |
|||
|
|||
if index == 0 { |
|||
return controllers.last |
|||
} |
|||
|
|||
return controllers[index - 1] |
|||
} |
|||
|
|||
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { |
|||
guard let index = controllers.index(of: viewController) else { |
|||
return nil |
|||
} |
|||
|
|||
if controllers.count == 1 { |
|||
return nil |
|||
} |
|||
|
|||
if index == controllers.count - 1 { |
|||
return controllers.first |
|||
} |
|||
|
|||
return controllers[index + 1] |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
// |
|||
// AttachmentViewController.swift |
|||
// elpha-ios |
|||
// |
|||
// Created by Dwayne Harris on 11/1/18. |
|||
// Copyright © 2018 Elpha. All rights reserved. |
|||
// |
|||
|
|||
import UIKit |
|||
|
|||
class AttachmentViewController: UIViewController { |
|||
@IBOutlet var attachmentImageView: UIImageView! |
|||
@IBOutlet var statusLabel: UILabel! |
|||
|
|||
var attachment: AttachmentMO? = nil |
|||
|
|||
override func viewDidLoad() { |
|||
super.viewDidLoad() |
|||
|
|||
if let attachment = attachment { |
|||
attachmentImageView.af_setImage(withURL: attachment.url!) |
|||
|
|||
if let content = attachment.status?.content { |
|||
do { |
|||
let styledContent = "<style>html * { font-size: 14px; color: #ffffff; font-family: -apple-system } a:link { color: #ffffff } a:visited { color: #ffffff }</style> \(content)" |
|||
let attributedText = try NSAttributedString( |
|||
data: styledContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!, |
|||
options: [.documentType: NSAttributedString.DocumentType.html], |
|||
documentAttributes: nil |
|||
) |
|||
|
|||
statusLabel.attributedText = attributedText |
|||
} catch { |
|||
print("\(error)") |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@IBAction func imageSwiped(_ sender: Any) { |
|||
if let controller = self.parent as? AttachmentPageViewController { |
|||
controller.dismissController() |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue