Browse Source

Development

master
Dwayne Harris 6 years ago
parent
commit
c6b1d4c510
  1. 8
      elpha-ios.xcodeproj/project.pbxproj
  2. 13
      elpha-ios/AccountTableViewController.swift
  3. 1
      elpha-ios/AlertView.xib
  4. 10
      elpha-ios/Base.lproj/Main.storyboard
  5. 4
      elpha-ios/StatusTableViewController.swift
  6. 106
      elpha-ios/StatusView.swift
  7. 25
      elpha-ios/StatusView.xib
  8. 40
      elpha-ios/String+HtmlAttributed.swift
  9. 23
      elpha-ios/UIColor+HexString.swift

8
elpha-ios.xcodeproj/project.pbxproj

@ -46,6 +46,8 @@
15960E84213774FC00C38CE9 /* InstancesTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15960E83213774FC00C38CE9 /* InstancesTableViewController.swift */; };
15A79B2E215C63B6007A326E /* AlamofireImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1517EA842159D72200DE80D6 /* AlamofireImage.framework */; };
15A79B43215EB959007A326E /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A79B42215EB959007A326E /* CoreDataManager.swift */; };
15B127922192467F00F4EF1D /* String+HtmlAttributed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15B127912192467F00F4EF1D /* String+HtmlAttributed.swift */; };
15B127A32192486200F4EF1D /* UIColor+HexString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15B127A22192486200F4EF1D /* UIColor+HexString.swift */; };
15BB72AB2171A8D4002F1FA4 /* TimelinesTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15BB72AA2171A8D4002F1FA4 /* TimelinesTableViewCell.swift */; };
15C91A02216AB2D600D97DC3 /* AlertView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 15C91A01216AB2D600D97DC3 /* AlertView.xib */; };
15C91A04216AB32500D97DC3 /* AlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15C91A03216AB32500D97DC3 /* AlertView.swift */; };
@ -230,6 +232,8 @@
15960E812136668500C38CE9 /* TimelinesNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelinesNavigationController.swift; sourceTree = "<group>"; };
15960E83213774FC00C38CE9 /* InstancesTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstancesTableViewController.swift; sourceTree = "<group>"; };
15A79B42215EB959007A326E /* CoreDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
15B127912192467F00F4EF1D /* String+HtmlAttributed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+HtmlAttributed.swift"; sourceTree = "<group>"; };
15B127A22192486200F4EF1D /* UIColor+HexString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+HexString.swift"; sourceTree = "<group>"; };
15BB72AA2171A8D4002F1FA4 /* TimelinesTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelinesTableViewCell.swift; sourceTree = "<group>"; };
15C91A01216AB2D600D97DC3 /* AlertView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AlertView.xib; sourceTree = "<group>"; };
15C91A03216AB32500D97DC3 /* AlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertView.swift; sourceTree = "<group>"; };
@ -315,6 +319,8 @@
isa = PBXGroup;
children = (
159026CF2163069600D362DD /* Date+TimeAgo.swift */,
15B127912192467F00F4EF1D /* String+HtmlAttributed.swift */,
15B127A22192486200F4EF1D /* UIColor+HexString.swift */,
);
name = Extensions;
sourceTree = "<group>";
@ -626,10 +632,12 @@
15F998352162C0E8009E58DA /* MastodonDataManager.swift in Sources */,
15960E7A2132387A00C38CE9 /* MainTabBarController.swift in Sources */,
15960E7C213272CD00C38CE9 /* AuthenticationManager.swift in Sources */,
15B127922192467F00F4EF1D /* String+HtmlAttributed.swift in Sources */,
15960E7E21329FED00C38CE9 /* AuthenticateViewController.swift in Sources */,
15960E5B213145E100C38CE9 /* AppDelegate.swift in Sources */,
15131EF2216D8D570092B252 /* StatusView.swift in Sources */,
152734D22186DC74003DB3C8 /* TimelinesViewController.swift in Sources */,
15B127A32192486200F4EF1D /* UIColor+HexString.swift in Sources */,
156FF07221779C650074D9CA /* InstanceRequest.swift in Sources */,
15960E7721322C6F00C38CE9 /* Configuration.swift in Sources */,
156FF07021779C570074D9CA /* MastodonAPI.swift in Sources */,

