feat: add title view for favorite scene

This commit is contained in:
CMK 2021-04-08 11:25:02 +08:00
parent e7279a0ab6
commit a0a636917f
7 changed files with 58 additions and 32 deletions

View File

@ -217,7 +217,7 @@
"new_posts": "See new posts", "new_posts": "See new posts",
"published": "Published!", "published": "Published!",
"Publishing": "Publishing post..." "Publishing": "Publishing post..."
}, }
}, },
"public_timeline": { "public_timeline": {
"title": "Public" "title": "Public"
@ -288,21 +288,24 @@
"cancel": "Cancel" "cancel": "Cancel"
}, },
"recommend": { "recommend": {
"buttonText": "See All", "buttonText": "See All",
"hash_tag": { "hash_tag": {
"title": "Trending in your timeline", "title": "Trending in your timeline",
"description": "Hashtags that are getting quite a bit of attention among people you follow", "description": "Hashtags that are getting quite a bit of attention among people you follow",
"people_talking": "%s people are talking" "people_talking": "%s people are talking"
}, },
"accounts": { "accounts": {
"title": "Accounts you might like", "title": "Accounts you might like",
"description": "Except for Sam, you will not like his account.", "description": "Except for Sam, you will not like his account.",
"follow": "Follow" "follow": "Follow"
} }
} }
}, },
"hashtag": { "hashtag": {
"prompt": "%s people talking" "prompt": "%s people talking"
},
"favorite": {
"title": "Your Favorites"
} }
} }
} }

View File

