Skip to content

Commit

Permalink
Release 1.5.0 (210)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Jan 3, 2024
1 parent 11f7ab2 commit f7a65d8
Show file tree
Hide file tree
Showing 511 changed files with 23,097 additions and 6,534 deletions.
2 changes: 1 addition & 1 deletion Nicegram/NGAppCache/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ swift_library(
"Sources/**/*.swift",
]),
deps = [
"@swiftpkg_nicegram_assistant_ios//:Sources_NGCore"

],
visibility = [
"//visibility:public",
Expand Down
11 changes: 0 additions & 11 deletions Nicegram/NGAppCache/Sources/AppCache.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import NGCore

public final class AppCache {
// Old key 'appLaunchCount'
Expand Down Expand Up @@ -32,16 +31,6 @@ public final class AppCache {
_wasLauchedBefore = newValue
}
}

public static var mobileIdentifier: String {
if let identifier = KeychainWrapper.standard.string(forKey: "ng_mobileIdentifier", withAccessibility: .afterFirstUnlock),
!identifier.isEmpty {
return identifier
}
let newIdentifier = UUID().uuidString
KeychainWrapper.standard.set(newIdentifier, forKey: "ng_mobileIdentifier", withAccessibility: .afterFirstUnlock)
return newIdentifier
}

private init() {}
}
Expand Down
11 changes: 5 additions & 6 deletions Nicegram/NGOnboarding/Sources/OnboardingFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import NGAiChat
import NGData
import NGStrings

public func onboardingController(languageCode: String, onComplete: @escaping () -> Void) -> UIViewController {
public func onboardingController(onComplete: @escaping () -> Void) -> UIViewController {
let controller = OnboardingViewController(
items: onboardingPages(languageCode: languageCode),
languageCode: languageCode,
items: onboardingPages(),
onComplete: {
if isPremium() {
onComplete()
Expand All @@ -23,7 +22,7 @@ public func onboardingController(languageCode: String, onComplete: @escaping ()
return controller
}

private func onboardingPages(languageCode: String) -> [OnboardingPageViewModel] {
private func onboardingPages() -> [OnboardingPageViewModel] {
let aiPageIndex = 6

var pages = Array(1...6)
Expand All @@ -41,8 +40,8 @@ private func onboardingPages(languageCode: String) -> [OnboardingPageViewModel]

return pages.map { index in
OnboardingPageViewModel(
title: l("NicegramOnboarding.\(index).Title", languageCode),
description: l("NicegramOnboarding.\(index).Desc", languageCode),
title: l("NicegramOnboarding.\(index).Title"),
description: l("NicegramOnboarding.\(index).Desc"),
videoURL: Bundle.main.url(forResource: "Nicegram_Onboarding-DS_v\(index)", withExtension: "mp4")!
)
}
Expand Down
6 changes: 2 additions & 4 deletions Nicegram/NGOnboarding/Sources/OnboardingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ class OnboardingViewController: UIViewController {
// MARK: - Logic

private let items: [OnboardingPageViewModel]
private let languageCode: String

// MARK: - Lifecycle

init(items: [OnboardingPageViewModel], languageCode: String, onComplete: @escaping () -> Void) {
init(items: [OnboardingPageViewModel], onComplete: @escaping () -> Void) {
self.items = items
self.languageCode = languageCode
self.onComplete = onComplete

super.init(nibName: nil, bundle: nil)
Expand All @@ -55,7 +53,7 @@ class OnboardingViewController: UIViewController {
scrollView.delegate = self

display(items: self.items)
display(buttonTitle: l("NicegramOnboarding.Continue", languageCode))
display(buttonTitle: l("NicegramOnboarding.Continue"))

nextButton.touchUpInside = { [weak self] in
self?.goToNextPage()
Expand Down
15 changes: 15 additions & 0 deletions Nicegram/NGRoundedVideos/BUILD
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"],

)
117 changes: 117 additions & 0 deletions Nicegram/NGRoundedVideos/Sources/NGRoundedVideos.swift
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")
}
}
18 changes: 18 additions & 0 deletions Nicegram/NGStealthMode/BUILD
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",
],
)
70 changes: 70 additions & 0 deletions Nicegram/NGStealthMode/Sources/NGStealthMode.swift
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
}
3 changes: 1 addition & 2 deletions Nicegram/NGStrings/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ swift_library(
"Sources/**/*.swift",
]),
deps = [
"//Nicegram/NGLogging:NGLogging",
"//submodules/AppBundle:AppBundle"
"@swiftpkg_nicegram_assistant_ios//:Sources_NGLocalization"
],
visibility = [
"//visibility:public",
Expand Down
Loading

0 comments on commit f7a65d8

Please sign in to comment.