Fix avatars light/dark mode

This commit is contained in:
Christophe Deschamps 2022-11-03 17:02:09 +01:00
parent f3bc7add35
commit 06cbe9fa1d
10 changed files with 66 additions and 12 deletions

View file

@ -370,8 +370,6 @@ static UICompositeViewDescription *compositeDescription = nil;
}
}
- (void)configureForRoom:(BOOL)editing {
if (!_chatRoom) {
_chatView.hidden = YES;

View file

@ -39,6 +39,10 @@
selector:@selector(ephemeralDeleted:)
name:kLinphoneEphemeralMessageDeletedInRoom
object:nil];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(displayModeChanged)
name:kDisplayModeChanged
object:nil];
[_backToCallButton update];
self.tableController.waitView = _waitView;
[self setEditing:NO];
@ -68,6 +72,9 @@
}
- (void)displayModeChanged{
[self.tableController.tableView reloadData];
}
- (void)ephemeralDeleted:(NSNotification *)notif {
//LinphoneChatRoom *r =[[notif.userInfo objectForKey:@"room"] intValue];

View file

@ -147,6 +147,10 @@ static UICompositeViewDescription *compositeDescription = nil;
selector:@selector(onMagicSearchMoreAvailable:)
name:kLinphoneMagicSearchMoreAvailable
object:nil];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(displayModeChanged)
name:kDisplayModeChanged
object:nil];
}
- (void)onMagicSearchStarted:(NSNotification *)k {
@ -258,6 +262,10 @@ static UICompositeViewDescription *compositeDescription = nil;
}
}
- (void)displayModeChanged{
[self.tableController.tableView reloadData];
}
- (IBAction)onDeleteClick:(id)sender {
NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete selected contacts?\nThey will also be deleted from your phone's address book.", nil)];
[LinphoneManager.instance setContactsUpdated:TRUE];

View file

@ -67,10 +67,15 @@ static UICompositeViewDescription *compositeDescription = nil;
// Fake event
[NSNotificationCenter.defaultCenter postNotificationName:kLinphoneCallUpdate object:self];
[_toggleSelectionButton setImage:[UIImage imageNamed:@"select_all_default.png"] forState:UIControlStateSelected];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(displayModeChanged)
name:kDisplayModeChanged
object:nil];
}
- (void) viewWillDisappear:(BOOL)animated {
self.view = NULL;
[NSNotificationCenter.defaultCenter removeObserver:self];
}
#pragma mark -
@ -100,6 +105,10 @@ static UICompositeViewDescription *compositeDescription = nil;
_selectedButtonImage.frame = frame;
}
- (void)displayModeChanged{
[self.tableController.tableView reloadData];
}
#pragma m ~ark - Action Functions
- (IBAction)onAllClick:(id)event {

View file

@ -85,6 +85,7 @@
[LinphoneManager.instance.fastAddressBook reloadFriends];
[NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:nil];
}
- (void)applicationWillResignActive:(UIApplication *)application {
@ -183,6 +184,11 @@
}];
if ([UIDeviceBridge switchedDisplayMode]) {
[AvatarBridge prepareIt];
[NSNotificationCenter.defaultCenter postNotificationName:kDisplayModeChanged object:nil];
}
}
#pragma deploymate push "ignored-api-availability"

View file

@ -66,6 +66,7 @@ extern NSString *const kLinphoneConfStateChanged;
extern NSString *const kLinphoneMagicSearchStarted;
extern NSString *const kLinphoneMagicSearchFinished;
extern NSString *const kLinphoneMagicSearchMoreAvailable;
extern NSString *const kDisplayModeChanged;
extern NSString *const kLinphoneMsgNotificationAppGroupId;

View file

@ -82,6 +82,7 @@ NSString *const kLinphoneConfStateParticipantListChanged = @"kLinphoneConfStateP
NSString *const kLinphoneMagicSearchStarted = @"LinphoneMagicSearchStarted";
NSString *const kLinphoneMagicSearchFinished = @"LinphoneMagicSearchFinished";
NSString *const kLinphoneMagicSearchMoreAvailable = @"LinphoneMagicSearchMoreAvailable";
NSString *const kDisplayModeChanged = @"DisplayModeChanged";
NSString *const kLinphoneMsgNotificationAppGroupId = @"group.org.linphone.phone.msgNotification";

View file

@ -54,4 +54,24 @@ extension UIDevice {
return [.landscapeRight,.landscapeLeft].contains(UIDevice.current.orientation) ? sidePadding : topPadding
}
static func switchedDisplayMode() -> Bool {
let displayMode = UserDefaults.standard.string(forKey: "displayMode")
if #available(iOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .light {
UserDefaults.standard.set("light", forKey: "displayMode")
} else {
UserDefaults.standard.set("dark", forKey: "displayMode")
}
}
return displayMode != nil && displayMode != UserDefaults.standard.string(forKey: "displayMode")
}
}
@objc class UIDeviceBridge : NSObject {
@available(iOS 12.0, *)
static let displayMode = MutableLiveData<UIUserInterfaceStyle>()
@objc static func switchedDisplayMode() -> Bool {
return UIDevice.switchedDisplayMode()
}
}

View file

@ -88,7 +88,7 @@ import UIKit
static let call_header_subtitle = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .center, font: fontName+"-Regular", size: 14.0)
static let call_generated_avatar_large = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .center, font: fontName+"-Regular", size: 53.0)
static let call_generated_avatar_medium = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .center, font: fontName+"-Regular", size: 27.0)
static let call_generated_avatar_small = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .center, font: fontName+"-Bold", size: 25.0)
static let call_generated_avatar_small = TextStyle(fgColor: LightDarkColor(.white,voip_dark_gray), bgColor: LightDarkColor(.clear,.clear), allCaps: true, align: .center, font: fontName+"-Bold", size: 25.0)
static let dtmf_label = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .center, font: fontName+"-Regular", size: 30.0)
static let call_remote_name = TextStyle(fgColor: LightDarkColor(.white,.white), bgColor: LightDarkColor(.clear,.clear), allCaps: false, align: .left, font: fontName+"-Regular", size: 18.0)

View file

@ -87,13 +87,20 @@ class Avatar : UIView {
@objc class AvatarBridge : NSObject { // Ugly work around to tap into the swift Avatars, until rest of the app is reworked in Swift.
static var shared : Avatar? = nil
static let size = 50.0
static let size = 50.0
@objc static func prepareIt() {
if (shared != nil) {
shared?.removeFromSuperview()
}
shared = Avatar(color:VoipTheme.primaryTextColor, textStyle: VoipTheme.call_generated_avatar_small)
PhoneMainView.instance().mainViewController.view.addSubview(shared!)
PhoneMainView.instance().mainViewController.view.sendSubviewToBack(shared!)
shared?.bounds.size = CGSize(width: size, height: size)
}
@objc static func imageForAddress(address:OpaquePointer) -> UIImage? {
if (shared == nil) {
shared = Avatar(color:VoipTheme.primaryTextColor, textStyle: VoipTheme.call_generated_avatar_small)
PhoneMainView.instance().mainViewController.view.addSubview(shared!)
PhoneMainView.instance().mainViewController.view.sendSubviewToBack(shared!)
shared?.bounds.size = CGSize(width: size, height: size)
prepareIt()
}
let sAddr = Address.getSwiftObject(cObject: address)
shared?.fillFromAddress(address: sAddr)
@ -102,10 +109,7 @@ class Avatar : UIView {
@objc static func imageForInitials(displayName:String) -> UIImage? {
if (shared == nil) {
shared = Avatar(color:VoipTheme.primaryTextColor, textStyle: VoipTheme.call_generated_avatar_small)
PhoneMainView.instance().mainViewController.view.addSubview(shared!)
PhoneMainView.instance().mainViewController.view.sendSubviewToBack(shared!)
shared?.bounds.size = CGSize(width: size, height: size)
prepareIt()
}
shared?.initialsLabel.text = Address.initials(displayName: displayName)
shared?.initialsLabel.isHidden = false