mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-08-16 11:00:22 +02:00
Update Ghostgram features
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user