2019-12-20 02:20:29 +00:00
|
|
|
//
|
|
|
|
// HashtagTimelineViewController.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 12/19/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Pachyderm
|
|
|
|
|
|
|
|
class HashtagTimelineViewController: TimelineTableViewController {
|
|
|
|
|
|
|
|
let hashtag: Hashtag
|
|
|
|
|
|
|
|
var toggleSaveButton: UIBarButtonItem!
|
|
|
|
var toggleSaveButtonTitle: String {
|
2020-01-20 16:48:47 +00:00
|
|
|
if SavedDataManager.shared.isSaved(hashtag: hashtag, for: mastodonController.accountInfo!) {
|
2019-12-20 02:20:29 +00:00
|
|
|
return NSLocalizedString("Unsave", comment: "unsave hashtag button")
|
|
|
|
} else {
|
|
|
|
return NSLocalizedString("Save", comment: "save hashtag button")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 20:25:07 +00:00
|
|
|
init(for hashtag: Hashtag, mastodonController: MastodonController) {
|
2019-12-20 02:20:29 +00:00
|
|
|
self.hashtag = hashtag
|
|
|
|
|
2020-01-05 20:25:07 +00:00
|
|
|
super.init(for: .tag(hashtag: hashtag.name), mastodonController: mastodonController)
|
2019-12-20 02:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
toggleSaveButton = UIBarButtonItem(title: toggleSaveButtonTitle, style: .plain, target: self, action: #selector(toggleSaveButtonPressed))
|
|
|
|
navigationItem.rightBarButtonItem = toggleSaveButton
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(savedHashtagsChanged), name: .savedHashtagsChanged, object: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func savedHashtagsChanged() {
|
|
|
|
toggleSaveButton.title = toggleSaveButtonTitle
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Interaction
|
|
|
|
|
|
|
|
@objc func toggleSaveButtonPressed() {
|
2020-01-20 16:48:47 +00:00
|
|
|
if SavedDataManager.shared.isSaved(hashtag: hashtag, for: mastodonController.accountInfo!) {
|
|
|
|
SavedDataManager.shared.remove(hashtag: hashtag, for: mastodonController.accountInfo!)
|
2019-12-20 02:20:29 +00:00
|
|
|
} else {
|
2020-01-20 16:48:47 +00:00
|
|
|
SavedDataManager.shared.add(hashtag: hashtag, for: mastodonController.accountInfo!)
|
2019-12-20 02:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|