Browse Source

Development

master
Dwayne Harris 6 years ago
parent
commit
7dd6613b83
  1. 32
      elpha-ios/AccountTableViewController.swift
  2. 47
      elpha-ios/AlertManager.swift
  3. 8
      elpha-ios/AlertView.swift
  4. 4
      elpha-ios/MastodonAPI.swift
  5. 30
      elpha-ios/StatusTableViewController.swift
  6. 17
      elpha-ios/StatusView.swift
  7. 22
      elpha-ios/StatusView.xib
  8. 44
      elpha-ios/TimelineTableViewController.swift

32
elpha-ios/AccountTableViewController.swift

@ -143,7 +143,7 @@ class AccountTableViewController: UITableViewController {
@objc func fetch() {
fetchStatuses { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}
@ -330,15 +330,21 @@ extension AccountTableViewController: StatusViewDelegate {
func favoriteTapped(status: StatusMO) {
if status.favorited {
MastodonAPI.unfavorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unfavorited", category: .favorited)
}
} else {
MastodonAPI.favorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Favorited!", category: .favorited)
}
}
}
@ -346,15 +352,21 @@ extension AccountTableViewController: StatusViewDelegate {
func reblogTapped(status: StatusMO) {
if status.reblogged {
MastodonAPI.unreblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unboosted", category: .boosted)
}
} else {
MastodonAPI.reblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Boosted!", category: .boosted)
}
}
}
@ -365,7 +377,7 @@ extension AccountTableViewController: StatusViewDelegate {
if marker.context == self.currentPaginationContext && marker.item.direction == direction {
fetchStatuses(withPagination: marker.item) { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}

47
elpha-ios/AlertManager.swift

@ -9,7 +9,7 @@
import UIKit
enum AlertCategory {
case normal, newStatuses, noConnection, error
case normal, newStatuses, favorited, boosted, noConnection, error
}
class Alert {
@ -25,6 +25,7 @@ class Alert {
class AlertManager {
static let shared = AlertManager()
static let alertStartPosition: CGFloat = 100.0
static let alertEndPosition: CGFloat = -80.0
var done: Bool = true
var alertView: AlertView? = nil
@ -56,7 +57,7 @@ class AlertManager {
view.addSubview(blurEffectView)
bottomLayoutConstraint = blurEffectView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: AlertManager.alertStartPosition)
bottomLayoutConstraint = blurEffectView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: AlertManager.alertStartPosition)
NSLayoutConstraint.activate([
blurEffectView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
@ -71,28 +72,32 @@ class AlertManager {
return
}
if alertView == nil {
createAlertView()
}
let view = UIApplication.shared.keyWindow!
done = false
self.alertView?.setAlert(self.alerts.first!)
view.layoutIfNeeded()
UIView.animate(withDuration: 1.0, animations: {
self.bottomLayoutConstraint?.constant = AlertManager.alertStartPosition
UIView.animate(withDuration: 0.2, animations: {
self.bottomLayoutConstraint?.constant = AlertManager.alertEndPosition
view.layoutIfNeeded()
}) { _ in
self.alertView?.setAlert(self.alerts.first!)
UIView.animate(withDuration: 1.0, animations: {
self.bottomLayoutConstraint?.constant = 20
}) { _ in
_ = self.alerts.remove(at: 0)
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
UIView.animate(withDuration: 1.0, animations: {
self.bottomLayoutConstraint?.constant = AlertManager.alertStartPosition
}) { _ in
self.done = true
if self.alerts.count > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.start()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
UIView.animate(withDuration: 0.2, animations: {
self.bottomLayoutConstraint?.constant = AlertManager.alertStartPosition
view.layoutIfNeeded()
}) { _ in
self.done = true
_ = self.alerts.remove(at: 0)
if self.alerts.count > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.start()
}
}
}

8
elpha-ios/AlertView.swift

@ -36,10 +36,14 @@ import UIKit
switch alert.category {
case .newStatuses:
alertImageView.image = UIImage(named: "Comments")
alertLabel.text = alert.message
case .favorited:
alertImageView.image = UIImage(named: "Star Filled")
case .boosted:
alertImageView.image = UIImage(named: "Boost Bold")
default:
alertImageView.image = UIImage(named: "Alert")
alertLabel.text = alert.message
}
alertLabel.text = alert.message
}
}

4
elpha-ios/MastodonAPI.swift

@ -317,7 +317,7 @@ class MastodonAPI {
}
static func favorite(statusID: String, completion: @escaping (Error?) -> Void) {
self.request(path: "api/v1/statuses/\(statusID)/favorite", method: .post) { _, _, error in
self.request(path: "api/v1/statuses/\(statusID)/favourite", method: .post) { _, _, error in
guard error == nil else {
completion(error)
return
@ -328,7 +328,7 @@ class MastodonAPI {
}
static func unfavorite(statusID: String, completion: @escaping (Error?) -> Void) {
self.request(path: "api/v1/statuses/\(statusID)/unfavorite", method: .post) { _, _, error in
self.request(path: "api/v1/statuses/\(statusID)/unfavourite", method: .post) { _, _, error in
guard error == nil else {
completion(error)
return

30
elpha-ios/StatusTableViewController.swift

@ -41,7 +41,7 @@ class StatusTableViewController: UITableViewController {
fetchStatuses { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}
@ -288,15 +288,21 @@ extension StatusTableViewController: StatusViewDelegate {
func favoriteTapped(status: StatusMO) {
if status.favorited {
MastodonAPI.unfavorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unfavorited", category: .favorited)
}
} else {
MastodonAPI.favorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Favorited!", category: .favorited)
}
}
}
@ -304,15 +310,21 @@ extension StatusTableViewController: StatusViewDelegate {
func reblogTapped(status: StatusMO) {
if status.reblogged {
MastodonAPI.unreblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unboosted", category: .boosted)
}
} else {
MastodonAPI.reblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Boosted!", category: .boosted)
}
}
}

17
elpha-ios/StatusView.swift

@ -105,6 +105,23 @@ class StatusView: UIView {
}
}
@IBAction func boostTapped(_ sender: Any) {
if let delegate = delegate, let status = status {
delegate.reblogTapped(status: status)
status.reblogged = !status.reblogged
CoreDataManager.shared.saveContext()
}
}
@IBAction func favoriteTapped(_ sender: Any) {
if let delegate = delegate, let status = status {
delegate.favoriteTapped(status: status)
status.favorited = !status.favorited
CoreDataManager.shared.saveContext()
}
}
@objc func reveal(sender: UITapGestureRecognizer) {
if let status = status {
status.hidden = false

22
elpha-ios/StatusView.xib

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@ -364,6 +364,7 @@
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="width" constant="60" id="4Fl-MA-OzE"/>
<constraint firstItem="MHw-QN-ZwH" firstAttribute="leading" secondItem="EID-tt-v32" secondAttribute="trailing" constant="8" id="AGn-oy-WMn"/>
@ -372,6 +373,9 @@
<constraint firstAttribute="trailing" secondItem="MHw-QN-ZwH" secondAttribute="trailing" constant="8" id="dGN-Dj-JTk"/>
<constraint firstItem="MHw-QN-ZwH" firstAttribute="centerY" secondItem="P6f-0v-SWB" secondAttribute="centerY" id="u2d-zL-cv3"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="z5d-1J-u4o" appends="YES" id="BQ7-6g-bja"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cfJ-cH-ci5">
<rect key="frame" x="239" y="10" width="60" height="30"/>
@ -391,6 +395,7 @@
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="trailing" secondItem="rq6-p2-tL4" secondAttribute="trailing" id="6rJ-cJ-0Xb"/>
<constraint firstAttribute="height" constant="30" id="8tv-lc-73N"/>
@ -399,6 +404,9 @@
<constraint firstItem="wns-8Z-i60" firstAttribute="centerY" secondItem="cfJ-cH-ci5" secondAttribute="centerY" id="iba-OS-yI0"/>
<constraint firstItem="rq6-p2-tL4" firstAttribute="leading" secondItem="wns-8Z-i60" secondAttribute="trailing" constant="8" id="wcx-Ut-goP"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="kY5-js-K1c" appends="YES" id="fqc-cY-jBp"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZKM-hs-NVu">
<rect key="frame" x="171" y="10" width="60" height="30"/>
@ -534,6 +542,16 @@
<action selector="topLoadMoreViewTapped:" destination="-1" id="VI5-n7-v8p"/>
</connections>
</tapGestureRecognizer>
<tapGestureRecognizer id="kY5-js-K1c">
<connections>
<action selector="boostTapped:" destination="-1" id="1vo-DM-5ce"/>
</connections>
</tapGestureRecognizer>
<tapGestureRecognizer id="z5d-1J-u4o">
<connections>
<action selector="favoriteTapped:" destination="-1" id="Hs1-BT-9gH"/>
</connections>
</tapGestureRecognizer>
</objects>
<resources>
<image name="Alert" width="22" height="22"/>

44
elpha-ios/TimelineTableViewController.swift

@ -69,7 +69,7 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle
fetchTimeline { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}
@ -133,7 +133,7 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle
@objc func fetch() {
fetchTimeline { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}
@ -173,10 +173,16 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle
}
DispatchQueue.main.async {
var newStatusCount = 0
for (index, status) in data.enumerated() {
if let upsertResult = MastodonDataManager.upsertStatus(status) {
let status = upsertResult.object
if upsertResult.new {
newStatusCount = newStatusCount + 1
}
if let pagination = pagination {
var markers: [PaginationMarker] = status.markers ?? []
markers = Array(markers.drop { $0.context == self.currentPaginationContext })
@ -204,6 +210,10 @@ class TimelineTableViewController: UITableViewController, TimelinesViewControlle
}
}
if newStatusCount > 0 {
AlertManager.shared.show(message: "\(newStatusCount) new toots", category: .newStatuses)
}
CoreDataManager.shared.saveContext()
self.loading = false
@ -396,15 +406,21 @@ extension TimelineTableViewController: StatusViewDelegate {
func favoriteTapped(status: StatusMO) {
if status.favorited {
MastodonAPI.unfavorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unfavorited", category: .favorited)
}
} else {
MastodonAPI.favorite(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Favorited!", category: .favorited)
}
}
}
@ -412,15 +428,21 @@ extension TimelineTableViewController: StatusViewDelegate {
func reblogTapped(status: StatusMO) {
if status.reblogged {
MastodonAPI.unreblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Unboosted", category: .boosted)
}
} else {
MastodonAPI.reblog(statusID: status.id!) { error in
if error != nil {
print("\(String(describing: error))")
guard error == nil else {
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
return
}
AlertManager.shared.show(message: "Boosted!", category: .boosted)
}
}
}
@ -431,7 +453,7 @@ extension TimelineTableViewController: StatusViewDelegate {
if marker.context == self.currentPaginationContext && marker.item.direction == direction {
fetchTimeline(withPagination: marker.item) { error in
if error != nil {
print("\(String(describing: error))")
AlertManager.shared.show(message: error!.localizedDescription, category: .error)
}
}
}

Loading…
Cancel
Save