diff --git a/Swiftgram/SGAPIWebSettings/Sources/File.swift b/Swiftgram/SGAPIWebSettings/Sources/File.swift index bfb022afaa..f29a97c990 100644 --- a/Swiftgram/SGAPIWebSettings/Sources/File.swift +++ b/Swiftgram/SGAPIWebSettings/Sources/File.swift @@ -15,6 +15,7 @@ public func updateSGWebSettingsInteractivelly(context: AccountContext) { SGLogger.shared.log("SGAPI", "New SGWebSettings for id \(context.account.peerId.id._internalGetInt64Value()): \(webSettings) ") SGSimpleSettings.shared.canUseStealthMode = webSettings.global.storiesAvailable SGSimpleSettings.shared.duckyAppIconAvailable = webSettings.global.duckyAppIconAvailable + SGSimpleSettings.shared.canUseNY = webSettings.global.nyAvailable let _ = (context.account.postbox.transaction { transaction in updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in var configuration = configuration diff --git a/Swiftgram/SGNY/BUILD b/Swiftgram/SGNY/BUILD new file mode 100644 index 0000000000..3228a543d9 --- /dev/null +++ b/Swiftgram/SGNY/BUILD @@ -0,0 +1,15 @@ +filegroup( + name = "SGNY", + srcs = glob([ + "Sources/**/*.swift", + ]), + visibility = [ + "//visibility:public", + ], +) + +filegroup( + name = "SGNYAssets", + srcs = glob(["Images.xcassets/**"]), + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/Contents.json b/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/Contents.json new file mode 100644 index 0000000000..3a7a8bfeab --- /dev/null +++ b/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "SGSnowflake.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/SGSnowflake.png b/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/SGSnowflake.png new file mode 100644 index 0000000000..f781e57161 Binary files /dev/null and b/Swiftgram/SGNY/Images.xcassets/SGSnowflake.imageset/SGSnowflake.png differ diff --git a/Swiftgram/SGNY/Sources/SGNY.swift b/Swiftgram/SGNY/Sources/SGNY.swift new file mode 100644 index 0000000000..f34c91443d --- /dev/null +++ b/Swiftgram/SGNY/Sources/SGNY.swift @@ -0,0 +1,66 @@ +import Foundation +import UIKit +import AsyncDisplayKit +import Display +import SGSimpleSettings + + +class WallpaperNYNode: ASDisplayNode { + private var emitterLayer: CAEmitterLayer? + + func updateLayout(size: CGSize) { + if self.emitterLayer == nil { + let particlesLayer = CAEmitterLayer() + self.emitterLayer = particlesLayer + + self.layer.addSublayer(particlesLayer) + self.layer.masksToBounds = true + + particlesLayer.backgroundColor = UIColor.clear.cgColor + particlesLayer.emitterShape = .circle + particlesLayer.emitterMode = .surface + particlesLayer.renderMode = .oldestLast + + let cell1 = CAEmitterCell() + switch SGSimpleSettings.shared.nyStyle { + case SGSimpleSettings.NYStyle.lightning.rawValue: + // cell1.contents = generateTintedImage(image: UIImage(bundleImageName: "SwiftgramContextMenu"), color: .white) + cell1.contents = UIImage(bundleImageName: "SwiftgramContextMenu")?.cgImage + cell1.name = "lightning" + cell1.scale = 0.15 + cell1.scaleRange = 0.25 + default: + cell1.contents = UIImage(bundleImageName: "SGSnowflake")?.cgImage + cell1.name = "snow" + cell1.scale = 0.04 + cell1.scaleRange = 0.15 + } + cell1.birthRate = 202.0 + cell1.lifetime = 70.0 + cell1.velocity = 1.0 + cell1.velocityRange = -1.5 + cell1.xAcceleration = 0.33 + cell1.yAcceleration = 1.0 + cell1.emissionRange = .pi + cell1.spin = -28.6 * (.pi / 180.0) + cell1.spinRange = 57.2 * (.pi / 180.0) + cell1.color = UIColor.white.withAlphaComponent(0.58).cgColor +// cell1.alphaRange = -0.2 + + particlesLayer.emitterCells = [cell1] + } + + if let emitterLayer = self.emitterLayer { + var emitterWidthK: CGFloat = 2.5 + switch SGSimpleSettings.shared.nyStyle { + case SGSimpleSettings.NYStyle.lightning.rawValue: + emitterWidthK = 5.0 + default: + break + } + emitterLayer.emitterPosition = CGPoint(x: size.width * 0.40, y: -size.height / 2.0) + emitterLayer.emitterSize = CGSize(width: size.width * emitterWidthK, height: size.height) + emitterLayer.frame = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height) + } + } +} diff --git a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift index 650c8cf488..fdf3c60ddc 100644 --- a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift +++ b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift @@ -27,6 +27,7 @@ import UndoUI private enum SGControllerSection: Int32, SGItemListSection { case search + case trending case content case tabs case folders @@ -103,6 +104,7 @@ private enum SGBoolSetting: String { } private enum SGOneFromManySetting: String { + case nyStyle case bottomTabStyle case downloadSpeedBoost case allChatsTitleLengthOverride @@ -143,6 +145,17 @@ private func SGControllerEntries(presentationData: PresentationData, callListSet let id = SGItemListCounter() entries.append(.searchInput(id: id.count, section: .search, title: NSAttributedString(string: "🔍"), text: state.searchQuery ?? "", placeholder: strings.Common_Search)) + + +// if SGSimpleSettings.shared.canUseNY { + if "".isEmpty { + entries.append(.header(id: id.count, section: .trending, text: i18n("Settings.NY.Header", lang), badge: nil)) + entries.append(.oneFromManySelector(id: id.count, section: .trending, settingName: .nyStyle, text: i18n("Settings.NY.Style", lang), value: i18n("Settings.NY.Style.\(SGSimpleSettings.shared.nyStyle)", lang), enabled: true)) + entries.append(.notice(id: id.count, section: .trending, text: i18n("Settings.NY.Notice", lang))) + } else { + id.increment(3) + } + if appConfiguration.sgWebSettings.global.canEditSettings { entries.append(.disclosure(id: id.count, section: .content, link: .contentSettings, text: i18n("Settings.ContentSettings", lang))) } else { @@ -648,6 +661,18 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int? setAction(value.rawValue) })) } + case .nyStyle: + let setAction: (String) -> Void = { value in + SGSimpleSettings.shared.nyStyle = value + simplePromise.set(true) + } + + for value in SGSimpleSettings.NYStyle.allCases { + items.append(ActionSheetButtonItem(title: i18n("Settings.NY.Style.\(value.rawValue)", presentationData.strings.baseLanguageCode), color: .accent, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + setAction(value.rawValue) + })) + } } actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ diff --git a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift index 220d357d72..b7ed1384dd 100644 --- a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift +++ b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift @@ -152,6 +152,8 @@ public class SGSimpleSettings { case transcriptionBackend case translationBackend case customAppBadge + case canUseNY + case nyStyle } public enum DownloadSpeedBoostValues: String, CaseIterable { @@ -212,6 +214,12 @@ public class SGSimpleSettings { case silenced case disabled } + + public enum NYStyle: String, CaseIterable { + case `default` + case snow + case lightning + } public static let defaultValues: [String: Any] = [ Keys.hidePhoneInSettings.rawValue: true, @@ -282,6 +290,8 @@ public class SGSimpleSettings { Keys.transcriptionBackend.rawValue: TranscriptionBackend.default.rawValue, Keys.translationBackend.rawValue: TranslationBackend.default.rawValue, Keys.customAppBadge.rawValue: "", + Keys.canUseNY.rawValue: false, + Keys.nyStyle.rawValue: NYStyle.snow.rawValue, ] public static let groupDefaultValues: [String: Any] = [ @@ -518,6 +528,12 @@ public class SGSimpleSettings { @UserDefault(key: Keys.customAppBadge.rawValue) public var customAppBadge: String + + @UserDefault(key: Keys.canUseNY.rawValue) + public var canUseNY: Bool + + @UserDefault(key: Keys.nyStyle.rawValue) + public var nyStyle: String } extension SGSimpleSettings { @@ -540,6 +556,12 @@ extension SGSimpleSettings { } } +extension SGSimpleSettings { + public var isNYEnabled: Bool { + return /*canUseNY && */ NYStyle(rawValue: nyStyle) != .default + } +} + public func getSGDownloadPartSize(_ default: Int64, fileSize: Int64?) -> Int64 { let currentDownloadSetting = SGSimpleSettings.shared.downloadSpeedBoost // Increasing chunk size for small files make it worse in terms of overall download performance diff --git a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings index c2f6ea56a2..af4901b978 100644 --- a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings +++ b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings @@ -262,3 +262,10 @@ "AppBadge.Title" = "App Badge"; "AppBadge.Notice" = "Customize App Badge shown on screenshots"; + +"Settings.NY.Header" = "HOLIDAY EFFECTS"; +"Settings.NY.Style" = "Style"; +"Settings.NY.Style.default" = "Disabled"; +"Settings.NY.Style.snow" = "Snow"; +"Settings.NY.Style.lightning" = "Swiftgram"; +"Settings.NY.Notice" = "Available for a limited time only!"; diff --git a/Swiftgram/SGWebSettingsScheme/Sources/File.swift b/Swiftgram/SGWebSettingsScheme/Sources/File.swift index b8e976e99f..981676a898 100644 --- a/Swiftgram/SGWebSettingsScheme/Sources/File.swift +++ b/Swiftgram/SGWebSettingsScheme/Sources/File.swift @@ -5,7 +5,7 @@ public struct SGWebSettings: Codable, Equatable { public let user: SGUserSettings public static var defaultValue: SGWebSettings { - return SGWebSettings(global: SGGlobalSettings(ytPip: true, qrLogin: true, storiesAvailable: false, canViewMessages: true, canEditSettings: false, canShowTelescope: false, announcementsData: nil, regdateFormat: "month", botMonkeys: [], forceReasons: [], unforceReasons: [], paymentsEnabled: true, duckyAppIconAvailable: true, canGrant: false, proSupportUrl: nil), user: SGUserSettings(contentReasons: [], canSendTelescope: false, canBuyInBeta: true)) + return SGWebSettings(global: SGGlobalSettings(ytPip: true, qrLogin: true, storiesAvailable: false, canViewMessages: true, canEditSettings: false, canShowTelescope: false, announcementsData: nil, regdateFormat: "month", botMonkeys: [], forceReasons: [], unforceReasons: [], paymentsEnabled: true, duckyAppIconAvailable: true, canGrant: false, proSupportUrl: nil, nyAvailable: false), user: SGUserSettings(contentReasons: [], canSendTelescope: false, canBuyInBeta: true)) } } @@ -25,6 +25,7 @@ public struct SGGlobalSettings: Codable, Equatable { public let duckyAppIconAvailable: Bool public let canGrant: Bool public let proSupportUrl: String? + public let nyAvailable: Bool } public struct SGBotMonkeys: Codable, Equatable { diff --git a/Telegram/BUILD b/Telegram/BUILD index fd9e0ce46b..ab569422b1 100644 --- a/Telegram/BUILD +++ b/Telegram/BUILD @@ -357,7 +357,7 @@ objc_library( ], ) -SGRESOURCES = ["//Swiftgram/SGSettingsUI:SGUIAssets", "//Swiftgram/SGPayWall:SGPayWallAssets", "//Swiftgram/SGAppBadgeAssets:SGAppBadgeAssets"] +SGRESOURCES = ["//Swiftgram/SGSettingsUI:SGUIAssets", "//Swiftgram/SGPayWall:SGPayWallAssets", "//Swiftgram/SGAppBadgeAssets:SGAppBadgeAssets", "//Swiftgram/SGNY:SGNYAssets"] swift_library( name = "Lib", diff --git a/submodules/WallpaperBackgroundNode/BUILD b/submodules/WallpaperBackgroundNode/BUILD index ccd9dff870..4176731a49 100644 --- a/submodules/WallpaperBackgroundNode/BUILD +++ b/submodules/WallpaperBackgroundNode/BUILD @@ -40,19 +40,27 @@ apple_resource_bundle( ], ) +sgdeps = [ + "//Swiftgram/SGSimpleSettings:SGSimpleSettings", +] + +sgsrcs = [ + "//Swiftgram/SGNY:SGNY" +] + swift_library( name = "WallpaperBackgroundNode", module_name = "WallpaperBackgroundNode", srcs = glob([ "Sources/**/*.swift", - ]), + ]) + sgsrcs, copts = [ "-warnings-as-errors", ], data = [ ":WallpaperBackgroundNodeBundle", ], - deps = [ + deps = sgdeps + [ "//submodules/AsyncDisplayKit:AsyncDisplayKit", "//submodules/Display:Display", "//submodules/GradientBackground:GradientBackground", diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index 8c96748f85..e005628d1d 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -1,3 +1,4 @@ +import SGSimpleSettings import Foundation import UIKit import AsyncDisplayKit @@ -959,6 +960,10 @@ public final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgrou } } + // MARK: Swiftgram + private var NYNode: WallpaperNYNode? + // + private var imageContentMode: UIView.ContentMode { didSet { self.contentNode.contentMode = self.imageContentMode @@ -1597,7 +1602,9 @@ public final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgrou if isFirstLayout && !self.frame.isEmpty { self.updateScale() + /* MARK: Swiftgram */ if SGSimpleSettings.shared.isNYEnabled && self.NYNode == nil { let nYNode = WallpaperNYNode(); self.addSubnode(nYNode); self.NYNode = nYNode } } + /* MARK: Swiftgram */ self.NYNode?.frame = CGRect(origin: CGPoint(), size: size); self.NYNode?.updateLayout(size: size) } private var isAnimating = false