forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
511 changed files
with
23,097 additions
and
6,534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") | ||
|
||
swift_library( | ||
name = "NGRoundedVideos", | ||
module_name = "NGRoundedVideos", | ||
srcs = glob([ | ||
"Sources/**/*.swift", | ||
]), | ||
deps = [ | ||
"//Nicegram/NGAppCache:NGAppCache", | ||
"//Nicegram/NGStrings:NGStrings", | ||
], | ||
visibility = ["//visibility:public"], | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import CoreMedia | ||
import NGAppCache | ||
import NGStrings | ||
import UIKit | ||
|
||
public struct NGRoundedVideos { | ||
public struct Constants { | ||
public static let trimSeconds = 60.0 | ||
public static let videoSize = CGSize( | ||
width: 384, | ||
height: 384 | ||
) | ||
} | ||
} | ||
|
||
public extension NGRoundedVideos { | ||
// Workaround to reduce changes in telegram code | ||
static var sendAsRoundedVideo = false | ||
|
||
static func calcCropRectAndScale( | ||
originalCropRect: CGRect | ||
) -> (CGRect, CGFloat) { | ||
let targetSize = NGRoundedVideos.Constants.videoSize | ||
|
||
let originalAspectRatio = originalCropRect.width / originalCropRect.height | ||
let targetAspectRatio = targetSize.width / targetSize.height | ||
|
||
let trimmingSize: CGSize | ||
if originalAspectRatio < targetAspectRatio { | ||
trimmingSize = CGSize( | ||
width: originalCropRect.width, | ||
height: originalCropRect.width / targetAspectRatio | ||
) | ||
} else { | ||
trimmingSize = CGSize( | ||
width: originalCropRect.height * targetAspectRatio, | ||
height: originalCropRect.height | ||
) | ||
} | ||
|
||
let extraWidth = originalCropRect.width - trimmingSize.width | ||
let extraHeight = originalCropRect.height - trimmingSize.height | ||
|
||
let cropRect = CGRect( | ||
origin: originalCropRect.origin.applying( | ||
CGAffineTransform( | ||
translationX: extraWidth / 2, | ||
y: extraHeight / 2 | ||
) | ||
), | ||
size: trimmingSize | ||
) | ||
let cropScale = targetSize.width / cropRect.width | ||
|
||
return (cropRect, cropScale) | ||
} | ||
|
||
static func trim(range: CMTimeRange) -> [CMTimeRange] { | ||
let length = CMTime( | ||
seconds: Constants.trimSeconds, | ||
preferredTimescale: 60 | ||
) | ||
|
||
var chunks: [CMTimeRange] = [] | ||
var from = range.start | ||
while from < range.end { | ||
chunks.append( | ||
CMTimeRange( | ||
start: from, | ||
duration: length | ||
).intersection(range) | ||
) | ||
from = from + length | ||
} | ||
|
||
return chunks | ||
} | ||
} | ||
|
||
public extension NGRoundedVideos { | ||
@UserDefaultsBacked( | ||
key: "sawRoundedVideoMoreButtonTooltip", | ||
defaultValue: false | ||
) | ||
static var sawMoreButtonTooltip | ||
|
||
@UserDefaultsBacked( | ||
key: "sawRoundedVideoSendButtonTooltip", | ||
defaultValue: false | ||
) | ||
static var sawSendButtonTooltip | ||
} | ||
|
||
public extension NGRoundedVideos { | ||
struct Resources {} | ||
} | ||
public extension NGRoundedVideos.Resources { | ||
static func buttonTitle() -> String { | ||
l("RoundedVideos.ButtonTitle") | ||
} | ||
|
||
static func buttonIcon() -> UIImage? { | ||
if #available(iOS 13.0, *) { | ||
UIImage(systemName: "video.circle") | ||
} else { | ||
nil | ||
} | ||
} | ||
|
||
static func moreButtonTooltip() -> String { | ||
l("RoundedVideos.MoreButtonTooltip") | ||
} | ||
|
||
static func sendButtonTooltip() -> String { | ||
l("RoundedVideos.SendButtonTooltip") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") | ||
|
||
swift_library( | ||
name = "NGStealthMode", | ||
module_name = "NGStealthMode", | ||
srcs = glob([ | ||
"Sources/**/*.swift", | ||
]), | ||
deps = [ | ||
"//Nicegram/NGStrings:NGStrings", | ||
"//submodules/AccountContext:AccountContext", | ||
"//submodules/TelegramUIPreferences:TelegramUIPreferences", | ||
"@swiftpkg_nicegram_assistant_ios//:Sources_FeatPremium", | ||
], | ||
visibility = [ | ||
"//visibility:public", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import AccountContext | ||
import FeatPremium | ||
import NGCore | ||
import NGStrings | ||
import TelegramUIPreferences | ||
|
||
public struct NGStealthMode { | ||
private static var stealthModeSubscription: Any? | ||
} | ||
|
||
public extension NGStealthMode { | ||
static func initialize( | ||
sharedContext: SharedAccountContext | ||
) { | ||
guard #available(iOS 13.0, *) else { | ||
return | ||
} | ||
|
||
let getPremiumStatusUseCase = PremiumContainer.shared.getPremiumStatusUseCase() | ||
|
||
stealthModeSubscription = $stealthModeEnabled | ||
.combineLatest(getPremiumStatusUseCase.hasPremiumOnDevicePublisher()) | ||
.map { stealthModeEnabled, hasPremium in | ||
stealthModeEnabled && hasPremium | ||
} | ||
.sink { [weak sharedContext] useStealthMode in | ||
guard let sharedContext else { | ||
return | ||
} | ||
|
||
let _ = updateExperimentalUISettingsInteractively(accountManager: sharedContext.accountManager, { settings in | ||
var settings = settings | ||
settings.skipReadHistory = useStealthMode | ||
return settings | ||
}).start() | ||
} | ||
} | ||
|
||
static func isStealthModeEnabled() -> Bool { | ||
if #available(iOS 13.0, *) { | ||
stealthModeEnabled | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
static func setStealthModeEnabled(_ enabled: Bool) { | ||
if #available(iOS 13.0, *) { | ||
stealthModeEnabled = enabled | ||
} | ||
} | ||
} | ||
|
||
public extension NGStealthMode { | ||
struct Resources {} | ||
} | ||
public extension NGStealthMode.Resources { | ||
static func toggleTitle() -> String { | ||
l("StealthMode.Toggle") | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
private extension NGStealthMode { | ||
@UserDefaultsValue( | ||
key: "stealthModeEnabled", | ||
defaultValue: false | ||
) | ||
static var stealthModeEnabled: Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.