feat: add account settings entry in settings scene

This commit is contained in:
CMK 2021-07-13 17:39:38 +08:00
parent 709993146a
commit f265e988e7
8 changed files with 42 additions and 6 deletions

View File

@ -519,6 +519,7 @@
}, },
"boringzone": { "boringzone": {
"title": "The Boring zone", "title": "The Boring zone",
"account_settings": "Account settings",
"terms": "Terms of Service", "terms": "Terms of Service",
"privacy": "Privacy Policy" "privacy": "Privacy Policy"
}, },

View File

@ -43,6 +43,7 @@ extension SettingsItem {
} }
enum Link: CaseIterable { enum Link: CaseIterable {
case accountSettings
case termsOfService case termsOfService
case privacyPolicy case privacyPolicy
case clearMediaCache case clearMediaCache
@ -50,6 +51,7 @@ extension SettingsItem {
var title: String { var title: String {
switch self { switch self {
case .accountSettings: return "Account settings"
case .termsOfService: return L10n.Scene.Settings.Section.Boringzone.terms case .termsOfService: return L10n.Scene.Settings.Section.Boringzone.terms
case .privacyPolicy: return L10n.Scene.Settings.Section.Boringzone.privacy case .privacyPolicy: return L10n.Scene.Settings.Section.Boringzone.privacy
case .clearMediaCache: return L10n.Scene.Settings.Section.Spicyzone.clear case .clearMediaCache: return L10n.Scene.Settings.Section.Spicyzone.clear
@ -59,6 +61,7 @@ extension SettingsItem {
var textColor: UIColor { var textColor: UIColor {
switch self { switch self {
case .accountSettings: return Asset.Colors.brandBlue.color
case .termsOfService: return Asset.Colors.brandBlue.color case .termsOfService: return Asset.Colors.brandBlue.color
case .privacyPolicy: return Asset.Colors.brandBlue.color case .privacyPolicy: return Asset.Colors.brandBlue.color
case .clearMediaCache: return .systemRed case .clearMediaCache: return .systemRed

View File

@ -942,6 +942,8 @@ internal enum L10n {
internal static let trueBlackDarkMode = L10n.tr("Localizable", "Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode") internal static let trueBlackDarkMode = L10n.tr("Localizable", "Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode")
} }
internal enum Boringzone { internal enum Boringzone {
/// Account settings
internal static let accountSettings = L10n.tr("Localizable", "Scene.Settings.Section.Boringzone.AccountSettings")
/// Privacy Policy /// Privacy Policy
internal static let privacy = L10n.tr("Localizable", "Scene.Settings.Section.Boringzone.Privacy") internal static let privacy = L10n.tr("Localizable", "Scene.Settings.Section.Boringzone.Privacy")
/// Terms of Service /// Terms of Service

View File

@ -145,8 +145,8 @@ extension StatusProviderFacade {
provider.coordinator.present(scene: .safari(url: url), from: nil, transition: .safariPresent(animated: true, completion: nil)) provider.coordinator.present(scene: .safari(url: url), from: nil, transition: .safariPresent(animated: true, completion: nil))
} }
case .hashtag(let text, _): case .hashtag(let text, _):
let hashtagTimelienViewModel = HashtagTimelineViewModel(context: provider.context, hashtag: text) let hashtagTimelineViewModel = HashtagTimelineViewModel(context: provider.context, hashtag: text)
provider.coordinator.present(scene: .hashtagTimeline(viewModel: hashtagTimelienViewModel), from: provider, transition: .show) provider.coordinator.present(scene: .hashtagTimeline(viewModel: hashtagTimelineViewModel), from: provider, transition: .show)
case .mention(let text, let userInfo): case .mention(let text, let userInfo):
let href = userInfo?["href"] as? String let href = userInfo?["href"] as? String
coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: text, href: href) coordinateToStatusMentionProfileScene(for: .primary, provider: provider, cell: cell, mention: text, href: href)

View File

@ -320,6 +320,7 @@ any server.";
"Scene.Settings.Section.Appearance.Title" = "Appearance"; "Scene.Settings.Section.Appearance.Title" = "Appearance";
"Scene.Settings.Section.AppearanceSettings.DisableAvatarAnimation" = "Disable avatar animation"; "Scene.Settings.Section.AppearanceSettings.DisableAvatarAnimation" = "Disable avatar animation";
"Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode" = "True black Dark Mode"; "Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode" = "True black Dark Mode";
"Scene.Settings.Section.Boringzone.AccountSettings" = "Account settings";
"Scene.Settings.Section.Boringzone.Privacy" = "Privacy Policy"; "Scene.Settings.Section.Boringzone.Privacy" = "Privacy Policy";
"Scene.Settings.Section.Boringzone.Terms" = "Terms of Service"; "Scene.Settings.Section.Boringzone.Terms" = "Terms of Service";
"Scene.Settings.Section.Boringzone.Title" = "The Boring zone"; "Scene.Settings.Section.Boringzone.Title" = "The Boring zone";

View File

@ -320,6 +320,7 @@ any server.";
"Scene.Settings.Section.Appearance.Title" = "Appearance"; "Scene.Settings.Section.Appearance.Title" = "Appearance";
"Scene.Settings.Section.AppearanceSettings.DisableAvatarAnimation" = "Disable avatar animation"; "Scene.Settings.Section.AppearanceSettings.DisableAvatarAnimation" = "Disable avatar animation";
"Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode" = "True black Dark Mode"; "Scene.Settings.Section.AppearanceSettings.TrueBlackDarkMode" = "True black Dark Mode";
"Scene.Settings.Section.Boringzone.AccountSettings" = "Account settings";
"Scene.Settings.Section.Boringzone.Privacy" = "Privacy Policy"; "Scene.Settings.Section.Boringzone.Privacy" = "Privacy Policy";
"Scene.Settings.Section.Boringzone.Terms" = "Terms of Service"; "Scene.Settings.Section.Boringzone.Terms" = "Terms of Service";
"Scene.Settings.Section.Boringzone.Title" = "The Boring zone"; "Scene.Settings.Section.Boringzone.Title" = "The Boring zone";

View File

@ -12,7 +12,7 @@ import ActiveLabel
import CoreData import CoreData
import CoreDataStack import CoreDataStack
import MastodonSDK import MastodonSDK
import AuthenticationServices
class SettingsViewController: UIViewController, NeedsDependency { class SettingsViewController: UIViewController, NeedsDependency {
@ -369,6 +369,10 @@ extension SettingsViewController: UITableViewDelegate {
break break
case .boringZone(let link), .spicyZone(let link): case .boringZone(let link), .spicyZone(let link):
switch link { switch link {
case .accountSettings:
guard let box = context.authenticationService.activeMastodonAuthenticationBox.value,
let url = URL(string: "https://\(box.domain)/auth/edit") else { return }
viewModel.openAuthenticationPage(authenticateURL: url, presentationContextProvider: self)
case .termsOfService, .privacyPolicy: case .termsOfService, .privacyPolicy:
// same URL // same URL
guard let url = viewModel.privacyURL else { break } guard let url = viewModel.privacyURL else { break }
@ -382,10 +386,10 @@ extension SettingsViewController: UITableViewDelegate {
.receive(on: RunLoop.main) .receive(on: RunLoop.main)
.sink { [weak self] byteCount in .sink { [weak self] byteCount in
guard let self = self else { return } guard let self = self else { return }
let byteCountformatted = AppContext.byteCountFormatter.string(fromByteCount: Int64(byteCount)) let byteCountFormatted = AppContext.byteCountFormatter.string(fromByteCount: Int64(byteCount))
let alertController = UIAlertController( let alertController = UIAlertController(
title: L10n.Common.Alerts.CleanCache.title, title: L10n.Common.Alerts.CleanCache.title,
message: L10n.Common.Alerts.CleanCache.message(byteCountformatted), message: L10n.Common.Alerts.CleanCache.message(byteCountFormatted),
preferredStyle: .alert preferredStyle: .alert
) )
let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil) let okAction = UIAlertAction(title: L10n.Common.Controls.Actions.ok, style: .default, handler: nil)
@ -537,6 +541,13 @@ extension SettingsViewController: ActiveLabelDelegate {
} }
} }
// MARK: - ASAuthorizationControllerPresentationContextProviding
extension SettingsViewController: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return view.window!
}
}
// MARK: - UIAdaptivePresentationControllerDelegate // MARK: - UIAdaptivePresentationControllerDelegate
extension SettingsViewController: UIAdaptivePresentationControllerDelegate { extension SettingsViewController: UIAdaptivePresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {

View File

@ -12,12 +12,14 @@ import Foundation
import MastodonSDK import MastodonSDK
import UIKit import UIKit
import os.log import os.log
import AuthenticationServices
class SettingsViewModel { class SettingsViewModel {
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
let context: AppContext let context: AppContext
var mastodonAuthenticationController: MastodonAuthenticationController?
// input // input
let setting: CurrentValueSubject<Setting, Never> let setting: CurrentValueSubject<Setting, Never>
@ -86,6 +88,20 @@ class SettingsViewModel {
extension SettingsViewModel { extension SettingsViewModel {
func openAuthenticationPage(
authenticateURL: URL,
presentationContextProvider: ASWebAuthenticationPresentationContextProviding
) {
let authenticationController = MastodonAuthenticationController(
context: self.context,
authenticateURL: authenticateURL
)
self.mastodonAuthenticationController = authenticationController
authenticationController.authenticationSession?.presentationContextProvider = presentationContextProvider
authenticationController.authenticationSession?.start()
}
// MARK: - Private methods // MARK: - Private methods
private func processDataSource(_ setting: Setting) { private func processDataSource(_ setting: Setting) {
guard let dataSource = self.dataSource else { return } guard let dataSource = self.dataSource else { return }
@ -117,6 +133,7 @@ extension SettingsViewModel {
// boring zone // boring zone
let boringZoneSettingsItems: [SettingsItem] = { let boringZoneSettingsItems: [SettingsItem] = {
let links: [SettingsItem.Link] = [ let links: [SettingsItem.Link] = [
.accountSettings,
.termsOfService, .termsOfService,
.privacyPolicy .privacyPolicy
] ]