70 lines
2.3 KiB
Swift
70 lines
2.3 KiB
Swift
//
|
|
// NotificationsPageViewController.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 9/13/19.
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Pachyderm
|
|
|
|
class NotificationsPageViewController: SegmentedPageViewController<NotificationsPageViewController.Page> {
|
|
|
|
private let notificationsTitle = NSLocalizedString("Notifications", comment: "notifications tab title")
|
|
private let mentionsTitle = NSLocalizedString("Mentions", comment: "mentions tab title")
|
|
|
|
weak var mastodonController: MastodonController!
|
|
|
|
var initialMode: NotificationsMode?
|
|
|
|
init(initialMode: NotificationsMode? = nil, mastodonController: MastodonController) {
|
|
self.initialMode = initialMode
|
|
self.mastodonController = mastodonController
|
|
|
|
let notifications = NotificationsTableViewController(allowedTypes: Pachyderm.Notification.Kind.allCases, mastodonController: mastodonController)
|
|
notifications.title = notificationsTitle
|
|
notifications.userActivity = UserActivityManager.checkNotificationsActivity(mode: .allNotifications)
|
|
|
|
let mentions = NotificationsTableViewController(allowedTypes: [.mention], mastodonController: mastodonController)
|
|
mentions.title = mentionsTitle
|
|
mentions.userActivity = UserActivityManager.checkNotificationsActivity(mode: .mentionsOnly)
|
|
|
|
super.init(pages: [
|
|
(.all, notificationsTitle, notifications),
|
|
(.mentions, mentionsTitle, mentions),
|
|
])
|
|
|
|
title = notificationsTitle
|
|
tabBarItem.image = UIImage(systemName: "bell.fill")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
selectMode(initialMode ?? Preferences.shared.defaultNotificationsMode)
|
|
}
|
|
|
|
func selectMode(_ mode: NotificationsMode) {
|
|
let page: Page
|
|
switch mode {
|
|
case .allNotifications:
|
|
page = .all
|
|
case .mentionsOnly:
|
|
page = .mentions
|
|
}
|
|
segmentedControl.setSelectedOption(page, animated: false)
|
|
selectPage(page, animated: false)
|
|
}
|
|
|
|
enum Page {
|
|
case all
|
|
case mentions
|
|
}
|
|
|
|
}
|