fix: use right privacyURL

- remove some redundancy code
This commit is contained in:
ihugo 2021-04-17 14:01:57 +08:00
parent 0ebf86bd43
commit 9be8b95aea
5 changed files with 18 additions and 24 deletions

View File

@ -9,7 +9,6 @@
import Foundation
import CoreData
@objc(SubscriptionAlerts)
public final class SubscriptionAlerts: NSManagedObject {
@NSManaged public var follow: NSNumber?
@NSManaged public var favourite: NSNumber?

View File

@ -44,22 +44,10 @@ extension UIButton {
}
extension UIButton {
// https://stackoverflow.com/questions/14523348/how-to-change-the-background-color-of-a-uibutton-while-its-highlighted
private func image(withColor color: UIColor) -> UIImage? {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
func setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
self.setBackgroundImage(image(withColor: color), for: state)
self.setBackgroundImage(
UIImage.placeholder(color: color),
for: state
)
}
}

View File

@ -311,8 +311,9 @@ extension SettingsViewController: UITableViewDelegate {
switch item {
case .boringZone:
guard let url = viewModel.privacyURL else { break }
coordinator.present(
scene: .safari(url: URL(string: "https://mastodon.online/terms")!),
scene: .safari(url: url),
from: self,
transition: .safariPresent(animated: true, completion: nil)
)
@ -345,11 +346,9 @@ extension SettingsViewController {
func updateTrigger(by who: String) {
guard let setting = self.viewModel.setting.value else { return }
context.managedObjectContext.performChanges {
_ = context.managedObjectContext.performChanges {
setting.update(triggerBy: who)
}
.sink { (_) in
}.store(in: &disposeBag)
}
func updateAlert(title: String?, isOn: Bool) {

View File

@ -70,6 +70,14 @@ class SettingsViewModel: NSObject, NeedsDependency {
noOne: noOneSwitchItems]
}()
lazy var privacyURL: URL? = {
guard let box = AppContext.shared.authenticationService.activeMastodonAuthenticationBox.value else {
return nil
}
return Mastodon.API.privacyURL(domain: box.domain)
}()
struct Input {
}

View File

@ -28,7 +28,7 @@ extension Mastodon.API.Subscriptions {
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - authorization: User token. Could be nil if status is public
/// - Returns: `AnyPublisher` contains `Poll` nested in the response
/// - Returns: `AnyPublisher` contains `Subscription` nested in the response
public static func subscription(
session: URLSession,
domain: String,
@ -61,7 +61,7 @@ extension Mastodon.API.Subscriptions {
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - authorization: User token. Could be nil if status is public
/// - Returns: `AnyPublisher` contains `Poll` nested in the response
/// - Returns: `AnyPublisher` contains `Subscription` nested in the response
public static func createSubscription(
session: URLSession,
domain: String,
@ -95,7 +95,7 @@ extension Mastodon.API.Subscriptions {
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - authorization: User token. Could be nil if status is public
/// - Returns: `AnyPublisher` contains `Poll` nested in the response
/// - Returns: `AnyPublisher` contains `Subscription` nested in the response
public static func updateSubscription(
session: URLSession,
domain: String,