diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 5069519402..44262dfbec 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1648,7 +1648,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController if case .undo = action, let self { let _ = updateMediaDownloadSettingsInteractively(accountManager: self.context.sharedContext.accountManager, { settings in var settings = settings - settings.energyUsageSettings.activationThreshold = 0 + settings.energyUsageSettings.activationThreshold = 4 return settings }).start() } diff --git a/submodules/Components/ReactionListContextMenuContent/Sources/ReactionListContextMenuContent.swift b/submodules/Components/ReactionListContextMenuContent/Sources/ReactionListContextMenuContent.swift index 4de82d3cd3..ec0df86aaf 100644 --- a/submodules/Components/ReactionListContextMenuContent/Sources/ReactionListContextMenuContent.swift +++ b/submodules/Components/ReactionListContextMenuContent/Sources/ReactionListContextMenuContent.swift @@ -94,7 +94,9 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent self.highlightBackgroundNode.frame = CGRect(origin: CGPoint(), size: size) - self.titleLabelNode.attributedText = NSAttributedString(string: presentationData.strings.Common_Back, font: Font.regular(17.0), textColor: presentationData.theme.contextMenu.primaryColor) + let titleFontSize = presentationData.listsFontSize.baseDisplaySize * 17.0 / 17.0 + + self.titleLabelNode.attributedText = NSAttributedString(string: presentationData.strings.Common_Back, font: Font.regular(titleFontSize), textColor: presentationData.theme.contextMenu.primaryColor) let titleSize = self.titleLabelNode.updateLayout(CGSize(width: size.width - sideInset - standardIconWidth, height: 100.0)) self.titleLabelNode.frame = CGRect(origin: CGPoint(x: sideInset + 36.0, y: floor((size.height - titleSize.height) / 2.0)), size: titleSize) @@ -587,7 +589,9 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent self.avatarNode.frame = CGRect(origin: CGPoint(x: avatarInset, y: floor((size.height - avatarSize) / 2.0)), size: CGSize(width: avatarSize, height: avatarSize)) self.avatarNode.setPeer(context: self.context, theme: presentationData.theme, peer: item.peer, synchronousLoad: true) - self.titleLabelNode.attributedText = NSAttributedString(string: item.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), font: Font.regular(17.0), textColor: presentationData.theme.contextMenu.primaryColor) + let titleFontSize = presentationData.listsFontSize.baseDisplaySize * 17.0 / 17.0 + + self.titleLabelNode.attributedText = NSAttributedString(string: item.peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), font: Font.regular(titleFontSize), textColor: presentationData.theme.contextMenu.primaryColor) var maxTextWidth: CGFloat = size.width - avatarInset - avatarSize - avatarSpacing - sideInset - additionalTitleInset if reaction != nil { maxTextWidth -= 32.0 @@ -622,7 +626,9 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent text = "yesterday at 12:00 PM" #endif*/ - self.textLabelNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: presentationData.theme.contextMenu.secondaryColor) + let textFontSize = presentationData.listsFontSize.baseDisplaySize * 15.0 / 17.0 + + self.textLabelNode.attributedText = NSAttributedString(string: text, font: Font.regular(textFontSize), textColor: presentationData.theme.contextMenu.secondaryColor) let textSize = self.textLabelNode.updateLayout(CGSize(width: maxTextWidth + 16.0, height: 100.0)) self.textLabelNode.isHidden = !self.displayReadTimestamps || text.isEmpty @@ -835,7 +841,15 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent if let size = self.currentSize { var apparentHeight = -self.scrollNode.view.contentOffset.y + self.scrollNode.view.contentSize.height - apparentHeight = max(apparentHeight, self.displayReadTimestamps ? 56.0 : 44.0) + + let heightFraction: CGFloat + if let presentationData = self.presentationData { + heightFraction = presentationData.listsFontSize.baseDisplaySize / 17.0 + } else { + heightFraction = 1.0 + } + + apparentHeight = max(apparentHeight, (self.displayReadTimestamps ? 56.0 : 44.0) * heightFraction) apparentHeight = min(apparentHeight, size.height + 100.0) if self.apparentHeight != apparentHeight { self.apparentHeight = apparentHeight @@ -852,7 +866,10 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent guard let presentationData = self.presentationData else { return } - let itemHeight: CGFloat = self.displayReadTimestamps ? 56.0 : 44.0 + + let heightFraction: CGFloat = presentationData.listsFontSize.baseDisplaySize / 17.0 + + let itemHeight: CGFloat = (self.displayReadTimestamps ? 56.0 : 44.0) * heightFraction let visibleBounds = self.scrollNode.bounds.insetBy(dx: 0.0, dy: -180.0) var validIds = Set() @@ -948,7 +965,8 @@ public final class ReactionListContextMenuContent: ContextControllerItemsContent } func update(presentationData: PresentationData, constrainedSize: CGSize, bottomInset: CGFloat, transition: ContainedViewLayoutTransition) -> (height: CGFloat, apparentHeight: CGFloat) { - let itemHeight: CGFloat = self.displayReadTimestamps ? 56.0 : 44.0 + let heightFraction: CGFloat = presentationData.listsFontSize.baseDisplaySize / 17.0 + let itemHeight: CGFloat = (self.displayReadTimestamps ? 56.0 : 44.0) * heightFraction if self.presentationData?.theme !== presentationData.theme { let sideInset: CGFloat = 40.0 diff --git a/submodules/SettingsUI/Sources/Data and Storage/EnergySavingSettingsScreen.swift b/submodules/SettingsUI/Sources/Data and Storage/EnergySavingSettingsScreen.swift index 8b69726fd5..f77d41ab09 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/EnergySavingSettingsScreen.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/EnergySavingSettingsScreen.swift @@ -211,7 +211,7 @@ private func energeSavingSettingsScreenEntries( let isOn = automaticEnergyUsageShouldBeOnNow(settings: settings) let allIsOn: Bool? - if settings.energyUsageSettings.activationThreshold == 0 || settings.energyUsageSettings.activationThreshold == 100 { + if settings.energyUsageSettings.activationThreshold <= 4 || settings.energyUsageSettings.activationThreshold >= 96 { allIsOn = nil } else { allIsOn = isOn @@ -220,9 +220,9 @@ private func energeSavingSettingsScreenEntries( entries.append(.all(settings.energyUsageSettings.activationThreshold)) let allText: String - if settings.energyUsageSettings.activationThreshold == 0 { + if settings.energyUsageSettings.activationThreshold <= 4 { allText = "Don’t disable all resource-intensive processes even when the battery is low." - } else if settings.energyUsageSettings.activationThreshold >= 100 { + } else if settings.energyUsageSettings.activationThreshold >= 96 { allText = "Always disable all resource-intensive processes, regardless of the battery charge level." } else { allText = "Automatically disable all resource-intensive processes when your battery is below \(settings.energyUsageSettings.activationThreshold)%." @@ -230,9 +230,9 @@ private func energeSavingSettingsScreenEntries( entries.append(.allFooter(allText)) let itemsEnabled: Bool - if settings.energyUsageSettings.activationThreshold == 0 { + if settings.energyUsageSettings.activationThreshold <= 4 { itemsEnabled = true - } else if settings.energyUsageSettings.activationThreshold == 100 { + } else if settings.energyUsageSettings.activationThreshold >= 96 { itemsEnabled = false } else if isOn { itemsEnabled = false @@ -258,7 +258,7 @@ public func energySavingSettingsScreen(context: AccountContext) -> ViewControlle updateThreshold: { value in let _ = updateMediaDownloadSettingsInteractively(accountManager: context.sharedContext.accountManager, { settings in var settings = settings - settings.energyUsageSettings.activationThreshold = max(0, min(100, value)) + settings.energyUsageSettings.activationThreshold = max(4, min(96, value)) return settings }).start() }, @@ -272,7 +272,7 @@ public func energySavingSettingsScreen(context: AccountContext) -> ViewControlle displayDisabledTooltip: { //TODO:localize let text: String - if context.sharedContext.currentAutomaticMediaDownloadSettings.energyUsageSettings.activationThreshold == 100 { + if context.sharedContext.currentAutomaticMediaDownloadSettings.energyUsageSettings.activationThreshold >= 96 { text = "Turn off Power Saving Mode to change these settings." } else { text = "Turn off Power Saving Mode or charge your phone to change these settings." @@ -296,7 +296,7 @@ public func energySavingSettingsScreen(context: AccountContext) -> ViewControlle //TODO:localize let controllerState = ItemListControllerState( presentationData: ItemListPresentationData(presentationData), - title: .text("Energy Saving"), + title: .text("Power Saving"), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), diff --git a/submodules/SettingsUI/Sources/Data and Storage/EnergyUsageBatteryLevelItem.swift b/submodules/SettingsUI/Sources/Data and Storage/EnergyUsageBatteryLevelItem.swift index 9c749e476a..a3c4f8cafa 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/EnergyUsageBatteryLevelItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/EnergyUsageBatteryLevelItem.swift @@ -59,6 +59,16 @@ class EnergyUsageBatteryLevelItem: ListViewItem, ItemListItem { } } +private func rescaleBatteryValueToSlider(_ value: CGFloat) -> CGFloat { + var result = (value - 0.04) / (0.96 - 0.04) + result = max(0.0, min(1.0, result)) + return result +} + +private func rescaleSliderToBatteryValue(_ value: CGFloat) -> CGFloat { + return 0.04 + (0.96 - 0.04) * value +} + class EnergyUsageBatteryLevelItemNode: ListViewItemNode { private let backgroundNode: ASDisplayNode private let topStripeNode: ASDisplayNode @@ -122,7 +132,7 @@ class EnergyUsageBatteryLevelItemNode: ListViewItemNode { sliderView.disablesInteractiveTransitionGestureRecognizer = true sliderView.displayEdges = true if let item = self.item, let params = self.layoutParams { - sliderView.value = CGFloat(item.value) / 100.0 + sliderView.value = rescaleBatteryValueToSlider(CGFloat(item.value) / 100.0) sliderView.backgroundColor = item.theme.list.itemBlocksBackgroundColor sliderView.backColor = item.theme.list.itemSwitchColors.frameColor sliderView.trackColor = item.theme.list.itemAccentColor @@ -214,11 +224,11 @@ class EnergyUsageBatteryLevelItemNode: ListViewItemNode { //TODO:localize let centralText: String let centralMeasureText: String - if item.value <= 0 { + if item.value <= 4 { centralText = "Always Off" centralMeasureText = centralText strongSelf.batteryBackgroundNode.isHidden = true - } else if item.value >= 100 { + } else if item.value >= 96 { centralText = "Always On" centralMeasureText = centralText strongSelf.batteryBackgroundNode.isHidden = true @@ -323,7 +333,7 @@ class EnergyUsageBatteryLevelItemNode: ListViewItemNode { guard let sliderView = self.sliderView else { return } - self.item?.updated(Int32(sliderView.value * 100.0)) + self.item?.updated(Int32(rescaleSliderToBatteryValue(sliderView.value) * 100.0)) } } diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index 9f14bc51af..f38ec45828 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -506,9 +506,9 @@ private func automaticThemeShouldSwitch(_ settings: AutomaticThemeSwitchSetting, } public func automaticEnergyUsageShouldBeOnNow(settings: MediaAutoDownloadSettings) -> Bool { - if settings.energyUsageSettings.activationThreshold == 0 { + if settings.energyUsageSettings.activationThreshold <= 4 { return false - } else if settings.energyUsageSettings.activationThreshold >= 100 { + } else if settings.energyUsageSettings.activationThreshold >= 96 { return true } else { let batteryLevel = UIDevice.current.batteryLevel @@ -521,9 +521,9 @@ public func automaticEnergyUsageShouldBeOnNow(settings: MediaAutoDownloadSetting } public func automaticEnergyUsageShouldBeOn(settings: MediaAutoDownloadSettings) -> Signal { - if settings.energyUsageSettings.activationThreshold == 0 { + if settings.energyUsageSettings.activationThreshold <= 4 { return .single(false) - } else if settings.energyUsageSettings.activationThreshold >= 100 { + } else if settings.energyUsageSettings.activationThreshold >= 96 { return .single(true) } else { return Signal { subscriber in diff --git a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift index 6d085c2171..6e028a3de5 100644 --- a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift +++ b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift @@ -837,6 +837,7 @@ private final class GroupHeaderLayer: UIView { isPremiumLocked: Bool, hasClear: Bool, embeddedItems: [EmojiPagerContentComponent.Item]?, + isStickers: Bool, constrainedSize: CGSize, insets: UIEdgeInsets, cache: AnimationCache, @@ -1138,6 +1139,7 @@ private final class GroupHeaderLayer: UIView { insets: insets, size: groupEmbeddedViewSize, items: embeddedItems, + isStickers: isStickers, cache: cache, renderer: renderer, attemptSynchronousLoad: attemptSynchronousLoad @@ -1252,6 +1254,7 @@ private final class GroupEmbeddedView: UIScrollView, UIScrollViewDelegate, Pager private var currentInsets: UIEdgeInsets? private var currentSize: CGSize? private var items: [EmojiPagerContentComponent.Item]? + private var isStickers: Bool = false private var itemLayout: ItemLayout? @@ -1348,7 +1351,7 @@ private final class GroupEmbeddedView: UIScrollView, UIScrollViewDelegate, Pager let itemFrame = itemLayout.frame(at: index) itemLayer.frame = itemFrame - itemLayer.isVisibleForAnimations = context.sharedContext.energyUsageSettings.loopEmoji + itemLayer.isVisibleForAnimations = self.isStickers ? context.sharedContext.energyUsageSettings.loopStickers : context.sharedContext.energyUsageSettings.loopEmoji } } @@ -1370,6 +1373,7 @@ private final class GroupEmbeddedView: UIScrollView, UIScrollViewDelegate, Pager insets: UIEdgeInsets, size: CGSize, items: [EmojiPagerContentComponent.Item], + isStickers: Bool, cache: AnimationCache, renderer: MultiAnimationRenderer, attemptSynchronousLoad: Bool @@ -1383,6 +1387,7 @@ private final class GroupEmbeddedView: UIScrollView, UIScrollViewDelegate, Pager self.currentInsets = insets self.currentSize = size self.items = items + self.isStickers = isStickers self.cache = cache self.renderer = renderer @@ -5368,6 +5373,7 @@ public final class EmojiPagerContentComponent: Component { isPremiumLocked: itemGroup.isPremiumLocked, hasClear: itemGroup.hasClear, embeddedItems: itemGroup.isEmbedded ? itemGroup.items : nil, + isStickers: component.itemLayoutType == .detailed, constrainedSize: CGSize(width: itemLayout.contentSize.width - itemLayout.headerInsets.left - itemLayout.headerInsets.right, height: itemGroupLayout.headerHeight), insets: itemLayout.headerInsets, cache: component.animationCache, @@ -5801,7 +5807,14 @@ public final class EmojiPagerContentComponent: Component { placeholderView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) } - itemLayer.isVisibleForAnimations = keyboardChildEnvironment.isContentInFocus && component.context.sharedContext.energyUsageSettings.loopEmoji + let allowPlayback: Bool + if case .detailed = component.itemLayoutType { + allowPlayback = component.context.sharedContext.energyUsageSettings.loopStickers + } else { + allowPlayback = component.context.sharedContext.energyUsageSettings.loopEmoji + } + + itemLayer.isVisibleForAnimations = keyboardChildEnvironment.isContentInFocus && allowPlayback } } if itemGroup.fillWithLoadingPlaceholders { diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index bed4fada3e..4777ec5630 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -11099,7 +11099,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if case .undo = action, let self { let _ = updateMediaDownloadSettingsInteractively(accountManager: self.context.sharedContext.accountManager, { settings in var settings = settings - settings.energyUsageSettings.activationThreshold = 0 + settings.energyUsageSettings.activationThreshold = 4 return settings }).start() } diff --git a/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift b/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift index 6849139415..78aaf44095 100644 --- a/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/MediaAutoDownloadSettings.swift @@ -272,7 +272,7 @@ public struct EnergyUsageSettings: Codable, Equatable { public static var `default`: EnergyUsageSettings { return EnergyUsageSettings( - activationThreshold: 10, + activationThreshold: 15, autoplayVideo: true, autoplayGif: true, loopStickers: true, @@ -285,7 +285,7 @@ public struct EnergyUsageSettings: Codable, Equatable { public static var powerSavingDefault: EnergyUsageSettings { return EnergyUsageSettings( - activationThreshold: 10, + activationThreshold: 15, autoplayVideo: false, autoplayGif: false, loopStickers: false,