13
elpha-ios/AccountTableViewController.swift

@ -77,18 +77,7 @@ class AccountTableViewController: UITableViewController {
usernameLabel.text = account.acct
if let note = account.note {
do {
let styledContent = "<style>html * { font-size: 15px; color: #170c49; font-family: -apple-system } p { margin: 0; padding: 0 }</style> \(note)"
let attributedText = try NSAttributedString(
data: styledContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
contentLabel.attributedText = attributedText
} catch {
print("\(error)")
}
contentLabel.attributedText = note.htmlAttributed(size: 15, centered: true)
}
statusesLabel.text = NumberFormatter.localizedString(from: NSNumber(value: account.statusesCount), number: .decimal)

1
elpha-ios/AlertView.xib

@ -35,6 +35,7 @@
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="clq-3k-X29" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="10" id="5fg-xq-NZI"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="uLF-4h-Bxo" secondAttribute="trailing" constant="8" id="UuS-UO-ukK"/>

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

@ -240,15 +240,7 @@
<refreshControl key="refreshControl" opaque="NO" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="agk-Mw-NTN">
<rect key="frame" x="0.0" y="0.0" width="1000" height="1000"/>
<autoresizingMask key="autoresizingMask"/>
<attributedString key="attributedTitle">
<fragment content="Loading Instances ...">
<attributes>
<color key="NSColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="12" name=".SFNSText"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
<attributedString key="attributedTitle"/>
<color key="tintColor" red="0.090196078430000007" green="0.047058823530000002" blue="0.28627450980000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</refreshControl>
<connections>

4
elpha-ios/StatusTableViewController.swift

@ -38,6 +38,7 @@ class StatusTableViewController: UITableViewController, UIGestureRecognizerDeleg
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
loadStatuses()
fetchStatuses { error in
if error != nil {
@ -153,7 +154,6 @@ class StatusTableViewController: UITableViewController, UIGestureRecognizerDeleg
self.loading = false
self.loadStatuses()
self.tableView.reloadData()
completion(nil)
}
@ -191,6 +191,8 @@ class StatusTableViewController: UITableViewController, UIGestureRecognizerDeleg
ancestors.reverse()
descendants.reverse()
self.tableView.reloadData()
} catch {
print("\(error)")
}

106
elpha-ios/StatusView.swift

@ -41,7 +41,6 @@ class StatusView: UIView {
@IBOutlet var avatarImageView: UIImageView!
@IBOutlet var displayNameLabel: UILabel!
@IBOutlet var usernameLabel: UILabel!
@IBOutlet var contentLabel: UILabel!
@IBOutlet var timestampLabel: UILabel!
@IBOutlet var repliesImageView: UIImageView!
@IBOutlet var repliesLabel: UILabel!
@ -57,6 +56,7 @@ class StatusView: UIView {
@IBOutlet var pinImageView: UIImageView!
@IBOutlet var topLoadMoreView: UIView!
@IBOutlet var bottomLoadMoreView: UIView!
@IBOutlet var contentTextView: UITextView!
var status: StatusMO? = nil
var delegate: StatusViewDelegate? = nil
@ -213,10 +213,8 @@ class StatusView: UIView {
public func update(withStatus status: StatusMO) {
self.status = status
topDividerView.isHidden = false
boostView.isHidden = true
replyView.isHidden = true
bottomDividerView.isHidden = false
attachmentsView.backgroundColor = UIColor.white
attachmentsView.isHidden = true
@ -242,62 +240,58 @@ class StatusView: UIView {
}
if let content = status.content {
do {
let styledContent = "<style>html * { font-size: 15px; color: #170C49; font-family: -apple-system } a:link { color: #8A7BAE } a:visited { color: #BAABD6 }</style> \(content)"
let attributedText = try NSAttributedString(
data: styledContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
// let linkAttributes: [NSAttributedString.Key : Any] = [
// NSAttributedString.Key.foregroundColor: UIColor(named: "Primary")!,
// NSAttributedString.Key.underlineColor: UIColor(named: "Primary")!,
// NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single,
// ]
contentTextView.attributedText = content.htmlAttributed(size: 15.0)
//contentTextView.linkTextAttributes = linkAttributes
if status.hidden && spoilerView == nil {
let spoilerText = UILabel(frame: contentTextView.frame)
spoilerText.textColor = UIColor(named: "Primary")
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))
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
blurEffectView.contentView.addSubview(spoilerText)
NSLayoutConstraint.activate([
spoilerText.leadingAnchor.constraint(equalTo: blurEffectView.leadingAnchor),
spoilerText.trailingAnchor.constraint(equalTo: blurEffectView.trailingAnchor),
spoilerText.centerYAnchor.constraint(equalTo: blurEffectView.centerYAnchor),
])
contentLabel.attributedText = attributedText
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.reveal))
tapGesture.numberOfTapsRequired = 1
tapGesture.numberOfTouchesRequired = 1
blurEffectView.addGestureRecognizer(tapGesture)
blurEffectView.isUserInteractionEnabled = true
self.spoilerView = blurEffectView
self.contentView.addSubview(blurEffectView)
NSLayoutConstraint.activate([
blurEffectView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
blurEffectView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
blurEffectView.topAnchor.constraint(equalTo: contentTextView.topAnchor),
blurEffectView.bottomAnchor.constraint(equalTo: detailsView.topAnchor),
])
} else {
if let spoilerView = spoilerView {
spoilerView.removeFromSuperview()
self.spoilerView = nil
}
if status.hidden && spoilerView == nil {
let spoilerText = UILabel(frame: contentLabel.frame)
spoilerText.textColor = UIColor(named: "Primary")
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))
blurEffectView.translatesAutoresizingMaskIntoConstraints = false
blurEffectView.contentView.addSubview(spoilerText)
NSLayoutConstraint.activate([
spoilerText.leadingAnchor.constraint(equalTo: blurEffectView.leadingAnchor),
spoilerText.trailingAnchor.constraint(equalTo: blurEffectView.trailingAnchor),
spoilerText.centerYAnchor.constraint(equalTo: blurEffectView.centerYAnchor),
])
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.reveal))
tapGesture.numberOfTapsRequired = 1
tapGesture.numberOfTouchesRequired = 1
blurEffectView.addGestureRecognizer(tapGesture)
blurEffectView.isUserInteractionEnabled = true
self.spoilerView = blurEffectView
self.contentView.addSubview(blurEffectView)
NSLayoutConstraint.activate([
blurEffectView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
blurEffectView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
blurEffectView.topAnchor.constraint(equalTo: contentLabel.topAnchor),
blurEffectView.bottomAnchor.constraint(equalTo: detailsView.topAnchor),
])
} else {
if let spoilerView = spoilerView {
spoilerView.removeFromSuperview()
self.spoilerView = nil
}
if let spoilerText = status.spoilerText, !spoilerText.isEmpty {
spoilerImageView.isHidden = false
}
if let spoilerText = status.spoilerText, !spoilerText.isEmpty {
spoilerImageView.isHidden = false
}
} catch {
print("\(error)")
}
}

25
elpha-ios/StatusView.xib

@ -22,7 +22,7 @@
<outlet property="boostsLabel" destination="rq6-p2-tL4" id="Osw-F4-eLa"/>
<outlet property="bottomDividerView" destination="m4t-ve-E78" id="fEE-Uh-2qq"/>
<outlet property="bottomLoadMoreView" destination="0aT-X9-NYg" id="FMc-yo-MAP"/>
<outlet property="contentLabel" destination="WPF-Oe-N2r" id="Gw6-2e-SDE"/>
<outlet property="contentTextView" destination="o7b-at-xQ9" id="M8m-yP-ozG"/>
<outlet property="contentView" destination="iN0-l3-epB" id="BBM-O7-PHb"/>
<outlet property="detailsView" destination="y5N-A7-27p" id="10T-HF-Veu"/>
<outlet property="displayNameLabel" destination="a9Z-2P-cZT" id="9w7-9G-cp3"/>
@ -226,12 +226,6 @@
<view contentMode="scaleToFill" verticalHuggingPriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="cAR-YB-u2k">
<rect key="frame" x="0.0" y="255" width="375" height="130"/>
<subviews>
<label opaque="NO" contentMode="left" verticalHuggingPriority="249" text="Content" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WPF-Oe-N2r">
<rect key="frame" x="8" y="86" width="359" height="36"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" name="Text"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="50m-cW-QIF">
<rect key="frame" x="0.0" y="8" width="367" height="70"/>
<subviews>
@ -272,17 +266,26 @@
<outletCollection property="gestureRecognizers" destination="13W-G2-Xm4" appends="YES" id="6RI-ff-czd"/>
</connections>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="top" scrollEnabled="NO" editable="NO" text="Content" textAlignment="natural" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o7b-at-xQ9">
<rect key="frame" x="8" y="86" width="359" height="36"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="tintColor" name="Primary"/>
<color key="textColor" name="Text"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" smartDashesType="no" smartInsertDeleteType="no" smartQuotesType="no"/>
<dataDetectorType key="dataDetectorTypes" link="YES"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="bottom" secondItem="WPF-Oe-N2r" secondAttribute="bottom" constant="8" id="60R-bR-ZXD"/>
<constraint firstItem="o7b-at-xQ9" firstAttribute="leading" secondItem="cAR-YB-u2k" secondAttribute="leading" constant="8" id="2NC-sT-kEN"/>
<constraint firstAttribute="trailing" secondItem="50m-cW-QIF" secondAttribute="trailing" constant="8" id="FxM-Hx-2Do"/>
<constraint firstAttribute="trailing" secondItem="o7b-at-xQ9" secondAttribute="trailing" constant="8" id="Ops-Ze-Eya"/>
<constraint firstAttribute="bottom" secondItem="o7b-at-xQ9" secondAttribute="bottom" constant="8" id="Wc8-dM-g26"/>
<constraint firstItem="50m-cW-QIF" firstAttribute="top" secondItem="cAR-YB-u2k" secondAttribute="top" constant="8" id="dNY-jH-OpT"/>
<constraint firstItem="50m-cW-QIF" firstAttribute="leading" secondItem="cAR-YB-u2k" secondAttribute="leading" id="diD-1N-0MJ"/>
<constraint firstItem="WPF-Oe-N2r" firstAttribute="top" secondItem="50m-cW-QIF" secondAttribute="bottom" constant="8" id="sAS-TY-p0y"/>
<constraint firstAttribute="trailing" secondItem="WPF-Oe-N2r" secondAttribute="trailing" constant="8" id="vxV-3b-ytI"/>
<constraint firstItem="WPF-Oe-N2r" firstAttribute="leading" secondItem="cAR-YB-u2k" secondAttribute="leading" constant="8" id="wqO-6z-tPD"/>
<constraint firstItem="o7b-at-xQ9" firstAttribute="top" secondItem="50m-cW-QIF" secondAttribute="bottom" constant="8" id="t4P-Dj-0Il"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="9fc-Py-yTV" appends="YES" id="nDQ-45-6W2"/>

40
elpha-ios/String+HtmlAttributed.swift

@ -0,0 +1,40 @@
//
// String+HtmlAttributed.swift
// elpha-ios
//
// Created by Dwayne Harris on 11/6/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import UIKit
extension String {
func htmlAttributed(size: CGFloat, centered: Bool = false) -> NSAttributedString? {
do {
let htmlString = """
<style>
html * {
font-family: -apple-system !important;
font-size: \(size)px !important;
color: \(UIColor(named: "Text")!.hexString()) !important;
text-align: \(centered ? "center" : "initial") !important;
}
</style>
\(self)
"""
guard let data = htmlString.data(using: String.Encoding.utf16) else {
return nil
}
return try NSAttributedString(
data: data,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil
)
} catch {
print("\(error)")
return nil
}
}
}

23
elpha-ios/UIColor+HexString.swift

@ -0,0 +1,23 @@
//
// UIColor+HexString.swift
// elpha-ios
//
// Created by Dwayne Harris on 11/6/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import UIKit
extension UIColor {
func hexString() -> String {
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
getRed(&r, green: &g, blue: &b, alpha: &a)
let rgb: Int = (Int)(r * 255) << 16 | (Int)(g * 255) << 8 | (Int)(b * 255) << 0
return String(format: "#%06x", rgb)
}
}
Loading…
Cancel
Save