@ -7,7 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
0F1E2D0B2615C39400C38565 /* HashtagTimelineTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1E2D0A2615C39400C38565 /* HashtagTimelineTitleView.swift */; }; 0F1E2D0B2615C39400C38565 /* DoubleTitleLabelNavigationBarTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1E2D0A2615C39400C38565 /* DoubleTitleLabelNavigationBarTitleView.swift */; };
0F2021FB2613262F000C64BF /* HashtagTimelineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */; }; 0F2021FB2613262F000C64BF /* HashtagTimelineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */; };
0F202201261326E6000C64BF /* HashtagTimelineViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */; }; 0F202201261326E6000C64BF /* HashtagTimelineViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */; };
0F20220726134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */; }; 0F20220726134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */; };
@ -377,7 +377,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
0F1E2D0A2615C39400C38565 /* HashtagTimelineTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTimelineTitleView.swift; sourceTree = "<group>"; }; 0F1E2D0A2615C39400C38565 /* DoubleTitleLabelNavigationBarTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoubleTitleLabelNavigationBarTitleView.swift; sourceTree = "<group>"; };
0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTimelineViewController.swift; sourceTree = "<group>"; }; 0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTimelineViewController.swift; sourceTree = "<group>"; };
0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTimelineViewModel.swift; sourceTree = "<group>"; }; 0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTimelineViewModel.swift; sourceTree = "<group>"; };
0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HashtagTimelineViewModel+Diffable.swift"; sourceTree = "<group>"; }; 0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HashtagTimelineViewModel+Diffable.swift"; sourceTree = "<group>"; };
@ -760,7 +760,6 @@
0F1E2D102615C39800C38565 /* View */ = { 0F1E2D102615C39800C38565 /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0F1E2D0A2615C39400C38565 /* HashtagTimelineTitleView.swift */,
); );
path = View; path = View;
sourceTree = "<group>"; sourceTree = "<group>";
@ -770,10 +769,10 @@
children = ( children = (
0F1E2D102615C39800C38565 /* View */, 0F1E2D102615C39800C38565 /* View */,
0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */, 0F2021FA2613262F000C64BF /* HashtagTimelineViewController.swift */,
0F202226261411BA000C64BF /* HashtagTimelineViewController+StatusProvider.swift */,
0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */, 0F202200261326E6000C64BF /* HashtagTimelineViewModel.swift */,
0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */, 0F20220626134DA4000C64BF /* HashtagTimelineViewModel+Diffable.swift */,
0F20220C26134E3F000C64BF /* HashtagTimelineViewModel+LoadLatestState.swift */, 0F20220C26134E3F000C64BF /* HashtagTimelineViewModel+LoadLatestState.swift */,
0F202226261411BA000C64BF /* HashtagTimelineViewController+StatusProvider.swift */,
0F20222C261457EE000C64BF /* HashtagTimelineViewModel+LoadOldestState.swift */, 0F20222C261457EE000C64BF /* HashtagTimelineViewModel+LoadOldestState.swift */,
0F20223226145E51000C64BF /* HashtagTimelineViewModel+LoadMiddleState.swift */, 0F20223226145E51000C64BF /* HashtagTimelineViewModel+LoadMiddleState.swift */,
); );
@ -853,6 +852,7 @@
2D571B2E26004EC000540450 /* NavigationBarProgressView.swift */, 2D571B2E26004EC000540450 /* NavigationBarProgressView.swift */,
DB87D44A2609C11900D12C0D /* PollOptionView.swift */, DB87D44A2609C11900D12C0D /* PollOptionView.swift */,
DBE3CDCE261C42ED00430CC6 /* TimelineHeaderView.swift */, DBE3CDCE261C42ED00430CC6 /* TimelineHeaderView.swift */,
0F1E2D0A2615C39400C38565 /* DoubleTitleLabelNavigationBarTitleView.swift */,
); );
path = Content; path = Content;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1510,13 +1510,13 @@
DB8AF55525C1379F002E6C99 /* Scene */ = { DB8AF55525C1379F002E6C99 /* Scene */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0F2021F5261325ED000C64BF /* HashtagTimeline */,
5D03938E2612D200007FE196 /* Webview */, 5D03938E2612D200007FE196 /* Webview */,
2D7631A425C1532200929FB9 /* Share */, 2D7631A425C1532200929FB9 /* Share */,
DB8AF54E25C13703002E6C99 /* MainTab */, DB8AF54E25C13703002E6C99 /* MainTab */,
DB01409B25C40BB600F9F3CF /* Onboarding */, DB01409B25C40BB600F9F3CF /* Onboarding */,
2D38F1D325CD463600561493 /* HomeTimeline */, 2D38F1D325CD463600561493 /* HomeTimeline */,
2D76316325C14BAC00929FB9 /* PublicTimeline */, 2D76316325C14BAC00929FB9 /* PublicTimeline */,
0F2021F5261325ED000C64BF /* HashtagTimeline */,
DB9D6BEE25E4F5370051B173 /* Search */, DB9D6BEE25E4F5370051B173 /* Search */,
DB9D6BFD25E4F57B0051B173 /* Notification */, DB9D6BFD25E4F57B0051B173 /* Notification */,
DB9D6C0825E4F5A60051B173 /* Profile */, DB9D6C0825E4F5A60051B173 /* Profile */,
@ -2163,7 +2163,7 @@
DB68A06325E905E000CFDF14 /* UIApplication.swift in Sources */, DB68A06325E905E000CFDF14 /* UIApplication.swift in Sources */,
DBB5255E2611F07A002F1F29 /* ProfileViewModel.swift in Sources */, DBB5255E2611F07A002F1F29 /* ProfileViewModel.swift in Sources */,
2D8434FB25FF46B300EECE90 /* HomeTimelineNavigationBarTitleView.swift in Sources */, 2D8434FB25FF46B300EECE90 /* HomeTimelineNavigationBarTitleView.swift in Sources */,
0F1E2D0B2615C39400C38565 /* HashtagTimelineTitleView.swift in Sources */, 0F1E2D0B2615C39400C38565 /* DoubleTitleLabelNavigationBarTitleView.swift in Sources */,
DB9A488A26034D40008B817C /* ComposeViewModel+PublishState.swift in Sources */, DB9A488A26034D40008B817C /* ComposeViewModel+PublishState.swift in Sources */,
DB45FAD725CA6C76005A8AC7 /* UIBarButtonItem.swift in Sources */, DB45FAD725CA6C76005A8AC7 /* UIBarButtonItem.swift in Sources */,
2DA504692601ADE7008F4E6C /* SawToothView.swift in Sources */, 2DA504692601ADE7008F4E6C /* SawToothView.swift in Sources */,

View File

@ -299,6 +299,10 @@ internal enum L10n {
internal static let title = L10n.tr("Localizable", "Scene.ConfirmEmail.OpenEmailApp.Title") internal static let title = L10n.tr("Localizable", "Scene.ConfirmEmail.OpenEmailApp.Title")
} }
} }
internal enum Favorite {
/// Your Favorites
internal static let title = L10n.tr("Localizable", "Scene.Favorite.Title")
}
internal enum Hashtag { internal enum Hashtag {
/// %@ people talking /// %@ people talking
internal static func prompt(_ p1: Any) -> String { internal static func prompt(_ p1: Any) -> String {

View File

@ -102,6 +102,7 @@ uploaded to Mastodon.";
"Scene.ConfirmEmail.Subtitle" = "We just sent an email to %@, "Scene.ConfirmEmail.Subtitle" = "We just sent an email to %@,
tap the link to confirm your account."; tap the link to confirm your account.";
"Scene.ConfirmEmail.Title" = "One last thing."; "Scene.ConfirmEmail.Title" = "One last thing.";
"Scene.Favorite.Title" = "Your Favorites";
"Scene.Hashtag.Prompt" = "%@ people talking"; "Scene.Hashtag.Prompt" = "%@ people talking";
"Scene.HomeTimeline.NavigationBarState.NewPosts" = "See new posts"; "Scene.HomeTimeline.NavigationBarState.NewPosts" = "See new posts";
"Scene.HomeTimeline.NavigationBarState.Offline" = "Offline"; "Scene.HomeTimeline.NavigationBarState.Offline" = "Offline";

View File

@ -41,7 +41,7 @@ class HashtagTimelineViewController: UIViewController, NeedsDependency {
let refreshControl = UIRefreshControl() let refreshControl = UIRefreshControl()
let titleView = HashtagTimelineNavigationBarTitleView() let titleView = DoubleTitleLabelNavigationBarTitleView()
deinit { deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s:", ((#file as NSString).lastPathComponent), #line, #function) os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s:", ((#file as NSString).lastPathComponent), #line, #function)
@ -54,7 +54,7 @@ extension HashtagTimelineViewController {
super.viewDidLoad() super.viewDidLoad()
title = "#\(viewModel.hashtag)" title = "#\(viewModel.hashtag)"
titleView.updateTitle(hashtag: viewModel.hashtag, peopleNumber: nil) titleView.update(title: viewModel.hashtag, subtitle: nil)
navigationItem.titleView = titleView navigationItem.titleView = titleView
view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
@ -107,9 +107,6 @@ extension HashtagTimelineViewController {
self?.updatePromptTitle() self?.updatePromptTitle()
} }
.store(in: &disposeBag) .store(in: &disposeBag)
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
@ -142,7 +139,7 @@ extension HashtagTimelineViewController {
private func updatePromptTitle() { private func updatePromptTitle() {
var subtitle: String? var subtitle: String?
defer { defer {
titleView.updateTitle(hashtag: viewModel.hashtag, peopleNumber: subtitle) titleView.update(title: "#" + viewModel.hashtag, subtitle: subtitle)
} }
guard let histories = viewModel.hashtagEntity.value?.history else { guard let histories = viewModel.hashtagEntity.value?.history else {
return return
@ -158,7 +155,7 @@ extension HashtagTimelineViewController {
.prefix(2) .prefix(2)
.compactMap({ Int($0.accounts) }) .compactMap({ Int($0.accounts) })
.reduce(0, +) .reduce(0, +)
subtitle = "\(peopleTalkingNumber)" subtitle = L10n.Scene.Hashtag.prompt("\(peopleTalkingNumber)")
} }
} }
} }

View File

@ -21,6 +21,8 @@ final class FavoriteViewController: UIViewController, NeedsDependency {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
var viewModel: FavoriteViewModel! var viewModel: FavoriteViewModel!
let titleView = DoubleTitleLabelNavigationBarTitleView()
lazy var tableView: UITableView = { lazy var tableView: UITableView = {
let tableView = UITableView() let tableView = UITableView()
@ -44,6 +46,7 @@ extension FavoriteViewController {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color view.backgroundColor = Asset.Colors.Background.systemGroupedBackground.color
navigationItem.titleView = titleView
tableView.translatesAutoresizingMaskIntoConstraints = false tableView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tableView) view.addSubview(tableView)

View File

@ -1,5 +1,5 @@
// //
// HashtagTimelineTitleView.swift // DoubleTitleLabelNavigationBarTitleView.swift
// Mastodon // Mastodon
// //
// Created by BradGao on 2021/4/1. // Created by BradGao on 2021/4/1.
@ -7,7 +7,7 @@
import UIKit import UIKit
final class HashtagTimelineNavigationBarTitleView: UIView { final class DoubleTitleLabelNavigationBarTitleView: UIView {
let containerView = UIStackView() let containerView = UIStackView()
@ -40,7 +40,7 @@ final class HashtagTimelineNavigationBarTitleView: UIView {
} }
extension HashtagTimelineNavigationBarTitleView { extension DoubleTitleLabelNavigationBarTitleView {
private func _init() { private func _init() {
containerView.axis = .vertical containerView.axis = .vertical
containerView.alignment = .center containerView.alignment = .center
@ -58,10 +58,10 @@ extension HashtagTimelineNavigationBarTitleView {
containerView.addArrangedSubview(subtitleLabel) containerView.addArrangedSubview(subtitleLabel)
} }
func updateTitle(hashtag: String, peopleNumber: String?) { func update(title: String, subtitle: String?) {
titleLabel.text = "#\(hashtag)" titleLabel.text = title
if let peopleNumebr = peopleNumber { if let subtitle = subtitle {
subtitleLabel.text = L10n.Scene.Hashtag.prompt(peopleNumebr) subtitleLabel.text = subtitle
subtitleLabel.isHidden = false subtitleLabel.isHidden = false
} else { } else {
subtitleLabel.text = nil subtitleLabel.text = nil
@ -69,3 +69,21 @@ extension HashtagTimelineNavigationBarTitleView {
} }
} }
} }
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct DoubleTitleLabelNavigationBarTitleView_Previews: PreviewProvider {
static var previews: some View {
UIViewPreview(width: 375) {
DoubleTitleLabelNavigationBarTitleView()
}
.previewLayout(.fixed(width: 375, height: 100))
}
}
#endif