mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Localized title
This commit is contained in:
parent
acfd127672
commit
a6d959a6b9
8 changed files with 41 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
// Copyright © 2020 Metabolist. All rights reserved.
|
||||
|
||||
"account.%@-followers" = "%@'s Followers";
|
||||
"account.block" = "Block";
|
||||
"account.field.verified" = "Verified %@";
|
||||
"account.follow" = "Follow";
|
||||
"account.following" = "Following";
|
||||
"account.following-count" = "%ld Following";
|
||||
"account.followed-by-%@" = "Followed by %@";
|
||||
"account.hide-reblogs" = "Hide boosts";
|
||||
"account.mute" = "Mute";
|
||||
"account.request" = "Request";
|
||||
|
|
|
@ -15,13 +15,18 @@ public struct AccountListService {
|
|||
private let endpoint: AccountsEndpoint
|
||||
private let mastodonAPIClient: MastodonAPIClient
|
||||
private let contentDatabase: ContentDatabase
|
||||
private let titleComponents: [String]?
|
||||
private let nextPageMaxIdSubject = PassthroughSubject<String, Never>()
|
||||
|
||||
init(endpoint: AccountsEndpoint, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
|
||||
init(endpoint: AccountsEndpoint,
|
||||
mastodonAPIClient: MastodonAPIClient,
|
||||
contentDatabase: ContentDatabase,
|
||||
titleComponents: [String]? = nil) {
|
||||
list = AccountList()
|
||||
self.endpoint = endpoint
|
||||
self.mastodonAPIClient = mastodonAPIClient
|
||||
self.contentDatabase = contentDatabase
|
||||
self.titleComponents = titleComponents
|
||||
sections = contentDatabase.accountListPublisher(list)
|
||||
.map { [$0.map(CollectionItem.account)] }
|
||||
.eraseToAnyPublisher()
|
||||
|
@ -41,4 +46,12 @@ extension AccountListService: CollectionService {
|
|||
.flatMap { contentDatabase.append(accounts: $0.result, toList: list) }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||
if let titleComponents = titleComponents {
|
||||
return Just(titleComponents).eraseToAnyPublisher()
|
||||
} else {
|
||||
return Empty().eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,14 +95,16 @@ public extension AccountService {
|
|||
AccountListService(
|
||||
endpoint: .accountsFollowing(id: account.id),
|
||||
mastodonAPIClient: mastodonAPIClient,
|
||||
contentDatabase: contentDatabase)
|
||||
contentDatabase: contentDatabase,
|
||||
titleComponents: ["account.followed-by-%@", "@".appending(account.acct)])
|
||||
}
|
||||
|
||||
func followersService() -> AccountListService {
|
||||
AccountListService(
|
||||
endpoint: .accountsFollowers(id: account.id),
|
||||
mastodonAPIClient: mastodonAPIClient,
|
||||
contentDatabase: contentDatabase)
|
||||
contentDatabase: contentDatabase,
|
||||
titleComponents: ["account.%@-followers", "@".appending(account.acct)])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ public protocol CollectionService {
|
|||
var sections: AnyPublisher<[[CollectionItem]], Error> { get }
|
||||
var nextPageMaxId: AnyPublisher<String, Never> { get }
|
||||
var title: AnyPublisher<String, Never> { get }
|
||||
var titleLocalizationComponents: AnyPublisher<[String], Never> { get }
|
||||
var navigationService: NavigationService { get }
|
||||
var markerTimeline: Marker.Timeline? { get }
|
||||
func request(maxId: String?, minId: String?) -> AnyPublisher<Never, Error>
|
||||
|
@ -17,5 +18,7 @@ extension CollectionService {
|
|||
|
||||
public var title: AnyPublisher<String, Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
public var titleLocalizationComponents: AnyPublisher<[String], Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
public var markerTimeline: Marker.Timeline? { nil }
|
||||
}
|
||||
|
|
|
@ -228,6 +228,15 @@ private extension TableViewController {
|
|||
func setupViewModelBindings() {
|
||||
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)
|
||||
|
||||
viewModel.titleLocalizationComponents.sink { [weak self] in
|
||||
guard let key = $0.first else { return }
|
||||
|
||||
self?.navigationItem.title = String(
|
||||
format: NSLocalizedString(key, comment: ""),
|
||||
arguments: Array($0.suffix(from: 1)))
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.updates.sink { [weak self] in self?.update($0) }.store(in: &cancellables)
|
||||
|
||||
viewModel.events.receive(on: DispatchQueue.main)
|
||||
|
|
|
@ -66,6 +66,10 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
|
||||
public var title: AnyPublisher<String, Never> { collectionService.title }
|
||||
|
||||
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||
collectionService.titleLocalizationComponents
|
||||
}
|
||||
|
||||
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
||||
expandAllSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import Foundation
|
|||
public protocol CollectionViewModel {
|
||||
var updates: AnyPublisher<CollectionUpdate, Never> { get }
|
||||
var title: AnyPublisher<String, Never> { get }
|
||||
var titleLocalizationComponents: AnyPublisher<[String], Never> { get }
|
||||
var expandAll: AnyPublisher<ExpandAllState, Never> { get }
|
||||
var alertItems: AnyPublisher<AlertItem, Never> { get }
|
||||
var loading: AnyPublisher<Bool, Never> { get }
|
||||
|
|
|
@ -70,6 +70,10 @@ extension ProfileViewModel: CollectionViewModel {
|
|||
$accountViewModel.compactMap { $0?.accountName }.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var titleLocalizationComponents: AnyPublisher<[String], Never> {
|
||||
collectionViewModel.flatMap(\.titleLocalizationComponents).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var expandAll: AnyPublisher<ExpandAllState, Never> {
|
||||
Empty().eraseToAnyPublisher()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue