Skip to content

Commit

Permalink
- Branding: add support for branding.theme-tint-color to allow provid…
Browse files Browse the repository at this point in the history
…ing a tint color to replace the standard iOS tint color
  • Loading branch information
felix-schwarz committed Oct 23, 2023
1 parent 0327736 commit cf90b7e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
23 changes: 19 additions & 4 deletions ownCloudAppShared/Branding/Branding+App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ extension OCClassSettingsKey {
public static let profileDefinitions : OCClassSettingsKey = OCClassSettingsKey("profile-definitions")

// Themes
public static let themeGenericColors : OCClassSettingsKey = OCClassSettingsKey("theme-generic-colors")
public static let themeDefinitions : OCClassSettingsKey = OCClassSettingsKey("theme-definitions")
public static let themeGenericColors: OCClassSettingsKey = OCClassSettingsKey("theme-generic-colors")
public static let themeDefinitions: OCClassSettingsKey = OCClassSettingsKey("theme-definitions")
public static let themeTintColor: OCClassSettingsKey = OCClassSettingsKey("theme-tint-color")
}

extension Branding : BrandingInitialization {
Expand Down Expand Up @@ -168,6 +169,14 @@ extension Branding : BrandingInitialization {
.status : OCClassSettingsKeyStatus.advanced
],

.themeTintColor : [
.type : OCClassSettingsMetadataType.string,
.label : "Theme Tint Color",
.description : "Color in hex notation that should be used as tint color instead of the standard system tint color that is used throughout the app for buttons and other controls. This color is only used if no themes are defined otherwise.",
.category : "Branding",
.status : OCClassSettingsKeyStatus.advanced
],

.profileBookmarkName : [
.type : OCClassSettingsMetadataType.string,
.label : "Bookmark Name",
Expand Down Expand Up @@ -437,8 +446,14 @@ extension Branding {
}
}
} else if isBranded {
brandingThemeStyles.append(ThemeStyle.systemLight)
brandingThemeStyles.append(ThemeStyle.systemDark)
var tintColor: UIColor?

if let tintColorString = self.computedValue(forClassSettingsKey: .themeTintColor) as? String {
tintColor = tintColorString.colorFromHex
}

brandingThemeStyles.append(ThemeStyle.systemLight(with: tintColor))
brandingThemeStyles.append(ThemeStyle.systemDark(with: tintColor))
allowThemeSelection = true
}

Expand Down
8 changes: 5 additions & 3 deletions ownCloudAppShared/User Interface/Theme/ThemeCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public class ThemeCollection : NSObject {
return colorPairs
}

