More swipe actions
This commit is contained in:
parent
22dfec0483
commit
4c9be91162
|
@ -41,6 +41,12 @@ class TimelineTableViewController: UITableViewController {
|
||||||
lazy var reblogActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 927/558, height: 30)).image { _ in
|
lazy var reblogActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 927/558, height: 30)).image { _ in
|
||||||
UIImage(named: "Reblog")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 927/558, height: 30))
|
UIImage(named: "Reblog")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 927/558, height: 30))
|
||||||
}
|
}
|
||||||
|
lazy var replyActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 205/151, height: 30)).image { _ in
|
||||||
|
UIImage(named: "Reply")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 205/151, height: 30))
|
||||||
|
}
|
||||||
|
lazy var moreActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 2/1, height: 30)).image { _ in
|
||||||
|
UIImage(named: "More")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 2/1, height: 30))
|
||||||
|
}
|
||||||
|
|
||||||
var timeline: Timeline!
|
var timeline: Timeline!
|
||||||
|
|
||||||
|
@ -130,36 +136,74 @@ class TimelineTableViewController: UITableViewController {
|
||||||
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
let status = statuses[indexPath.row]
|
let status = statuses[indexPath.row]
|
||||||
|
|
||||||
let favorite = UIContextualAction(style: .normal, title: "Favorite") { (action, view, completion) in
|
let favorite: UIContextualAction
|
||||||
status.favourite(completion: { response in
|
if status.favourited ?? false {
|
||||||
DispatchQueue.main.async {
|
favorite = UIContextualAction(style: .normal, title: "Unfavorite", handler: { (action, view, completion) in
|
||||||
if case .success = response {
|
status.unfavourite(completion: { response in
|
||||||
completion(true)
|
DispatchQueue.main.async {
|
||||||
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
if case .success = response {
|
||||||
cell.updateUI(for: cell.status)
|
completion(true)
|
||||||
} else {
|
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
||||||
completion(false)
|
cell.updateUI(for: cell.status)
|
||||||
|
} else {
|
||||||
|
completion(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
|
favorite.backgroundColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1)
|
||||||
|
} else {
|
||||||
|
favorite = UIContextualAction(style: .normal, title: "Favorite") { (action, view, completion) in
|
||||||
|
status.favourite(completion: { response in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if case .success = response {
|
||||||
|
completion(true)
|
||||||
|
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
||||||
|
cell.updateUI(for: cell.status)
|
||||||
|
} else {
|
||||||
|
completion(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
favorite.backgroundColor = UIColor(displayP3Red: 1, green: 204/255, blue: 0, alpha: 1)
|
||||||
}
|
}
|
||||||
favorite.image = favoriteActionImage
|
favorite.image = favoriteActionImage
|
||||||
favorite.backgroundColor = UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1)
|
|
||||||
let reblog = UIContextualAction(style: .normal, title: "Reblog") { (action, view, completion) in
|
let reblog: UIContextualAction
|
||||||
status.reblog(completion: { response in
|
if status.reblogged ?? false {
|
||||||
DispatchQueue.main.async {
|
reblog = UIContextualAction(style: .normal, title: "Unreblog", handler: { (action, view, completion) in
|
||||||
if case .success = response {
|
status.unreblog(completion: { response in
|
||||||
completion(true)
|
DispatchQueue.main.async {
|
||||||
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
if case .success = response {
|
||||||
cell.updateUI(for: cell.status)
|
completion(true)
|
||||||
} else {
|
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
||||||
completion(false)
|
cell.updateUI(for: cell.status)
|
||||||
|
} else {
|
||||||
|
completion(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
})
|
||||||
|
reblog.backgroundColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1)
|
||||||
|
} else {
|
||||||
|
reblog = UIContextualAction(style: .normal, title: "Reblog") { (action, view, completion) in
|
||||||
|
status.reblog(completion: { response in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if case .success = response {
|
||||||
|
completion(true)
|
||||||
|
guard let cell = tableView.cellForRow(at: indexPath) as? StatusTableViewCell else { return }
|
||||||
|
cell.updateUI(for: cell.status)
|
||||||
|
} else {
|
||||||
|
completion(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
reblog.backgroundColor = view.tintColor
|
||||||
}
|
}
|
||||||
reblog.image = reblogActionImage
|
reblog.image = reblogActionImage
|
||||||
reblog.backgroundColor = view.tintColor
|
|
||||||
|
|
||||||
let actions = [
|
let actions = [
|
||||||
favorite,
|
favorite,
|
||||||
|
@ -168,6 +212,30 @@ class TimelineTableViewController: UITableViewController {
|
||||||
return UISwipeActionsConfiguration(actions: actions)
|
return UISwipeActionsConfiguration(actions: actions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
|
let status = statuses[indexPath.row]
|
||||||
|
|
||||||
|
let reply = UIContextualAction(style: .normal, title: "Reply") { (action, view, completion) in
|
||||||
|
completion(true)
|
||||||
|
self.reply(to: status)
|
||||||
|
}
|
||||||
|
reply.image = replyActionImage
|
||||||
|
reply.backgroundColor = view.tintColor
|
||||||
|
|
||||||
|
let more = UIContextualAction(style: .normal, title: "More") { (action, view, completion) in
|
||||||
|
completion(true)
|
||||||
|
self.showMoreOptions(status: status)
|
||||||
|
}
|
||||||
|
more.image = moreActionImage
|
||||||
|
more.backgroundColor = .gray
|
||||||
|
|
||||||
|
let actions = [
|
||||||
|
reply,
|
||||||
|
more
|
||||||
|
]
|
||||||
|
return UISwipeActionsConfiguration(actions: actions)
|
||||||
|
}
|
||||||
|
|
||||||
@IBAction func refreshStatuses(_ sender: Any) {
|
@IBAction func refreshStatuses(_ sender: Any) {
|
||||||
guard let newer = newer else { return }
|
guard let newer = newer else { return }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue