diff --git a/Session/Meta/AppDelegate.m b/Session/Meta/AppDelegate.m index 000af7460..1f31d6604 100644 --- a/Session/Meta/AppDelegate.m +++ b/Session/Meta/AppDelegate.m @@ -194,7 +194,7 @@ static NSTimeInterval launchStartedAt; mainWindow.rootViewController = [LoadingViewController new]; [mainWindow makeKeyAndVisible]; - LKAppMode appMode = [self getCurrentAppMode]; + LKAppMode appMode = [LKAppModeManager getAppModeOrSystemDefault]; [self adaptAppMode:appMode]; if (@available(iOS 11, *)) { @@ -245,7 +245,7 @@ static NSTimeInterval launchStartedAt; [self ensureRootViewController]; - LKAppMode appMode = [self getCurrentAppMode]; + LKAppMode appMode = [LKAppModeManager getAppModeOrSystemDefault]; [self adaptAppMode:appMode]; [AppReadiness runNowOrWhenAppDidBecomeReady:^{ @@ -734,12 +734,6 @@ static NSTimeInterval launchStartedAt; [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.appModeChanged object:nil]; } -- (LKAppMode)getCurrentAppMode -{ - LKAppMode appMode = [self getAppModeOrSystemDefault]; - return appMode; -} - - (void)setCurrentAppMode:(LKAppMode)appMode { [NSUserDefaults.standardUserDefaults setInteger:appMode forKey:@"appMode"]; @@ -749,7 +743,7 @@ static NSTimeInterval launchStartedAt; - (void)setAppModeToSystemDefault { [NSUserDefaults.standardUserDefaults removeObjectForKey:@"appMode"]; - LKAppMode appMode = [self getCurrentAppMode]; + LKAppMode appMode = [LKAppModeManager getAppModeOrSystemDefault]; [self adaptAppMode:appMode]; } diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index bb28b0b81..56e4100b2 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -40,20 +40,4 @@ extension AppDelegate { @objc func stopClosedGroupPoller() { ClosedGroupPoller.shared.stop() } - - @objc func getAppModeOrSystemDefault() -> AppMode { - let userDefaults = UserDefaults.standard - - guard userDefaults.dictionaryRepresentation().keys.contains("appMode") else { - if #available(iOS 13.0, *) { - return UITraitCollection.current.userInterfaceStyle == .dark ? .dark : .light - } else { - return .light - } - } - - let mode = userDefaults.integer(forKey: "appMode") - return AppMode(rawValue: mode) ?? .light - } - } diff --git a/SessionMessagingKit/Sending & Receiving/Attachments/SignalAttachment.swift b/SessionMessagingKit/Sending & Receiving/Attachments/SignalAttachment.swift index f65d8640c..0087c3663 100644 --- a/SessionMessagingKit/Sending & Receiving/Attachments/SignalAttachment.swift +++ b/SessionMessagingKit/Sending & Receiving/Attachments/SignalAttachment.swift @@ -462,7 +462,12 @@ public class SignalAttachment: NSObject { @objc public var isText: Bool { - return UTTypeConformsTo(dataUTI as CFString, kUTTypeText) || isOversizeText + return ( + isConvertibleToTextMessage && ( + UTTypeConformsTo(dataUTI as CFString, kUTTypeText) || + isOversizeText + ) + ) } @objc diff --git a/SessionShareExtension/ShareVC.swift b/SessionShareExtension/ShareVC.swift index 1492f8d80..34716c706 100644 --- a/SessionShareExtension/ShareVC.swift +++ b/SessionShareExtension/ShareVC.swift @@ -162,15 +162,6 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD } // MARK: - App Mode - - public func getCurrentAppMode() -> AppMode { - guard let window = self.view.window else { return .light } - - let userInterfaceStyle = window.traitCollection.userInterfaceStyle - let isLightMode = (userInterfaceStyle == .light || userInterfaceStyle == .unspecified) - - return (isLightMode ? .light : .dark) - } public func setCurrentAppMode(to appMode: AppMode) { return // Not applicable to share extensions diff --git a/SessionShareExtension/ThreadPickerVC.swift b/SessionShareExtension/ThreadPickerVC.swift index 6e4df133a..3e975d51d 100644 --- a/SessionShareExtension/ThreadPickerVC.swift +++ b/SessionShareExtension/ThreadPickerVC.swift @@ -95,6 +95,11 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView } } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + view.setGradient(Gradients.defaultBackground) + fadeView.setGradient(Gradients.homeVCFade) + } + // MARK: Layout private func setupLayout() { diff --git a/SessionUIKit/Style Guide/AppMode.swift b/SessionUIKit/Style Guide/AppMode.swift index 01db04682..e2ad9e75a 100644 --- a/SessionUIKit/Style Guide/AppMode.swift +++ b/SessionUIKit/Style Guide/AppMode.swift @@ -1,11 +1,11 @@ -import Foundation +import UIKit @objc(LKAppModeManager) public final class AppModeManager : NSObject { private let delegate: AppModeManagerDelegate public var currentAppMode: AppMode { - return delegate.getCurrentAppMode() + return AppModeManager.getAppModeOrSystemDefault() } public static var shared: AppModeManager! @@ -29,19 +29,33 @@ public final class AppModeManager : NSObject { public func setAppModeToSystemDefault() { delegate.setAppModeToSystemDefault() } + + @objc public static func getAppModeOrSystemDefault() -> AppMode { + let userDefaults = UserDefaults.standard + + guard userDefaults.dictionaryRepresentation().keys.contains("appMode") else { + if #available(iOS 13.0, *) { + return UITraitCollection.current.userInterfaceStyle == .dark ? .dark : .light + } + + return .light + } + + let mode = userDefaults.integer(forKey: "appMode") + return AppMode(rawValue: mode) ?? .light + } } @objc(LKAppModeManagerDelegate) public protocol AppModeManagerDelegate { - func getCurrentAppMode() -> AppMode @objc(setCurrentAppMode:) func setCurrentAppMode(to appMode: AppMode) func setAppModeToSystemDefault() } @objc(LKAppMode) -public enum AppMode : Int { +public enum AppMode: Int { case light, dark }