init(darkBrandColor inDarkColor: UIColor, lightBrandColor inLightColor: UIColor, style: ThemeCollectionStyle = .dark, customColors: NSDictionary? = nil, genericColors: NSDictionary? = nil, interfaceStyles: NSDictionary? = nil, useSystemColors: Bool = false) {
init(darkBrandColor inDarkColor: UIColor, lightBrandColor inLightColor: UIColor, style: ThemeCollectionStyle = .dark, customColors: NSDictionary? = nil, genericColors: NSDictionary? = nil, interfaceStyles: NSDictionary? = nil, useSystemColors: Bool = false, systemTintColor: UIColor? = nil) {
var logoFillColor : UIColor?

self.css = ThemeCSS()
Expand All @@ -223,6 +223,8 @@ public class ThemeCollection : NSObject {
let darkBrandColor = inDarkColor.resolvedColor(with: styleTraitCollection)
let lightBrandColor = inLightColor.resolvedColor(with: styleTraitCollection)

let resolvedSystemTintColor: UIColor = systemTintColor ?? .tintColor.resolvedColor(with: styleTraitCollection)

/*
Cells:
- cell -> lightCell
Expand Down Expand Up @@ -333,7 +335,7 @@ public class ThemeCollection : NSObject {
contentToolbarSet = cellSet

sidebarCellStateSet = ThemeColorStateSet.from(colorSet: darkBrandSet, for: interfaceStyle)
sidebarCellStateSet.selected.backgroundColor = useSystemColors ? .tintColor.resolvedColor(with: styleTraitCollection) : sidebarCellStateSet.regular.labelColor
sidebarCellStateSet.selected.backgroundColor = useSystemColors ? resolvedSystemTintColor : sidebarCellStateSet.regular.labelColor
sidebarCellStateSet.selected.labelColor = useSystemColors ? .white : sidebarCellStateSet.regular.backgroundColor
sidebarCellStateSet.selected.iconColor = sidebarCellStateSet.selected.labelColor

Expand Down Expand Up @@ -394,7 +396,7 @@ public class ThemeCollection : NSObject {
sidebarCellStateSet.regular.backgroundColor = .secondarySystemBackground.resolvedColor(with: styleTraitCollection)
sidebarCellStateSet.selected.labelColor = .white
sidebarCellStateSet.selected.iconColor = .white
sidebarCellStateSet.selected.backgroundColor = useSystemColors ? .tintColor.resolvedColor(with: styleTraitCollection) : darkBrandColor
sidebarCellStateSet.selected.backgroundColor = useSystemColors ? resolvedSystemTintColor : darkBrandColor

sidebarLogoIconColor = darkBrandColor
sidebarLogoLabel = darkBrandColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ extension ThemeStyle {
return (ThemeStyle(styleIdentifier: "com.owncloud.dark", localizedName: "Dark".localized, lightColor: .ownCloudLightColor, darkColor: .ownCloudDarkColor, themeStyle: .dark))
}

static public var systemLight : ThemeStyle {
return (ThemeStyle(styleIdentifier: "system.light", darkStyleIdentifier: "system.dark", localizedName: VendorServices.shared.isBranded ? "Light".localized : "System Light".localized, lightColor: .tintColor, darkColor: .label, themeStyle: .light, useSystemColors: true))
static public func systemLight(with tintColor: UIColor? = nil) -> ThemeStyle {
return (ThemeStyle(styleIdentifier: "system.light", darkStyleIdentifier: "system.dark", localizedName: VendorServices.shared.isBranded ? "Light".localized : "System Light".localized, lightColor: tintColor ?? .tintColor, darkColor: .label, themeStyle: .light, useSystemColors: true, systemTintColor: tintColor))
}
static public var systemDark : ThemeStyle {
return (ThemeStyle(styleIdentifier: "system.dark", localizedName: VendorServices.shared.isBranded ? "Dark".localized : "System Dark".localized, lightColor: .tintColor, darkColor: .secondarySystemGroupedBackground, themeStyle: .dark, useSystemColors: true))
static public func systemDark(with tintColor: UIColor? = nil) -> ThemeStyle {
return (ThemeStyle(styleIdentifier: "system.dark", localizedName: VendorServices.shared.isBranded ? "Dark".localized : "System Dark".localized, lightColor: tintColor ?? .tintColor, darkColor: .secondarySystemGroupedBackground, themeStyle: .dark, useSystemColors: true, systemTintColor: tintColor))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ extension ThemeStyle {
if !Branding.shared.setupThemeStyles() {
OCExtensionManager.shared.addExtension(ThemeStyle.ownCloudLight.themeStyleExtension(isDefault: true))
OCExtensionManager.shared.addExtension(ThemeStyle.ownCloudDark.themeStyleExtension())
OCExtensionManager.shared.addExtension(ThemeStyle.systemLight.themeStyleExtension())
OCExtensionManager.shared.addExtension(ThemeStyle.systemDark.themeStyleExtension())
OCExtensionManager.shared.addExtension(ThemeStyle.systemLight().themeStyleExtension())
OCExtensionManager.shared.addExtension(ThemeStyle.systemDark().themeStyleExtension())
}
}

Expand Down
6 changes: 4 additions & 2 deletions ownCloudAppShared/User Interface/Theme/ThemeStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ public class ThemeStyle : NSObject {
public var styles : NSDictionary?

public var useSystemColors: Bool
public var systemTintColor: UIColor?

public var cssRecordStrings: [String]?

public init(styleIdentifier: String, darkStyleIdentifier darkIdentifier: String? = nil, localizedName name: String, lightColor lColor: UIColor, darkColor dColor: UIColor, themeStyle style: ThemeCollectionStyle = .light, useSystemColors: Bool = false, customColors: NSDictionary? = nil, genericColors: NSDictionary? = nil, interfaceStyles: NSDictionary? = nil, cssRecordStrings: [String]? = nil) {
public init(styleIdentifier: String, darkStyleIdentifier darkIdentifier: String? = nil, localizedName name: String, lightColor lColor: UIColor, darkColor dColor: UIColor, themeStyle style: ThemeCollectionStyle = .light, useSystemColors: Bool = false, systemTintColor: UIColor? = nil, customColors: NSDictionary? = nil, genericColors: NSDictionary? = nil, interfaceStyles: NSDictionary? = nil, cssRecordStrings: [String]? = nil) {
self.identifier = styleIdentifier
self.darkStyleIdentifier = darkIdentifier
self.localizedName = name
self.lightColor = lColor
self.darkColor = dColor
self.themeStyle = style
self.useSystemColors = useSystemColors
self.systemTintColor = systemTintColor
self.customColors = customColors
self.genericColors = genericColors
self.styles = interfaceStyles
Expand Down Expand Up @@ -110,7 +112,7 @@ public extension ThemeCSSRecord {

public extension ThemeCollection {
convenience init(with style: ThemeStyle) {
self.init(darkBrandColor: style.darkColor, lightBrandColor: style.lightColor, style: style.themeStyle, customColors: style.customColors, genericColors: style.genericColors, interfaceStyles: style.styles, useSystemColors: style.useSystemColors)
self.init(darkBrandColor: style.darkColor, lightBrandColor: style.lightColor, style: style.themeStyle, customColors: style.customColors, genericColors: style.genericColors, interfaceStyles: style.styles, useSystemColors: style.useSystemColors, systemTintColor: style.systemTintColor)

if let cssRecordStrings = style.cssRecordStrings, let records = ThemeCSSRecord.from(cssRecordStrings) {
css.add(records: records)
Expand Down

0 comments on commit cf90b7e

Please sign in to comment.