Merge MatrixKit develop with commit hash: b85b736313bec0592bd1cabc68035d97f5331137

This commit is contained in:
SBiOSoftWhare
2021-12-03 11:47:24 +01:00
parent 8d15fe55a2
commit e7d4cd7707
475 changed files with 87437 additions and 0 deletions
@@ -0,0 +1,67 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <MatrixSDK/MatrixSDK.h>
#import "MXKTableViewCell.h"
/**
MXPushRuleCreationTableViewCell instance is a table view cell used to create a new push rule.
*/
@interface MXKPushRuleCreationTableViewCell : MXKTableViewCell <UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate>
/**
The category the created push rule will belongs to (MXPushRuleKindContent by default).
*/
@property (nonatomic) MXPushRuleKind mxPushRuleKind;
/**
The related matrix session
*/
@property (nonatomic) MXSession* mxSession;
/**
The graphics items
*/
@property (strong, nonatomic) IBOutlet UITextField* inputTextField;
@property (unsafe_unretained, nonatomic) IBOutlet UISegmentedControl *actionSegmentedControl;
@property (unsafe_unretained, nonatomic) IBOutlet UISwitch *soundSwitch;
@property (unsafe_unretained, nonatomic) IBOutlet UISwitch *highlightSwitch;
@property (strong, nonatomic) IBOutlet UIButton* addButton;
@property (strong, nonatomic) IBOutlet UIPickerView* roomPicker;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *roomPickerDoneButton;
/**
Force dismiss keyboard.
*/
- (void)dismissKeyboard;
/**
Action registered to handle text field editing change (UIControlEventEditingChanged).
*/
- (IBAction)textFieldEditingChanged:(id)sender;
/**
Action registered on the following events:
- 'UIControlEventTouchUpInside' for UIButton instances.
- 'UIControlEventValueChanged' for UISwitch and UISegmentedControl instances.
*/
- (IBAction)onButtonPressed:(id)sender;
@end
@@ -0,0 +1,208 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "MXKPushRuleCreationTableViewCell.h"
#import "NSBundle+MatrixKit.h"
#import "MXKSwiftHeader.h"
@interface MXKPushRuleCreationTableViewCell ()
{
/**
Snapshot of matrix session rooms used in room picker (in case of MXPushRuleKindRoom)
*/
NSArray* rooms;
}
@end
@implementation MXKPushRuleCreationTableViewCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.mxPushRuleKind = MXPushRuleKindContent;
}
- (void)setMxPushRuleKind:(MXPushRuleKind)mxPushRuleKind
{
switch (mxPushRuleKind)
{
case MXPushRuleKindContent:
_inputTextField.placeholder = [MatrixKitL10n notificationSettingsWordToMatch];
_inputTextField.autocorrectionType = UITextAutocorrectionTypeDefault;
break;
case MXPushRuleKindRoom:
_inputTextField.placeholder = [MatrixKitL10n notificationSettingsSelectRoom];
break;
case MXPushRuleKindSender:
_inputTextField.placeholder = [MatrixKitL10n notificationSettingsSenderHint];
_inputTextField.autocorrectionType = UITextAutocorrectionTypeNo;
break;
default:
break;
}
_inputTextField.hidden = NO;
_roomPicker.hidden = YES;
_roomPickerDoneButton.hidden = YES;
_mxPushRuleKind = mxPushRuleKind;
}
- (void)dismissKeyboard
{
[_inputTextField resignFirstResponder];
}
#pragma mark - UITextField delegate
- (IBAction)textFieldEditingChanged:(id)sender
{
// Update Add Room button
if (_inputTextField.text.length)
{
_addButton.enabled = YES;
}
else
{
_addButton.enabled = NO;
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField == _inputTextField && _mxPushRuleKind == MXPushRuleKindRoom)
{
_inputTextField.hidden = YES;
_roomPicker.hidden = NO;
_roomPickerDoneButton.hidden = NO;
return NO;
}
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == _inputTextField && _mxPushRuleKind == MXPushRuleKindSender)
{
if (textField.text.length == 0)
{
textField.text = @"@";
}
}
}
- (BOOL)textFieldShouldReturn:(UITextField*) textField
{
// "Done" key has been pressed
[textField resignFirstResponder];
return YES;
}
#pragma mark - Actions
- (IBAction)onButtonPressed:(id)sender
{
[self dismissKeyboard];
if (sender == _addButton)
{
// Disable button to prevent multiple request
_addButton.enabled = NO;
if (_mxPushRuleKind == MXPushRuleKindContent)
{
[_mxSession.notificationCenter addContentRule:_inputTextField.text
notify:(_actionSegmentedControl.selectedSegmentIndex == 0)
sound:_soundSwitch.on
highlight:_highlightSwitch.on];
}
else if (_mxPushRuleKind == MXPushRuleKindRoom)
{
MXRoom* room;
NSInteger row = [_roomPicker selectedRowInComponent:0];
if ((row >= 0) && (row < rooms.count))
{
room = [rooms objectAtIndex:row];
}
if (room)
{
[_mxSession.notificationCenter addRoomRule:room.roomId
notify:(_actionSegmentedControl.selectedSegmentIndex == 0)
sound:_soundSwitch.on
highlight:_highlightSwitch.on];
}
}
else if (_mxPushRuleKind == MXPushRuleKindSender)
{
[_mxSession.notificationCenter addSenderRule:_inputTextField.text
notify:(_actionSegmentedControl.selectedSegmentIndex == 0)
sound:_soundSwitch.on
highlight:_highlightSwitch.on];
}
_inputTextField.text = nil;
}
else if (sender == _roomPickerDoneButton)
{
NSInteger row = [_roomPicker selectedRowInComponent:0];
// sanity check
if ((row >= 0) && (row < rooms.count))
{
MXRoom* room = [rooms objectAtIndex:row];
_inputTextField.text = room.summary.displayname;
_addButton.enabled = YES;
}
_inputTextField.hidden = NO;
_roomPicker.hidden = YES;
_roomPickerDoneButton.hidden = YES;
}
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
rooms = [_mxSession.rooms sortedArrayUsingComparator:^NSComparisonResult(MXRoom* firstRoom, MXRoom* secondRoom) {
// Alphabetic order
return [firstRoom.summary.displayname compare:secondRoom.summary.displayname options:NSCaseInsensitiveSearch];
}];
return rooms.count;
}
#pragma mark - UIPickerViewDelegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
MXRoom* room = [rooms objectAtIndex:row];
return room.summary.displayname;
}
@end
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="100" id="odA-la-SwE" customClass="MXKPushRuleCreationTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="600" height="120"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="odA-la-SwE" id="Ice-YN-Ffy">
<rect key="frame" x="0.0" y="0.0" width="600" height="119"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Wwh-3Z-z7F" userLabel="input Text Field">
<rect key="frame" x="8" y="8" width="546" height="30"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="done"/>
<connections>
<action selector="textFieldEditingChanged:" destination="odA-la-SwE" eventType="editingChanged" id="ivl-8t-XsA"/>
<outlet property="delegate" destination="odA-la-SwE" id="Xax-eN-mqc"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="contactAdd" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sMf-pD-nYN" userLabel="add Button">
<rect key="frame" x="562" y="8" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="9xs-Pn-KoC"/>
<constraint firstAttribute="height" constant="30" id="PdY-qO-X5W"/>
</constraints>
<state key="normal">
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="touchUpInside" id="ml4-uK-KMC"/>
</connections>
</button>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="4Bt-EK-JDS">
<rect key="frame" x="8" y="46" width="273" height="29"/>
<segments>
<segment title="Always Notify"/>
<segment title="Never Notify"/>
</segments>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="valueChanged" id="PtA-K2-021"/>
</connections>
</segmentedControl>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sound:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bRv-hA-dFH">
<rect key="frame" x="357.5" y="87" width="45.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="lwC-Mg-bJ2" userLabel="sound Switch">
<rect key="frame" x="411" y="80" width="51" height="31"/>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="valueChanged" id="okw-8q-GHg"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Highlight:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aQf-3y-ZeE">
<rect key="frame" x="468" y="87" width="63" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="2lY-ne-Uzm" userLabel="highlight Switch">
<rect key="frame" x="539" y="80" width="51" height="31"/>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="valueChanged" id="pIo-K0-3Vj"/>
</connections>
</switch>
<pickerView hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4YJ-sM-Eyq" userLabel="Room Picker View">
<rect key="frame" x="0.0" y="0.0" width="600" height="119.5"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="dataSource" destination="odA-la-SwE" id="SoZ-Lh-rcQ"/>
<outlet property="delegate" destination="odA-la-SwE" id="YPx-UY-MPp"/>
</connections>
</pickerView>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="na4-JH-zWr">
<rect key="frame" x="563" y="0.0" width="37" height="30"/>
<state key="normal" title="Done"/>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="touchUpInside" id="z4A-OA-GOO"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="2lY-ne-Uzm" secondAttribute="bottom" constant="8" id="4uG-g4-RI4"/>
<constraint firstItem="4Bt-EK-JDS" firstAttribute="width" relation="greaterThanOrEqual" secondItem="Wwh-3Z-z7F" secondAttribute="width" multiplier="0.5" id="6lL-rQ-mkF"/>
<constraint firstItem="Wwh-3Z-z7F" firstAttribute="leading" secondItem="Ice-YN-Ffy" secondAttribute="leading" constant="8" id="782-mf-jUX"/>
<constraint firstAttribute="trailing" secondItem="4YJ-sM-Eyq" secondAttribute="trailing" id="AKi-Nk-Ms8"/>
<constraint firstItem="sMf-pD-nYN" firstAttribute="centerY" secondItem="Wwh-3Z-z7F" secondAttribute="centerY" id="CcL-nP-nGq"/>
<constraint firstItem="lwC-Mg-bJ2" firstAttribute="leading" secondItem="bRv-hA-dFH" secondAttribute="trailing" constant="8" id="G1v-5M-3j6"/>
<constraint firstItem="2lY-ne-Uzm" firstAttribute="leading" secondItem="aQf-3y-ZeE" secondAttribute="trailing" constant="8" id="Ibh-BF-E33"/>
<constraint firstItem="bRv-hA-dFH" firstAttribute="centerY" secondItem="lwC-Mg-bJ2" secondAttribute="centerY" id="MZl-5M-vEN"/>
<constraint firstItem="Wwh-3Z-z7F" firstAttribute="top" secondItem="Ice-YN-Ffy" secondAttribute="top" constant="8" id="OCq-8g-V8a"/>
<constraint firstItem="2lY-ne-Uzm" firstAttribute="centerY" secondItem="lwC-Mg-bJ2" secondAttribute="centerY" id="QjH-Dg-ioK"/>
<constraint firstItem="4YJ-sM-Eyq" firstAttribute="leading" secondItem="Ice-YN-Ffy" secondAttribute="leading" id="Qwu-hZ-j55"/>
<constraint firstItem="aQf-3y-ZeE" firstAttribute="leading" secondItem="lwC-Mg-bJ2" secondAttribute="trailing" constant="8" id="RQP-g9-afW"/>
<constraint firstItem="sMf-pD-nYN" firstAttribute="leading" secondItem="Wwh-3Z-z7F" secondAttribute="trailing" constant="8" id="T94-hg-JLi"/>
<constraint firstItem="aQf-3y-ZeE" firstAttribute="centerY" secondItem="2lY-ne-Uzm" secondAttribute="centerY" id="WOc-OU-60a"/>
<constraint firstAttribute="trailing" secondItem="na4-JH-zWr" secondAttribute="trailing" id="b6f-dP-HI4"/>
<constraint firstItem="na4-JH-zWr" firstAttribute="top" secondItem="Ice-YN-Ffy" secondAttribute="top" id="cCI-wg-eqv"/>
<constraint firstItem="4YJ-sM-Eyq" firstAttribute="top" secondItem="Ice-YN-Ffy" secondAttribute="top" id="ca3-mx-Lsd"/>
<constraint firstAttribute="centerY" secondItem="4Bt-EK-JDS" secondAttribute="centerY" id="g9a-O2-NG3"/>
<constraint firstAttribute="trailing" secondItem="sMf-pD-nYN" secondAttribute="trailing" constant="8" id="imD-jM-dTY"/>
<constraint firstItem="4Bt-EK-JDS" firstAttribute="leading" secondItem="Ice-YN-Ffy" secondAttribute="leading" constant="8" id="lFI-Gm-IJE"/>
<constraint firstAttribute="bottom" secondItem="4YJ-sM-Eyq" secondAttribute="bottom" id="mUK-bs-iv0"/>
<constraint firstAttribute="trailing" secondItem="2lY-ne-Uzm" secondAttribute="trailing" constant="12" id="mzL-Jd-jiR"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="actionSegmentedControl" destination="4Bt-EK-JDS" id="rV5-NL-F4o"/>
<outlet property="addButton" destination="sMf-pD-nYN" id="kbu-pj-Phj"/>
<outlet property="highlightSwitch" destination="2lY-ne-Uzm" id="28l-f6-PBF"/>
<outlet property="inputTextField" destination="Wwh-3Z-z7F" id="xv5-7G-Pqj"/>
<outlet property="roomPicker" destination="4YJ-sM-Eyq" id="NKT-cO-AGo"/>
<outlet property="roomPickerDoneButton" destination="na4-JH-zWr" id="lCs-qp-Hdr"/>
<outlet property="soundSwitch" destination="lwC-Mg-bJ2" id="3aE-oH-UYx"/>
</connections>
<point key="canvasLocation" x="391" y="402"/>
</tableViewCell>
</objects>
</document>
@@ -0,0 +1,57 @@
/*
Copyright 2015 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <MatrixSDK/MatrixSDK.h>
#import "MXKTableViewCell.h"
/**
MKPushRuleTableViewCell instance is a table view cell used to display a notification rule.
*/
@interface MXKPushRuleTableViewCell : MXKTableViewCell
/**
The displayed rule
*/
@property (nonatomic) MXPushRule* mxPushRule;
/**
The related matrix session
*/
@property (nonatomic) MXSession* mxSession;
/**
The graphics items
*/
@property (strong, nonatomic) IBOutlet UIButton* controlButton;
@property (strong, nonatomic) IBOutlet UIButton* deleteButton;
@property (unsafe_unretained, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidthConstraint;
@property (strong, nonatomic) IBOutlet UILabel* ruleDescription;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ruleDescriptionBottomConstraint;
@property (unsafe_unretained, nonatomic) IBOutlet NSLayoutConstraint *ruleDescriptionLeftConstraint;
@property (strong, nonatomic) IBOutlet UILabel* ruleActions;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ruleActionsHeightConstraint;
/**
Action registered on `UIControlEventTouchUpInside` event for both buttons.
*/
- (IBAction)onButtonPressed:(id)sender;
@end
@@ -0,0 +1,174 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "MXKPushRuleTableViewCell.h"
#import "NSBundle+MatrixKit.h"
#import "MXKSwiftHeader.h"
@implementation MXKPushRuleTableViewCell
- (void)awakeFromNib
{
[super awakeFromNib];
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_pause"] forState:UIControlStateNormal];
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_pause"] forState:UIControlStateHighlighted];
[_deleteButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_minus"] forState:UIControlStateNormal];
[_deleteButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_minus"] forState:UIControlStateHighlighted];
}
- (void)customizeTableViewCellRendering
{
[super customizeTableViewCellRendering];
_controlButton.backgroundColor = [UIColor clearColor];
_deleteButton.backgroundColor = [UIColor clearColor];
_ruleDescription.numberOfLines = 0;
}
- (void)setMxPushRule:(MXPushRule *)mxPushRule
{
// Set the right control icon
if (mxPushRule.enabled)
{
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_pause"] forState:UIControlStateNormal];
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_pause"] forState:UIControlStateHighlighted];
}
else
{
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_play"] forState:UIControlStateNormal];
[_controlButton setImage:[NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_play"] forState:UIControlStateHighlighted];
}
// Prepare rule description (use rule id by default)
NSString *description = mxPushRule.ruleId;
switch (mxPushRule.kind)
{
case MXPushRuleKindContent:
description = mxPushRule.pattern;
break;
case MXPushRuleKindRoom:
{
MXRoom *room = [_mxSession roomWithRoomId:mxPushRule.ruleId];
if (room)
{
description = [MatrixKitL10n notificationSettingsRoomRuleTitle:room.summary.displayname];
}
break;
}
default:
break;
}
_ruleDescription.text = description;
// Delete button and rule actions are hidden for predefined rules
if (mxPushRule.isDefault)
{
if (!_deleteButton.hidden)
{
_deleteButton.hidden = YES;
// Adjust layout by updating constraint
_ruleDescriptionLeftConstraint.constant -= _deleteButtonWidthConstraint.constant;
}
if (!_ruleActions.isHidden)
{
_ruleActions.hidden = YES;
// Adjust layout by updating constraint
_ruleDescriptionBottomConstraint.constant -= _ruleActionsHeightConstraint.constant;
}
}
else
{
if (_deleteButton.hidden)
{
_deleteButton.hidden = NO;
// Adjust layout by updating constraint
_ruleDescriptionLeftConstraint.constant += _deleteButtonWidthConstraint.constant;
}
// Prepare rule actions description
NSString *notify;
NSString *sound = @"";
NSString *highlight = @"";
for (MXPushRuleAction *ruleAction in mxPushRule.actions)
{
if (ruleAction.actionType == MXPushRuleActionTypeDontNotify)
{
notify = [MatrixKitL10n notificationSettingsNeverNotify];
sound = @"";
highlight = @"";
break;
}
else if (ruleAction.actionType == MXPushRuleActionTypeNotify || ruleAction.actionType == MXPushRuleActionTypeCoalesce)
{
notify = [MatrixKitL10n notificationSettingsAlwaysNotify];
}
else if (ruleAction.actionType == MXPushRuleActionTypeSetTweak)
{
if ([ruleAction.parameters[@"set_tweak"] isEqualToString:@"sound"])
{
sound = [NSString stringWithFormat:@", %@", [MatrixKitL10n notificationSettingsCustomSound]];
}
else if ([ruleAction.parameters[@"set_tweak"] isEqualToString:@"highlight"])
{
// Check the highlight tweak "value"
// If not present, highlight. Else check its value before highlighting
if (nil == ruleAction.parameters[@"value"] || YES == [ruleAction.parameters[@"value"] boolValue])
{
highlight = [NSString stringWithFormat:@", %@", [MatrixKitL10n notificationSettingsHighlight]];
}
}
}
}
if (notify.length)
{
_ruleActions.text = [NSString stringWithFormat:@"%@%@%@", notify, sound, highlight];
}
if (_ruleActions.isHidden)
{
_ruleActions.hidden = NO;
// Adjust layout by updating constraint
_ruleDescriptionBottomConstraint.constant += _ruleActionsHeightConstraint.constant;
}
}
_mxPushRule = mxPushRule;
}
- (IBAction)onButtonPressed:(id)sender
{
if (sender == _controlButton)
{
// Swap enable state
[_mxSession.notificationCenter enableRule:_mxPushRule isEnabled:!_mxPushRule.enabled];
}
else if (sender == _deleteButton)
{
[_mxSession.notificationCenter removeRule:_mxPushRule];
}
}
@end
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="odA-la-SwE" customClass="MXKPushRuleTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="600" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="odA-la-SwE" id="Ice-YN-Ffy">
<rect key="frame" x="0.0" y="0.0" width="600" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iWG-aB-Kvb" userLabel="controlButton">
<rect key="frame" x="5" y="10" width="30" height="30"/>
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="VuV-aZ-asl"/>
<constraint firstAttribute="width" constant="30" id="ZYK-wP-XQL"/>
</constraints>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="touchUpInside" id="vDk-Tj-qOK"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rfi-Fa-7Uq" userLabel="ruleDescription">
<rect key="frame" x="43" y="5" width="552" height="39"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="you-3G-2zC" userLabel="ruleActions">
<rect key="frame" x="73" y="25" width="522" height="19"/>
<constraints>
<constraint firstAttribute="height" constant="19" id="BuO-WH-nQ1"/>
</constraints>
<fontDescription key="fontDescription" type="italicSystem" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wyh-BC-Nxb" userLabel="deleteButton">
<rect key="frame" x="35" y="10" width="30" height="30"/>
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="30" id="fKT-Ta-DCC"/>
<constraint firstAttribute="height" constant="30" id="mpD-eM-ruI"/>
</constraints>
<state key="normal">
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onButtonPressed:" destination="odA-la-SwE" eventType="touchUpInside" id="Cm7-6b-yuZ"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="iWG-aB-Kvb" firstAttribute="leading" secondItem="Ice-YN-Ffy" secondAttribute="leading" constant="5" id="0Zg-Ll-azQ"/>
<constraint firstItem="you-3G-2zC" firstAttribute="leading" secondItem="Wyh-BC-Nxb" secondAttribute="trailing" constant="8" id="EZs-yR-hRf"/>
<constraint firstItem="rfi-Fa-7Uq" firstAttribute="leading" secondItem="iWG-aB-Kvb" secondAttribute="trailing" constant="8" id="LNA-AM-aNX"/>
<constraint firstItem="Wyh-BC-Nxb" firstAttribute="leading" secondItem="iWG-aB-Kvb" secondAttribute="trailing" id="LrI-UV-gDa"/>
<constraint firstAttribute="centerY" secondItem="Wyh-BC-Nxb" secondAttribute="centerY" id="QB6-fg-4Gf"/>
<constraint firstAttribute="trailing" secondItem="you-3G-2zC" secondAttribute="trailing" constant="5" id="QoB-AS-kZD"/>
<constraint firstAttribute="bottom" secondItem="you-3G-2zC" secondAttribute="bottom" constant="5" id="Y2g-No-qFm"/>
<constraint firstAttribute="centerY" secondItem="iWG-aB-Kvb" secondAttribute="centerY" id="eBs-sy-U6v"/>
<constraint firstItem="rfi-Fa-7Uq" firstAttribute="top" secondItem="Ice-YN-Ffy" secondAttribute="top" constant="5" id="fAO-c4-ldm"/>
<constraint firstAttribute="bottom" secondItem="rfi-Fa-7Uq" secondAttribute="bottom" constant="5" id="tTB-2B-aYK"/>
<constraint firstAttribute="trailing" secondItem="rfi-Fa-7Uq" secondAttribute="trailing" constant="5" id="v0c-zI-8LX"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="controlButton" destination="iWG-aB-Kvb" id="WOl-F1-EyR"/>
<outlet property="deleteButton" destination="Wyh-BC-Nxb" id="7e8-Us-uiS"/>
<outlet property="deleteButtonWidthConstraint" destination="fKT-Ta-DCC" id="kMc-It-JbI"/>
<outlet property="ruleActions" destination="you-3G-2zC" id="1C0-Dy-1hO"/>
<outlet property="ruleActionsHeightConstraint" destination="BuO-WH-nQ1" id="AOJ-jc-L94"/>
<outlet property="ruleDescription" destination="rfi-Fa-7Uq" id="9uR-Bq-QFM"/>
<outlet property="ruleDescriptionBottomConstraint" destination="tTB-2B-aYK" id="BBj-Lf-Nz3"/>
<outlet property="ruleDescriptionLeftConstraint" destination="LNA-AM-aNX" id="rSS-9A-sVP"/>
</connections>
<point key="canvasLocation" x="213" y="415"/>
</tableViewCell>
</objects>
</document>