@@ -16,6 +16,26 @@ import TGUIKit
1616import InAppSettings
1717
1818
19+ func generatePeerNameColorImage( _ peer: Peer ? ) -> CGImage {
20+ let attr = NSMutableAttributedString ( )
21+ let color = peer? . nameColor ?? . blue
22+
23+ _ = attr. append ( string: ( peer? . compactDisplayTitle ?? " " ) . prefixWithDots ( 15 ) , color: color. color, font: . avatar( . short) )
24+ let textNode = TextNode . layoutText ( attr, nil , 1 , . end, NSMakeSize ( . greatestFiniteMagnitude, 20 ) , nil , false , . center)
25+
26+ var size = textNode. 0 . size
27+ size. width += 16
28+ size. height += 8
29+ return generateImage ( size, rotatedContext: { size, ctx in
30+ let rect = NSMakeRect ( 0 , 0 , size. width, size. height)
31+ ctx. clear ( rect)
32+ ctx. round ( rect. size, size. height / 2 )
33+ ctx. setFillColor ( color. color. withAlphaComponent ( 0.1 ) . cgColor)
34+ ctx. fill ( rect)
35+ textNode. 1 . draw ( rect. focus ( textNode. 0 . size) , in: ctx, backingScaleFactor: System . backingScale, backgroundColor: . clear)
36+ } ) !
37+ }
38+
1939private extension TelegramBuiltinTheme {
2040 var baseTheme : TelegramBaseTheme {
2141 switch self {
@@ -148,7 +168,8 @@ private final class AppAppearanceViewArguments {
148168 let shareLocal : ( ColorPalette ) -> Void
149169 let toggleDarkMode : ( Bool ) -> Void
150170 let toggleRevealThemes : ( ) -> Void
151- init ( context: AccountContext , togglePalette: @escaping ( InstallThemeSource ) -> Void , toggleBubbles: @escaping ( Bool ) -> Void , toggleFontSize: @escaping ( CGFloat ) -> Void , selectAccentColor: @escaping ( AppearanceAccentColor ? ) -> Void , selectChatBackground: @escaping ( ) -> Void , openAutoNightSettings: @escaping ( ) -> Void , removeTheme: @escaping ( TelegramTheme ) -> Void , editTheme: @escaping ( TelegramTheme ) -> Void , shareTheme: @escaping ( TelegramTheme ) -> Void , shareLocal: @escaping ( ColorPalette ) -> Void , toggleDarkMode: @escaping ( Bool ) -> Void , toggleRevealThemes: @escaping ( ) -> Void ) {
171+ let userNameColor : ( ) -> Void
172+ init ( context: AccountContext , togglePalette: @escaping ( InstallThemeSource ) -> Void , toggleBubbles: @escaping ( Bool ) -> Void , toggleFontSize: @escaping ( CGFloat ) -> Void , selectAccentColor: @escaping ( AppearanceAccentColor ? ) -> Void , selectChatBackground: @escaping ( ) -> Void , openAutoNightSettings: @escaping ( ) -> Void , removeTheme: @escaping ( TelegramTheme ) -> Void , editTheme: @escaping ( TelegramTheme ) -> Void , shareTheme: @escaping ( TelegramTheme ) -> Void , shareLocal: @escaping ( ColorPalette ) -> Void , toggleDarkMode: @escaping ( Bool ) -> Void , toggleRevealThemes: @escaping ( ) -> Void , userNameColor: @escaping ( ) -> Void ) {
152173 self . context = context
153174 self . togglePalette = togglePalette
154175 self . toggleBubbles = toggleBubbles
@@ -162,6 +183,7 @@ private final class AppAppearanceViewArguments {
162183 self . shareLocal = shareLocal
163184 self . toggleDarkMode = toggleDarkMode
164185 self . toggleRevealThemes = toggleRevealThemes
186+ self . userNameColor = userNameColor
165187 }
166188}
167189
@@ -178,6 +200,7 @@ private let _id_theme_night_mode = InputDataIdentifier("_id_theme_night_mode")
178200
179201private let _id_cloud_themes = InputDataIdentifier ( " _id_cloud_themes " )
180202
203+ private let _id_name_color = InputDataIdentifier ( " _id_name_color " )
181204
182205private func appAppearanceEntries( appearance: Appearance , state: State , settings: ThemePaletteSettings , cloudThemes: [ TelegramTheme ] , generated: CloudThemesCachedData , autoNightSettings: AutoNightThemePreferences , animatedEmojiStickers: [ String : StickerPackItem ] , arguments: AppAppearanceViewArguments ) -> [ InputDataEntry ] {
183206
@@ -203,21 +226,7 @@ private func appAppearanceEntries(appearance: Appearance, state: State, settings
203226 cloudThemes. append ( cloud)
204227 }
205228 }
206-
207- // var smartThemesList:[SmartThemeCachedData] = []
208- // var values:[SmartThemeCachedData] = generated.list[.init(base: appearance.presentation.colors.parent.baseTheme, bubbled: appearance.presentation.bubbled)] ?? []
209- // if let value = generated.default {
210- // smartThemesList.append(value)
211- // }
212- // if values.isEmpty {
213- // values = generated.list[.init(base: appearance.presentation.dark ? .night : .classic, bubbled: appearance.presentation.bubbled)] ?? []
214- // }
215- // for smartTheme in values {
216- // smartThemesList.append(smartTheme)
217- // }
218- // if let custom = generated.custom {
219- // smartThemesList.append(custom)
220- // }
229+
221230
222231 if appearance. presentation. cloudTheme == nil || appearance. presentation. cloudTheme? . settings != nil {
223232 let copy = cloudThemes
@@ -347,18 +356,24 @@ private func appAppearanceEntries(appearance: Appearance, state: State, settings
347356 } ) ) )
348357 index += 1
349358
359+
350360
351- entries. append ( . general( sectionId: sectionId, index: index, value: . none, error: nil , identifier: _id_theme_chat_mode, data: InputDataGeneralData ( name: strings ( ) . appearanceSettingsBubblesMode, color: appearance. presentation. colors. text, type: . switchable( appearance. presentation. bubbled) , viewType: appearance. presentation. bubbled ? . innerItem : . lastItem, action: {
361+
362+ entries. append ( . general( sectionId: sectionId, index: index, value: . none, error: nil , identifier: _id_theme_chat_mode, data: InputDataGeneralData ( name: strings ( ) . appearanceSettingsBubblesMode, color: appearance. presentation. colors. text, type: . switchable( appearance. presentation. bubbled) , viewType: . innerItem, action: {
352363 arguments. toggleBubbles ( !appearance. presentation. bubbled)
353364 } ) ) )
354365 index += 1
355366
356367
357368 if appearance. presentation. bubbled {
358- entries. append ( . general( sectionId: sectionId, index: index, value: . none, error: nil , identifier: _id_theme_wallpaper1, data: InputDataGeneralData ( name: strings ( ) . generalSettingsChatBackground, color: appearance. presentation. colors. text, type: . next, viewType: . lastItem , action: arguments. selectChatBackground) ) )
369+ entries. append ( . general( sectionId: sectionId, index: index, value: . none, error: nil , identifier: _id_theme_wallpaper1, data: InputDataGeneralData ( name: strings ( ) . generalSettingsChatBackground, color: appearance. presentation. colors. text, type: . next, viewType: . innerItem , action: arguments. selectChatBackground) ) )
359370 index += 1
360371 }
361372
373+ entries. append ( . general( sectionId: sectionId, index: index, value: . none, error: nil , identifier: _id_name_color, data: InputDataGeneralData ( name: strings ( ) . appearanceYourNameColor, color: appearance. presentation. colors. text, type: . imageContext( generatePeerNameColorImage ( state. myPeer) , " " ) , viewType: . lastItem, action: arguments. userNameColor) ) )
374+ index += 1
375+
376+
362377 entries. append ( . sectionId( sectionId, type: . normal) )
363378 sectionId += 1
364379
@@ -404,6 +419,7 @@ private func appAppearanceEntries(appearance: Appearance, state: State, settings
404419
405420private struct State : Equatable {
406421 var revealed : Bool
422+ var myPeer : TelegramUser ?
407423}
408424
409425func AppAppearanceViewController( context: AccountContext , focusOnItemTag: ThemeSettingsEntryTag ? = nil ) -> InputDataController {
@@ -412,6 +428,9 @@ func AppAppearanceViewController(context: AccountContext, focusOnItemTag: ThemeS
412428 let updateDisposable = MetaDisposable ( )
413429
414430
431+ let actionsDisposable = DisposableSet ( )
432+
433+
415434 let initialState = State ( revealed: false )
416435
417436 let statePromise = ValuePromise ( initialState, ignoreRepeated: true )
@@ -420,6 +439,13 @@ func AppAppearanceViewController(context: AccountContext, focusOnItemTag: ThemeS
420439 statePromise. set ( stateValue. modify ( f) )
421440 }
422441
442+ actionsDisposable. add ( getPeerView ( peerId: context. peerId, postbox: context. account. postbox) . start ( next: { peer in
443+ updateState { current in
444+ var current = current
445+ current. myPeer = peer as? TelegramUser
446+ return current
447+ }
448+ } ) )
423449
424450 let applyTheme : ( InstallThemeSource ) -> Void = { source in
425451 switch source {
@@ -569,6 +595,8 @@ func AppAppearanceViewController(context: AccountContext, focusOnItemTag: ThemeS
569595 current. revealed = !current. revealed
570596 return current
571597 }
598+ } , userNameColor: {
599+ context. bindings. rootNavigation ( ) . push ( SelectColorController ( context: context, source: . account( context. myPeer!) ) )
572600 } )
573601
574602
@@ -665,6 +693,10 @@ func AppAppearanceViewController(context: AccountContext, focusOnItemTag: ThemeS
665693 controller. genericView. tableView. needUpdateVisibleAfterScroll = true
666694 }
667695
696+ controller. onDeinit = {
697+ actionsDisposable. dispose ( )
698+ }
699+
668700 return controller
669701}
670702
0 commit comments