2019-09-14 16:04:06 +00:00
|
|
|
//
|
|
|
|
// NotificationsPageViewController.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/13/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Pachyderm
|
|
|
|
|
2022-12-13 01:57:38 +00:00
|
|
|
class NotificationsPageViewController: SegmentedPageViewController<NotificationsPageViewController.Page> {
|
2019-09-14 16:04:06 +00:00
|
|
|
|
2020-01-20 04:02:07 +00:00
|
|
|
weak var mastodonController: MastodonController!
|
2020-01-05 04:13:23 +00:00
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
var initialMode: NotificationsMode?
|
|
|
|
|
|
|
|
init(initialMode: NotificationsMode? = nil, mastodonController: MastodonController) {
|
|
|
|
self.initialMode = initialMode
|
2020-01-05 20:25:07 +00:00
|
|
|
self.mastodonController = mastodonController
|
|
|
|
|
2022-12-21 04:37:12 +00:00
|
|
|
super.init(pages: [.all, .mentions]) { page in
|
|
|
|
let vc = NotificationsTableViewController(allowedTypes: page.allowedTypes, mastodonController: mastodonController)
|
|
|
|
vc.title = page.title
|
|
|
|
vc.userActivity = page.userActivity
|
|
|
|
return vc
|
|
|
|
}
|
2019-09-14 16:04:06 +00:00
|
|
|
|
2022-12-21 04:37:12 +00:00
|
|
|
title = Page.all.title
|
2019-09-14 16:04:06 +00:00
|
|
|
tabBarItem.image = UIImage(systemName: "bell.fill")
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
2019-09-14 17:02:33 +00:00
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
selectMode(initialMode ?? Preferences.shared.defaultNotificationsMode)
|
2019-09-16 01:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func selectMode(_ mode: NotificationsMode) {
|
2022-12-13 01:57:38 +00:00
|
|
|
let page: Page
|
2019-09-16 01:15:32 +00:00
|
|
|
switch mode {
|
2019-09-14 17:02:33 +00:00
|
|
|
case .allNotifications:
|
2022-12-13 01:57:38 +00:00
|
|
|
page = .all
|
2019-09-14 17:02:33 +00:00
|
|
|
case .mentionsOnly:
|
2022-12-13 01:57:38 +00:00
|
|
|
page = .mentions
|
2019-09-14 17:02:33 +00:00
|
|
|
}
|
2022-12-13 01:57:38 +00:00
|
|
|
segmentedControl.setSelectedOption(page, animated: false)
|
|
|
|
selectPage(page, animated: false)
|
|
|
|
}
|
|
|
|
|
2022-12-21 04:37:12 +00:00
|
|
|
enum Page: SegmentedPageViewControllerPage {
|
2022-12-13 01:57:38 +00:00
|
|
|
case all
|
|
|
|
case mentions
|
2022-12-21 04:37:12 +00:00
|
|
|
|
|
|
|
var title: String {
|
|
|
|
switch self {
|
|
|
|
case .all:
|
|
|
|
return NSLocalizedString("Notifications", comment: "notifications tab title")
|
|
|
|
case .mentions:
|
|
|
|
return NSLocalizedString("Mentions", comment: "mentions tab title")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var segmentedControlTitle: String {
|
|
|
|
title
|
|
|
|
}
|
|
|
|
|
|
|
|
var allowedTypes: [Pachyderm.Notification.Kind] {
|
|
|
|
switch self {
|
|
|
|
case .all:
|
|
|
|
return Pachyderm.Notification.Kind.allCases
|
|
|
|
case .mentions:
|
|
|
|
return [.mention]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var userActivity: NSUserActivity {
|
|
|
|
switch self {
|
|
|
|
case .all:
|
|
|
|
return UserActivityManager.checkNotificationsActivity(mode: .allNotifications)
|
|
|
|
case .mentions:
|
|
|
|
return UserActivityManager.checkNotificationsActivity(mode: .mentionsOnly)
|
|
|
|
}
|
|
|
|
}
|
2019-09-14 17:02:33 +00:00
|
|
|
}
|
2019-09-14 16:04:06 +00:00
|
|
|
|
|
|
|
}
|