mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
chatrooms widget : update user defaults, print names & pictures
This commit is contained in:
parent
88a8820f95
commit
50000e66e5
7 changed files with 164 additions and 0 deletions
|
|
@ -30,4 +30,5 @@
|
|||
|
||||
- (void)loadData;
|
||||
- (void)markCellAsRead:(LinphoneChatRoom *)chatRoom;
|
||||
+ (void)saveDataToUserDefaults;
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -123,6 +123,40 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo
|
|||
}
|
||||
}
|
||||
|
||||
+ (void) saveDataToUserDefaults {
|
||||
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.belledonne-communications.linphone.widget"];
|
||||
MSList *sorted = nil;
|
||||
const MSList *unsorted = linphone_core_get_chat_rooms(LC);
|
||||
const MSList *iter = unsorted;
|
||||
|
||||
while (iter) {
|
||||
// store last message in user data
|
||||
LinphoneChatRoom *chat_room = iter->data;
|
||||
sorted = bctbx_list_insert_sorted(sorted, chat_room, (bctbx_compare_func)sorted_history_comparison);
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
NSMutableArray *addresses = [NSMutableArray array];
|
||||
|
||||
while (sorted) {
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
LinphoneChatRoom *cr = sorted->data;
|
||||
const LinphoneAddress *address = linphone_chat_room_get_peer_address(cr);
|
||||
NSString *display;
|
||||
[dict setObject:[[NSString stringWithUTF8String:linphone_address_as_string_uri_only(address)] substringFromIndex:4] forKey:@"address"];
|
||||
if (linphone_chat_room_get_nb_participants(cr) > 1)
|
||||
display = [NSString stringWithUTF8String:linphone_chat_room_get_subject(cr)];
|
||||
else
|
||||
display = [NSString stringWithUTF8String:linphone_address_get_display_name(address)?:linphone_address_get_username(address)];
|
||||
[dict setObject:display forKey:@"display"];
|
||||
[dict setObject:[NSNumber numberWithInt:linphone_chat_room_get_nb_participants(cr)] forKey:@"nbParticipants"];
|
||||
[addresses addObject:dict];
|
||||
sorted = sorted->next;
|
||||
}
|
||||
|
||||
[defaults setObject:addresses forKey:@"chatrooms"];
|
||||
}
|
||||
|
||||
- (void)markCellAsRead:(LinphoneChatRoom *)chatRoom {
|
||||
int idx = bctbx_list_index(_data, VIEW(ChatConversationView).chatRoom);
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0];
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@
|
|||
}
|
||||
[LinphoneManager.instance.iapManager check];
|
||||
[HistoryListTableView saveDataToUserDefaults];
|
||||
[ChatsListTableView saveDataToUserDefaults];
|
||||
}
|
||||
|
||||
#pragma deploymate push "ignored-api-availability"
|
||||
|
|
@ -343,10 +344,15 @@
|
|||
NSString *sipUri = [[url resourceSpecifier] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
|
||||
[VIEW(DialerView) setAddress:sipUri];
|
||||
} else if ([scheme isEqualToString:@"linphone-widget"]) {
|
||||
printf("cparla\n");
|
||||
if ([[url host] isEqualToString:@"call_log"] &&
|
||||
[[url path] isEqualToString:@"/show"]) {
|
||||
[VIEW(HistoryDetailsView) setCallLogId:[url query]];
|
||||
[PhoneMainView.instance changeCurrentView:HistoryDetailsView.compositeViewDescription];
|
||||
} else if ([[url host] isEqualToString:@"chatroom"] &&
|
||||
[[url path] isEqualToString:@"/show"]) {
|
||||
LinphoneChatRoom *cr = linphone_core_get_chat_room_from_uri(LC, url.query.UTF8String);
|
||||
[PhoneMainView.instance goToChatRoom:cr];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@
|
|||
<constraint firstAttribute="height" constant="60" id="gNd-AG-oLn"/>
|
||||
</constraints>
|
||||
<state key="normal" image="avatar.png"/>
|
||||
<connections>
|
||||
<action selector="firstButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="n6M-cY-cWU"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fpJ-Wl-BT1">
|
||||
<rect key="frame" x="0.0" y="70" width="60" height="17.5"/>
|
||||
|
|
@ -54,6 +57,9 @@
|
|||
<constraint firstAttribute="width" constant="60" id="iil-bF-24j"/>
|
||||
</constraints>
|
||||
<state key="normal" image="avatar.png"/>
|
||||
<connections>
|
||||
<action selector="secondButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="e09-4G-NJf"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fEo-fa-uyD">
|
||||
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
|
||||
|
|
@ -76,6 +82,9 @@
|
|||
<constraint firstAttribute="height" constant="60" id="rtD-OM-bmH"/>
|
||||
</constraints>
|
||||
<state key="normal" image="avatar.png"/>
|
||||
<connections>
|
||||
<action selector="thirdButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="OtO-nr-X1J"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zM6-aO-Pes">
|
||||
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
|
||||
|
|
@ -98,6 +107,9 @@
|
|||
<constraint firstAttribute="height" constant="60" id="SYf-Yl-EDf"/>
|
||||
</constraints>
|
||||
<state key="normal" image="avatar.png"/>
|
||||
<connections>
|
||||
<action selector="fourthButtonTapped" destination="M4Y-Lb-cyx" eventType="touchUpInside" id="a2u-BT-Fkp"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bpY-VL-FDz">
|
||||
<rect key="frame" x="0.0" y="70.5" width="60" height="17"/>
|
||||
|
|
@ -123,6 +135,12 @@
|
|||
<extendedEdge key="edgesForExtendedLayout"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<size key="freeformSize" width="320" height="37"/>
|
||||
<connections>
|
||||
<outletCollection property="stackViews" destination="P4U-hP-N9F" id="3f1-th-6ZO"/>
|
||||
<outletCollection property="stackViews" destination="79U-UR-Bp2" id="ix2-7S-Rim"/>
|
||||
<outletCollection property="stackViews" destination="Xgm-go-u3S" id="VYM-Ld-joW"/>
|
||||
<outletCollection property="stackViews" destination="nHe-ID-vxE" id="iGd-Ix-Pj6"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
|
|
|||
|
|
@ -8,5 +8,15 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface TodayViewController : UIViewController
|
||||
@property (strong, nonatomic) IBOutletCollection(UIStackView) NSArray *stackViews;
|
||||
@property (strong, nonatomic) NSMutableArray *chatrooms;
|
||||
@property (strong, nonatomic) NSMutableArray *addresses;
|
||||
@property (strong, nonatomic) NSMutableArray *displayNames;
|
||||
@property (strong, nonatomic) NSMutableDictionary *imgs;
|
||||
@property (strong, nonatomic) NSMutableArray *isConf;
|
||||
|
||||
- (IBAction)firstButtonTapped;
|
||||
- (IBAction)secondButtonTapped;
|
||||
- (IBAction)thirdButtonTapped;
|
||||
- (IBAction)fourthButtonTapped;
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#import "TodayViewController.h"
|
||||
#import <NotificationCenter/NotificationCenter.h>
|
||||
#import "linphone/linphonecore.h"
|
||||
|
||||
@interface TodayViewController () <NCWidgetProviding>
|
||||
|
||||
|
|
@ -14,14 +15,72 @@
|
|||
|
||||
@implementation TodayViewController
|
||||
|
||||
- (void)loadData {
|
||||
NSUserDefaults *mySharedDefaults = [[NSUserDefaults alloc] initWithSuiteName: @"group.belledonne-communications.linphone.widget"];
|
||||
[_chatrooms removeAllObjects];
|
||||
[_imgs removeAllObjects];
|
||||
[_addresses removeAllObjects];
|
||||
[_displayNames removeAllObjects];
|
||||
[_isConf removeAllObjects];
|
||||
_imgs = [NSMutableDictionary dictionaryWithDictionary:[mySharedDefaults objectForKey:@"imageData"]];
|
||||
_chatrooms = [NSMutableArray arrayWithArray:[mySharedDefaults objectForKey:@"chatrooms"]];
|
||||
for (NSDictionary *dict in _chatrooms) {
|
||||
[_addresses addObject:[dict objectForKey:@"address"]];
|
||||
[_displayNames addObject:[dict objectForKey:@"display"]];
|
||||
[_isConf addObject:[NSNumber numberWithBool:(((NSNumber *)[dict objectForKey:@"nbParticipants"]).intValue > 1)]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)draw {
|
||||
int i = 0;
|
||||
for (i = 0 ; i < 4 && i < _addresses.count ; i++) {
|
||||
UIStackView *stack = _stackViews[i];
|
||||
UIButton *button = stack.subviews[0];
|
||||
UILabel *name = stack.subviews[1];
|
||||
printf("%s\n", ((NSString *)_addresses[i]).UTF8String);
|
||||
if ([self.imgs.allKeys containsObject:_addresses[i]]) {
|
||||
NSData *imgData = [_imgs objectForKey:_addresses[i]];
|
||||
[button setImage:[UIImage imageWithData:imgData] forState:UIControlStateNormal];
|
||||
NSLog(@"Size of Image(bytes):%d", (int)[imgData length]);
|
||||
} else if (((NSNumber *)_isConf[i]).boolValue) {
|
||||
[button setImage:[UIImage imageNamed:@"chat_group_avatar.png"] forState:UIControlStateNormal];
|
||||
}
|
||||
[stack setAlpha:1];
|
||||
button.enabled = YES;
|
||||
[name setText:_displayNames[i]];
|
||||
}
|
||||
|
||||
while (i < 4) {
|
||||
UIStackView *stack = _stackViews[i];
|
||||
UIButton *button = stack.subviews[0];
|
||||
[stack setAlpha:0];
|
||||
button.enabled = NO;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view from its nib.
|
||||
for (UIStackView *stack in _stackViews) {
|
||||
UIButton *button = stack.subviews[0];
|
||||
// making rounded image
|
||||
UIImageView *imageView = button.imageView;
|
||||
imageView.layer.cornerRadius = imageView.frame.size.height / 2;
|
||||
imageView.clipsToBounds = YES;
|
||||
}
|
||||
|
||||
_chatrooms = [NSMutableArray array];
|
||||
_addresses = [NSMutableArray array];
|
||||
_displayNames = [NSMutableArray array];
|
||||
_imgs = [NSMutableDictionary dictionary];
|
||||
_isConf = [NSMutableArray array];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
[_imgs removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
|
||||
|
|
@ -30,8 +89,34 @@
|
|||
// If an error is encountered, use NCUpdateResultFailed
|
||||
// If there's no update required, use NCUpdateResultNoData
|
||||
// If there's an update, use NCUpdateResultNewData
|
||||
[self loadData];
|
||||
[self draw];
|
||||
|
||||
completionHandler(NCUpdateResultNewData);
|
||||
}
|
||||
|
||||
- (void)launchAppWithURL:(NSURL *) url {
|
||||
[self.extensionContext openURL:url
|
||||
completionHandler:nil];
|
||||
}
|
||||
|
||||
- (void)launchOnChatConversationViewWithId:(NSString *)chatId {
|
||||
[self launchAppWithURL:[NSURL URLWithString:[@"linphone-widget://chatroom/show?" stringByAppendingString:chatId]]];
|
||||
}
|
||||
|
||||
- (IBAction)firstButtonTapped {
|
||||
[self launchOnChatConversationViewWithId:_addresses[0]];
|
||||
}
|
||||
|
||||
- (IBAction)secondButtonTapped {
|
||||
[self launchOnChatConversationViewWithId:_addresses[1]];
|
||||
}
|
||||
|
||||
- (IBAction)thirdButtonTapped {
|
||||
[self launchOnChatConversationViewWithId:_addresses[2]];
|
||||
}
|
||||
|
||||
- (IBAction)fourthButtonTapped {
|
||||
[self launchOnChatConversationViewWithId:_addresses[3]];
|
||||
}
|
||||
@end
|
||||
|
|
|
|||
10
latestChatroomsWidget/latestChatroomsWidget.entitlements
Normal file
10
latestChatroomsWidget/latestChatroomsWidget.entitlements
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.belledonne-communications.linphone.widget</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
Loading…
Add table
Reference in a new issue