forked from shadowfacts/Tusker
State restoration for non-home timeline pages
This commit is contained in:
parent
1e950b5ccb
commit
ea6698a2d8
|
@ -391,8 +391,7 @@ extension MainSplitViewController: TuskerRootViewController {
|
||||||
return tabBarViewController.stateRestorationActivity()
|
return tabBarViewController.stateRestorationActivity()
|
||||||
} else {
|
} else {
|
||||||
if let timelinePages = navigationStackFor(item: .tab(.timelines))?.first as? TimelinesPageViewController {
|
if let timelinePages = navigationStackFor(item: .tab(.timelines))?.first as? TimelinesPageViewController {
|
||||||
let timeline = timelinePages.pageControllers[timelinePages.currentIndex] as! TimelineViewController
|
return timelinePages.stateRestorationActivity()
|
||||||
return timeline.stateRestorationActivity()
|
|
||||||
} else {
|
} else {
|
||||||
stateRestorationLogger.fault("MainSplitViewController: Unable to create state restoration activity")
|
stateRestorationLogger.fault("MainSplitViewController: Unable to create state restoration activity")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -244,9 +244,8 @@ extension MainTabBarViewController: TuskerRootViewController {
|
||||||
func stateRestorationActivity() -> NSUserActivity? {
|
func stateRestorationActivity() -> NSUserActivity? {
|
||||||
let nav = viewController(for: .timelines) as! UINavigationController
|
let nav = viewController(for: .timelines) as! UINavigationController
|
||||||
var activity: NSUserActivity?
|
var activity: NSUserActivity?
|
||||||
if let timelinePages = nav.viewControllers.first as? TimelinesPageViewController,
|
if let timelinePages = nav.viewControllers.first as? TimelinesPageViewController {
|
||||||
let timelineVC = timelinePages.pageControllers[timelinePages.currentIndex] as? TimelineViewController {
|
activity = timelinePages.stateRestorationActivity()
|
||||||
activity = timelineVC.stateRestorationActivity()
|
|
||||||
} else {
|
} else {
|
||||||
stateRestorationLogger.fault("MainTabBarViewController: Unable to create state restoration activity, couldn't find timeline/page VC")
|
stateRestorationLogger.fault("MainTabBarViewController: Unable to create state restoration activity, couldn't find timeline/page VC")
|
||||||
}
|
}
|
||||||
|
@ -268,12 +267,11 @@ extension MainTabBarViewController: TuskerRootViewController {
|
||||||
|
|
||||||
if activity.activityType == UserActivityType.showTimeline.rawValue {
|
if activity.activityType == UserActivityType.showTimeline.rawValue {
|
||||||
let nav = viewController(for: .timelines) as! UINavigationController
|
let nav = viewController(for: .timelines) as! UINavigationController
|
||||||
guard let timelinePages = nav.viewControllers.first as? TimelinesPageViewController,
|
guard let timelinePages = nav.viewControllers.first as? TimelinesPageViewController else {
|
||||||
let timelineVC = timelinePages.pageControllers[timelinePages.currentIndex] as? TimelineViewController else {
|
|
||||||
stateRestorationLogger.fault("MainTabBarViewController: Unable to restore timeline activity, couldn't find VC")
|
stateRestorationLogger.fault("MainTabBarViewController: Unable to restore timeline activity, couldn't find VC")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
timelineVC.restoreActivity(activity)
|
timelinePages.restoreActivity(activity)
|
||||||
restoreEditedDraft()
|
restoreEditedDraft()
|
||||||
} else if activity.activityType == UserActivityType.newPost.rawValue {
|
} else if activity.activityType == UserActivityType.newPost.rawValue {
|
||||||
restoreEditedDraft()
|
restoreEditedDraft()
|
||||||
|
|
|
@ -252,8 +252,10 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
|
|
||||||
private func doRestore() -> Bool {
|
private func doRestore() -> Bool {
|
||||||
guard let activity = activityToRestore,
|
guard let activity = activityToRestore else {
|
||||||
let statusIDs = activity.userInfo?["statusIDs"] as? [String] else {
|
return false
|
||||||
|
}
|
||||||
|
guard let statusIDs = activity.userInfo?["statusIDs"] as? [String] else {
|
||||||
stateRestorationLogger.fault("TimelineViewController: activity missing statusIDs")
|
stateRestorationLogger.fault("TimelineViewController: activity missing statusIDs")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,21 +46,27 @@ class TimelinesPageViewController: SegmentedPageViewController {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stateRestorationActivity() -> NSUserActivity? {
|
||||||
|
return (pageControllers[currentIndex] as! TimelineViewController).stateRestorationActivity()
|
||||||
|
}
|
||||||
|
|
||||||
func restoreActivity(_ activity: NSUserActivity) {
|
func restoreActivity(_ activity: NSUserActivity) {
|
||||||
guard let timeline = UserActivityManager.getTimeline(from: activity) else {
|
guard let timeline = UserActivityManager.getTimeline(from: activity) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let index: Int
|
||||||
switch timeline {
|
switch timeline {
|
||||||
case .home:
|
case .home:
|
||||||
selectPage(at: 0, animated: false)
|
index = 0
|
||||||
case .public(local: false):
|
case .public(local: false):
|
||||||
selectPage(at: 1, animated: false)
|
index = 1
|
||||||
case .public(local: true):
|
case .public(local: true):
|
||||||
selectPage(at: 2, animated: false)
|
index = 2
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let timelineVC = pageControllers[currentIndex] as! TimelineViewController
|
selectPage(at: index, animated: false)
|
||||||
|
let timelineVC = pageControllers[index] as! TimelineViewController
|
||||||
timelineVC.restoreActivity(activity)
|
timelineVC.restoreActivity(activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
let titles: [String]
|
let titles: [String]
|
||||||
let pageControllers: [UIViewController]
|
let pageControllers: [UIViewController]
|
||||||
|
|
||||||
|
private var initialIndex = 0
|
||||||
private(set) var currentIndex = 0
|
private(set) var currentIndex = 0
|
||||||
|
|
||||||
var segmentedControl: UISegmentedControl!
|
var segmentedControl: UISegmentedControl!
|
||||||
|
@ -43,7 +44,7 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
|
|
||||||
view.backgroundColor = .systemBackground
|
view.backgroundColor = .systemBackground
|
||||||
|
|
||||||
selectPage(at: 0, animated: false)
|
selectPage(at: initialIndex, animated: false)
|
||||||
|
|
||||||
addKeyCommand(MenuController.prevSubTabCommand)
|
addKeyCommand(MenuController.prevSubTabCommand)
|
||||||
addKeyCommand(MenuController.nextSubTabCommand)
|
addKeyCommand(MenuController.nextSubTabCommand)
|
||||||
|
@ -57,6 +58,10 @@ class SegmentedPageViewController: UIPageViewController, UIPageViewControllerDel
|
||||||
}
|
}
|
||||||
|
|
||||||
func selectPage(at index: Int, animated: Bool) {
|
func selectPage(at index: Int, animated: Bool) {
|
||||||
|
guard isViewLoaded else {
|
||||||
|
initialIndex = index
|
||||||
|
return
|
||||||
|
}
|
||||||
let direction: UIPageViewController.NavigationDirection = index - currentIndex > 0 ? .forward : .reverse
|
let direction: UIPageViewController.NavigationDirection = index - currentIndex > 0 ? .forward : .reverse
|
||||||
setViewControllers([pageControllers[index]], direction: direction, animated: animated)
|
setViewControllers([pageControllers[index]], direction: direction, animated: animated)
|
||||||
navigationItem.title = pageControllers[index].title
|
navigationItem.title = pageControllers[index].title
|
||||||
|
|
Loading…
Reference in New Issue