Update Ghostgram features

This commit is contained in:
ichmagmaus 812
2026-03-07 18:15:32 +01:00
parent 1a3303b059
commit 24a7ec39d9
902 changed files with 148295 additions and 62348 deletions
@@ -0,0 +1,9 @@
filegroup(
name = "SGChatListSimpleSettingsSignal",
srcs = glob([
"Sources/**/*.swift",
]),
visibility = [
"//visibility:public",
],
)
@@ -0,0 +1,21 @@
import SGSimpleSettings
import Foundation
import SwiftSignalKit
public func sgSimpleSettingsBoolSignal(_ key: SGSimpleSettings.Keys, defaultValue: Bool) -> Signal<Bool, NoError> {
let initial = Signal<Bool, NoError>.single(UserDefaults.standard.object(forKey: key.rawValue) as? Bool ?? defaultValue)
let changes = Signal<Bool, NoError> { subscriber in
let observer = NotificationCenter.default.addObserver(
forName: UserDefaults.didChangeNotification,
object: UserDefaults.standard,
queue: nil
) { _ in
let value = UserDefaults.standard.object(forKey: key.rawValue) as? Bool ?? defaultValue
subscriber.putNext(value)
}
return ActionDisposable {
NotificationCenter.default.removeObserver(observer)
}
}
return (initial |> then(changes)) |> distinctUntilChanged
}
@@ -0,0 +1,60 @@
import SGSimpleSettings
import CoreGraphics
import Display
enum SGCompactMessagePreviewLayout {
static func isEnabled() -> Bool {
(SGSimpleSettings.ChatListLines(rawValue: SGSimpleSettings.shared.chatListLines) ?? .three) != .three
}
static func avatarScaleDivisor(compactChatList: Bool, compactMessagePreview: Bool) -> CGFloat {
compactChatList ? 1.5 : (compactMessagePreview ? 1.1 : 1.0)
}
static func forumTopicIconYOffset(compactMessagePreview: Bool) -> CGFloat {
compactMessagePreview ? 8.0 : 0.0
}
static func badgeOffset(sizeFactor: CGFloat, compactMessagePreview: Bool, compactChatList: Bool) -> CGFloat {
guard compactMessagePreview && !compactChatList else {
return 0.0
}
let sizeRange: CGFloat = 0.5
let maxLift: CGFloat = 16.0
let maxDownshift: CGFloat = 24.0
let sizeDelta = sizeFactor - 1.0
let lift: CGFloat
if sizeDelta >= 0.0 {
let sizeGrow = min(sizeRange, sizeDelta)
let sizeGrowFactor = sizeGrow / sizeRange
lift = maxLift * sizeGrowFactor * sizeGrowFactor * (3.0 - 2.0 * sizeGrowFactor)
} else {
let sizeShrink = min(sizeRange, -sizeDelta)
let sizeShrinkFactor = sizeShrink / sizeRange
let downshift = maxDownshift * sizeShrinkFactor * sizeShrinkFactor * (3.0 - 2.0 * sizeShrinkFactor)
lift = -downshift
}
return floorToScreenPixels(lift)
}
static func textVerticalOffset(sizeFactor: CGFloat, compactMessagePreview: Bool, compactChatList: Bool, hasAuthorLine: Bool) -> CGFloat {
guard compactMessagePreview && !compactChatList && !hasAuthorLine else {
return 0.0
}
return floorToScreenPixels(6.0 * sizeFactor)
}
static func titleTextSpacing(sizeFactor: CGFloat, compactMessagePreview: Bool, compactChatList: Bool, hasAuthorLine: Bool) -> CGFloat {
guard compactMessagePreview && !compactChatList && !hasAuthorLine else {
return 0.0
}
return floorToScreenPixels(6.0 * sizeFactor)
}
static func textBlockOffset(sizeFactor: CGFloat, compactMessagePreview: Bool, compactChatList: Bool, hasAuthorLine: Bool) -> CGFloat {
textVerticalOffset(sizeFactor: sizeFactor, compactMessagePreview: compactMessagePreview, compactChatList: compactChatList, hasAuthorLine: hasAuthorLine)
+ titleTextSpacing(sizeFactor: sizeFactor, compactMessagePreview: compactMessagePreview, compactChatList: compactChatList, hasAuthorLine: hasAuthorLine)
}
}