mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-16 06:28:27 +02:00
Added BWIThemeService helper class
This commit is contained in:
@@ -338,7 +338,7 @@ class AllChatsViewController: HomeViewController {
|
||||
return
|
||||
}
|
||||
|
||||
let viewController = UIHostingController(rootView: IntroduceFederationView())
|
||||
let viewController = UIHostingController(rootView: IntroduceFederationView().environmentObject(BWIThemeService.shared))
|
||||
viewController.isModalInPresentation = true
|
||||
present(viewController, animated: true) {
|
||||
notificationService.setShowFederationIntroductionFlag(false)
|
||||
|
||||
@@ -23,7 +23,7 @@ import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class func makeViewController(session: MXSession) -> UIViewController {
|
||||
return UIHostingController(rootView: DeveloperSettingsView(session: session))
|
||||
return UIHostingController(rootView: DeveloperSettingsView(session: session).environmentObject(BWIThemeService.shared))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import SwiftUI
|
||||
struct DeveloperSettingsView: View {
|
||||
let session: MXSession?
|
||||
|
||||
@EnvironmentObject var themeService: BWIThemeService
|
||||
@State private var showAlert = false
|
||||
@State private var showAlertBirthdayCampaign = false
|
||||
@State private var permalinkPrefix: String? = UserDefaults.standard.string(forKey: "bwi_permalink_prefix")
|
||||
@@ -42,7 +43,7 @@ struct DeveloperSettingsView: View {
|
||||
SwiftUI.Section {
|
||||
Button(action: { showAlert = createNewPersonalNotesRoom(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperCreateNewPersonalNotesRoom)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
.alert(isPresented: $showAlert) {
|
||||
@@ -51,7 +52,7 @@ struct DeveloperSettingsView: View {
|
||||
|
||||
Button(action: { showAlert = resetMatomoInfoScreen(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperResetMatomoInfo)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
.alert(isPresented: $showAlert) {
|
||||
@@ -59,7 +60,7 @@ struct DeveloperSettingsView: View {
|
||||
}
|
||||
Button(action: { showAlertBirthdayCampaign = resetBirthdayCampaignScreen(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperSettingsResetBirthdayBanner)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
.alert(isPresented: $showAlertBirthdayCampaign) {
|
||||
@@ -67,34 +68,35 @@ struct DeveloperSettingsView: View {
|
||||
}
|
||||
Button(action: { _ = restrictUser(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperRestrictUser)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
Button(action: { _ = unrestrictUser(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperUnrestrictUser)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
Button(action: { _ = unmarkBannerVersion(mxSession: session) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperUnmarkBanner)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
}
|
||||
SwiftUI.Section(header: Text(BWIL10n.bwiSettingsDeveloperIntroduceFederation)) {
|
||||
Button(action: { showIntroduceFederation = true }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperIntroduceFederationPreview)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
.sheet(isPresented: $showIntroduceFederation) {
|
||||
IntroduceFederationView()
|
||||
.interactiveDismissDisabled()
|
||||
.environmentObject(BWIThemeService.shared)
|
||||
}
|
||||
if let session = session {
|
||||
Button(action: { BWIAccountNotificationService(mxSession: session).setShowFederationIntroductionFlag(true) }) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperIntroduceFederationReset)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
||||
.foregroundColor(Color(themeService.theme.tintColor))
|
||||
.font(.system(size: 17))
|
||||
}
|
||||
}
|
||||
@@ -172,7 +174,7 @@ fileprivate func resetMatomoInfoScreen(mxSession: MXSession?) -> Bool {
|
||||
guard let mxSession = mxSession else {
|
||||
return false
|
||||
}
|
||||
BWIAnalyticsAccountDataService(mxSession: mxSession)
|
||||
_ = BWIAnalyticsAccountDataService(mxSession: mxSession)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
import SwiftUI
|
||||
|
||||
struct IntroduceFederationScreen1: View {
|
||||
@EnvironmentObject var themeService: BWIThemeService
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .top) {
|
||||
Color(ThemeService.shared().theme.backgroundColor)
|
||||
Color(themeService.theme.backgroundColor)
|
||||
|
||||
VStack(spacing: 26) {
|
||||
ZStack {
|
||||
@@ -36,18 +38,18 @@ struct IntroduceFederationScreen1: View {
|
||||
.background(Color(hex: 0xE3E8F0))
|
||||
.clipShape(Circle())
|
||||
.padding(5) // outer border size
|
||||
.background(Color(ThemeService.shared().theme.backgroundColor))
|
||||
.background(Color(themeService.theme.backgroundColor))
|
||||
.clipShape(Circle())
|
||||
.frame(width: IntroduceFederationView.imageSize + 12, height: IntroduceFederationView.imageSize + 12)
|
||||
.padding(.trailing, 50)
|
||||
}
|
||||
.padding(.bottom, 42)
|
||||
Text(BWIL10n.introduceFederationScreen1Title)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 28, weight: .semibold))
|
||||
.multilineTextAlignment(.center)
|
||||
Text(BWIL10n.introduceFederationScreen1Description)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 17))
|
||||
.multilineTextAlignment(.center)
|
||||
Spacer()
|
||||
|
||||
@@ -18,22 +18,24 @@
|
||||
import SwiftUI
|
||||
|
||||
struct IntroduceFederationScreen2: View {
|
||||
@EnvironmentObject var themeService: BWIThemeService
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .top) {
|
||||
Color(ThemeService.shared().theme.backgroundColor)
|
||||
Color(themeService.theme.backgroundColor)
|
||||
|
||||
VStack(spacing: 26) {
|
||||
Image(uiImage: getImage(darkmode: ThemeService.shared().isCurrentThemeDark()))
|
||||
Image(uiImage: getImage(darkmode: themeService.isCurrentThemeDark))
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fit)
|
||||
.frame(height: IntroduceFederationView.imageSize + 12)
|
||||
.padding(.bottom, 42)
|
||||
Text(BWIL10n.introduceFederationScreen2Title)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 28, weight: .semibold))
|
||||
.multilineTextAlignment(.center)
|
||||
Text(BWIL10n.introduceFederationScreen2Description)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 17))
|
||||
.multilineTextAlignment(.center)
|
||||
Spacer()
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct IntroduceFederationScreen3: View {
|
||||
@EnvironmentObject var themeService: BWIThemeService
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
@@ -28,11 +29,11 @@ struct IntroduceFederationScreen3: View {
|
||||
.frame(height: IntroduceFederationView.topConstraintTitle)
|
||||
.padding(.bottom, 42)
|
||||
Text(BWIL10n.introduceFederationScreen3Title)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 28, weight: .semibold))
|
||||
.multilineTextAlignment(.center)
|
||||
Text(BWIL10n.introduceFederationScreen3Description)
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textPrimaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textPrimaryColor))
|
||||
.font(.system(size: 17))
|
||||
.multilineTextAlignment(.center)
|
||||
Spacer()
|
||||
|
||||
@@ -26,6 +26,7 @@ enum VisibleScreen {
|
||||
struct IntroduceFederationView: View {
|
||||
static let imageSize: CGFloat = 108
|
||||
static let topConstraintTitle: CGFloat = 390
|
||||
@EnvironmentObject var themeService: BWIThemeService
|
||||
@State var visibleScreen = VisibleScreen.screen1
|
||||
|
||||
var body: some View {
|
||||
@@ -36,7 +37,7 @@ struct IntroduceFederationView: View {
|
||||
}
|
||||
.tabViewStyle(.page(indexDisplayMode: .always))
|
||||
.background {
|
||||
Color(ThemeService.shared().theme.backgroundColor)
|
||||
Color(themeService.theme.backgroundColor)
|
||||
.edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
.overlay(alignment: .bottom) {
|
||||
@@ -44,7 +45,7 @@ struct IntroduceFederationView: View {
|
||||
if visibleScreen != .screen1 {
|
||||
Button(action: presentPreviousScreen) {
|
||||
Image(systemName: "arrow.left")
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textSecondaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textSecondaryColor))
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -52,7 +53,7 @@ struct IntroduceFederationView: View {
|
||||
if visibleScreen != .screen3 {
|
||||
Button(action: presentNextScreen) {
|
||||
Image(systemName: "arrow.right")
|
||||
.foregroundColor(Color(ThemeService.shared().theme.textSecondaryColor))
|
||||
.foregroundColor(Color(themeService.theme.textSecondaryColor))
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -65,8 +66,8 @@ struct IntroduceFederationView: View {
|
||||
}
|
||||
|
||||
private func setupIndicatorColors() {
|
||||
UIPageControl.appearance().currentPageIndicatorTintColor = ThemeService.shared().theme.textPrimaryColor
|
||||
UIPageControl.appearance().pageIndicatorTintColor = ThemeService.shared().theme.textSecondaryColor
|
||||
UIPageControl.appearance().currentPageIndicatorTintColor = themeService.theme.textPrimaryColor
|
||||
UIPageControl.appearance().pageIndicatorTintColor = themeService.theme.textSecondaryColor
|
||||
}
|
||||
|
||||
private func presentNextScreen() {
|
||||
|
||||
48
bwi/Tools/BWIThemeService.swift
Normal file
48
bwi/Tools/BWIThemeService.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
/*
|
||||
* Copyright (c) 2022 BWI GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
class BWIThemeService: ObservableObject {
|
||||
static let shared = BWIThemeService()
|
||||
@Published var themeId: String?
|
||||
@Published var theme: Theme
|
||||
@Published var isCurrentThemeDark: Bool
|
||||
var cancellable: Cancellable?
|
||||
|
||||
private init() {
|
||||
let service = ThemeService.shared()
|
||||
themeId = service.themeId
|
||||
theme = service.theme
|
||||
isCurrentThemeDark = service.isCurrentThemeDark()
|
||||
|
||||
cancellable = NotificationCenter.default
|
||||
.publisher(for: .themeServiceDidChangeTheme)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink() { _ in
|
||||
self.themeDidChange()
|
||||
}
|
||||
}
|
||||
|
||||
private func themeDidChange() {
|
||||
let service = ThemeService.shared()
|
||||
themeId = service.themeId
|
||||
theme = service.theme
|
||||
isCurrentThemeDark = service.isCurrentThemeDark()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user