Setting for Image Compression.

pull/1/head
dtsbourg 10 years ago committed by Frederic Jacobs
parent 224cea7773
commit f2217cacd7

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C68k" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
@ -2887,6 +2887,104 @@ Licensed under the GPLv3</string>
<segue destination="8Xl-8d-r8m" kind="show" id="Vv8-VV-3Hv"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="imageUploadQuality" rowHeight="60" id="UYv-h0-6xf" customClass="SettingsTableViewCell">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="UYv-h0-6xf" id="cYD-8i-Zwo">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Image Upload Quality" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d8R-ua-yQv">
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="307" id="rGA-1F-k0N">
<variation key="heightClass=regular-widthClass=compact" constant="200"/>
</constraint>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
<exclude reference="rGA-1F-k0N"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=compact">
<mask key="constraints">
<include reference="rGA-1F-k0N"/>
</mask>
</variation>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Current" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rRX-8L-Jga">
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="307" id="Gnm-ai-ti7">
<variation key="heightClass=regular-widthClass=compact" constant="200"/>
</constraint>
<constraint firstAttribute="width" constant="62" id="dvA-6V-T6S"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Light" family="Helvetica Neue" pointSize="17"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
<exclude reference="Gnm-ai-ti7"/>
<exclude reference="dvA-6V-T6S"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=compact">
<mask key="constraints">
<exclude reference="Gnm-ai-ti7"/>
<include reference="dvA-6V-T6S"/>
</mask>
</variation>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="rRX-8L-Jga" secondAttribute="trailing" constant="-8" id="FFc-XP-Ppr"/>
<constraint firstAttribute="centerY" secondItem="d8R-ua-yQv" secondAttribute="centerY" constant="0.5" id="Pi0-Up-gOI">
<variation key="heightClass=regular-widthClass=compact" constant="0.0"/>
</constraint>
<constraint firstItem="d8R-ua-yQv" firstAttribute="leading" secondItem="cYD-8i-Zwo" secondAttribute="leadingMargin" id="YkD-aW-EwA">
<variation key="heightClass=regular-widthClass=compact" constant="7"/>
</constraint>
<constraint firstItem="d8R-ua-yQv" firstAttribute="centerY" secondItem="rRX-8L-Jga" secondAttribute="centerY" id="beE-hr-geV"/>
<constraint firstAttribute="trailingMargin" secondItem="d8R-ua-yQv" secondAttribute="trailing" constant="70" id="fEf-dt-paZ"/>
<constraint firstItem="d8R-ua-yQv" firstAttribute="top" secondItem="cYD-8i-Zwo" secondAttribute="topMargin" constant="3" id="uLM-ey-uCo">
<variation key="heightClass=regular-widthClass=compact" constant="11"/>
</constraint>
</constraints>
<variation key="default">
<mask key="subviews">
<exclude reference="d8R-ua-yQv"/>
<exclude reference="rRX-8L-Jga"/>
</mask>
<mask key="constraints">
<exclude reference="Pi0-Up-gOI"/>
<exclude reference="YkD-aW-EwA"/>
<exclude reference="beE-hr-geV"/>
<exclude reference="fEf-dt-paZ"/>
<exclude reference="uLM-ey-uCo"/>
<exclude reference="FFc-XP-Ppr"/>
</mask>
</variation>
<variation key="heightClass=regular-widthClass=compact">
<mask key="subviews">
<include reference="d8R-ua-yQv"/>
<include reference="rRX-8L-Jga"/>
</mask>
<mask key="constraints">
<include reference="Pi0-Up-gOI"/>
<include reference="YkD-aW-EwA"/>
<include reference="beE-hr-geV"/>
<exclude reference="fEf-dt-paZ"/>
<exclude reference="uLM-ey-uCo"/>
<include reference="FFc-XP-Ppr"/>
</mask>
</variation>
</tableViewCellContentView>
<connections>
<outlet property="detailLabel" destination="rRX-8L-Jga" id="Re7-xi-iPD"/>
</connections>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" rowHeight="60" id="qa9-qm-gch">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="qa9-qm-gch" id="TLw-od-YLh">
@ -3416,7 +3514,7 @@ Licensed under the GPLv3</string>
<viewControllerLayoutGuide type="bottom" id="kH6-9L-pzh"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="P0X-AM-Yjw">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="551"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ukg-om-VX3">

@ -9,6 +9,12 @@ typedef NS_ENUM(NSUInteger, NotificationType) {
NotificationNamePreview,
};
typedef NS_ENUM(NSUInteger, TSImageQuality) {
TSImageQualityHigh,
TSImageQualityMedium,
TSImageQualityLow
};
@class PhoneNumber;
@interface PropertyListPreferences (PropertyUtil)
@ -27,6 +33,9 @@ typedef NS_ENUM(NSUInteger, NotificationType) {
-(NotificationType)notificationPreviewType;
-(void)setNotificationPreviewType:(NotificationType)type;
-(TSImageQuality)imageUploadQuality;
-(void)setImageUploadQuality:(TSImageQuality)quality;
-(NSString*)lastRanVersion;
-(NSString*)setAndGetCurrentVersion;

@ -24,6 +24,7 @@
#define SCREEN_SECURITY_KEY @"Screen Security Key"
#define DEBUG_IS_ENABLED_KEY @"Debugging Log Enabled Key"
#define NOTIFICATION_PREVIEW_TYPE_KEY @"Notification Preview Type Key"
#define IMAGE_UPLOAD_QUALITY_KEY @"Image Upload Quality Key"
#define kSignalVersionKey @"SignalUpdateVersionKey"
@ -128,6 +129,20 @@
}
}
-(TSImageQuality)imageUploadQuality {
NSNumber * preference = [self tryGetValueForKey:IMAGE_UPLOAD_QUALITY_KEY];
if (preference) {
return [preference unsignedIntegerValue];
} else {
return TSImageQualityMedium;
}
}
-(void)setImageUploadQuality:(TSImageQuality)quality {
[self setValueForKey:IMAGE_UPLOAD_QUALITY_KEY toValue:@(quality)];
}
-(void)setNotificationPreviewType:(NotificationType)type
{
[self setValueForKey:NOTIFICATION_PREVIEW_TYPE_KEY toValue:@(type)];

@ -48,6 +48,7 @@
#import "Environment.h"
#import "PhoneManager.h"
#import "ContactsManager.h"
#import "PreferencesUtil.h"
static NSTimeInterval const kTSMessageSentDateShowTimeInterval = 5 * 60;
static NSString *const kUpdateGroupSegueIdentifier = @"updateGroupSegue";
@ -662,13 +663,78 @@ typedef enum : NSUInteger {
DDLogWarn(@"Video formats not supported, yet");
} else if (picture_camera) {
DDLogVerbose(@"Sending picture attachement ...");
[[TSMessagesManager sharedManager] sendAttachment:UIImagePNGRepresentation(picture_camera) contentType:@"image/png" thread:self.thread];
[[TSMessagesManager sharedManager] sendAttachment:[self qualityAdjustedAttachmentForImage:picture_camera] contentType:@"image/jpeg" thread:self.thread];
[self finishSendingMessage];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
-(NSData*)qualityAdjustedAttachmentForImage:(UIImage*)image
{
return UIImageJPEGRepresentation([self adjustedImageSizedForSending:image], [self compressionRate]);
}
-(UIImage*)adjustedImageSizedForSending:(UIImage*)image
{
CGFloat correctedWidth;
switch ([Environment.preferences imageUploadQuality]) {
case TSImageQualityHigh:
correctedWidth = 2048;
break;
case TSImageQualityMedium:
correctedWidth = 1024;
break;
case TSImageQualityLow:
correctedWidth = 512;
break;
default:
break;
}
return [self imageScaled:image toMaxSize:correctedWidth];
}
- (UIImage*)imageScaled:(UIImage *)image toMaxSize:(CGFloat)size
{
CGFloat scaleFactor;
CGFloat aspectRatio = image.size.height / image.size.width;
if( aspectRatio > 1 ) {
scaleFactor = size / image.size.width;
}
else {
scaleFactor = size / image.size.height;
}
CGSize newSize = CGSizeMake(image.size.width * scaleFactor, image.size.height * scaleFactor);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* updatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return updatedImage;
}
-(CGFloat)compressionRate
{
switch ([Environment.preferences imageUploadQuality]) {
case TSImageQualityHigh:
return 0.9f;
break;
case TSImageQualityMedium:
return 0.5f;
break;
case TSImageQualityLow:
return 0.3f;
break;
default:
break;
}
}
#pragma mark Storage access
- (YapDatabaseConnection*)uiDatabaseConnection {

@ -10,7 +10,10 @@
@interface SettingsTableViewCell : UITableViewCell
//Regular cell
-(void)updateImageQualityLabel;
//Optionals
@property(nonatomic, strong) IBOutlet UISwitch* toggle;
@property(nonatomic,strong) IBOutlet UILabel* detailLabel;
@end

@ -14,16 +14,19 @@
@implementation SettingsTableViewCell
- (void)awakeFromNib {
// Initialization code
[self.toggle setOn:[Environment.preferences screenSecurityIsEnabled]];
[self.toggle addTarget:self action:@selector(toggleSetting:) forControlEvents:UIControlEventValueChanged];
if (self.toggle) {
[self.toggle setOn:[Environment.preferences screenSecurityIsEnabled]];
[self.toggle addTarget:self action:@selector(toggleSetting:) forControlEvents:UIControlEventValueChanged];
}
if ([self.reuseIdentifier isEqualToString:@"imageUploadQuality"]) {
[self updateImageQualityLabel];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#pragma mark - UISwitch
@ -35,5 +38,24 @@
}
}
#pragma mark - Detail Label
-(void)updateImageQualityLabel
{
switch ([Environment.preferences imageUploadQuality]) {
case TSImageQualityHigh:
self.detailLabel.text = @"High";
break;
case TSImageQualityMedium:
self.detailLabel.text = @"Medium";
break;
case TSImageQualityLow:
self.detailLabel.text = @"Low";
break;
default:
DDLogWarn(@"Unknown Image Quality setting : %ld <%s>", [Environment.preferences imageUploadQuality], __PRETTY_FUNCTION__);
break;
}
}
@end

@ -12,6 +12,8 @@
#import "TSAccountManager.h"
#import "TSStorageManager.h"
#import "Environment.h"
#import "PreferencesUtil.h"
#import "RPServerRequestsManager.h"
@ -22,15 +24,16 @@
#define kNumberOfSections 2
#define kClearHistoryLogCellRow 2
#define kMessageDisplayCellRow 3
#define kSendDebugLogCellRow 4
#define kUnregisterCell 5
#define kMessageDisplayCellRow 1
#define kImageQualitySettingRow 2
#define kClearHistoryLogCellRow 3
#define kSendDebugLogCellRow 5
#define kUnregisterCell 6
typedef enum {
kProfileRows = 1,
kSecurityRows = 6,
kSecurityRows = 7,
} kRowsForSection;
typedef enum {
@ -115,6 +118,43 @@ typedef enum {
break;
}
case kImageQualitySettingRow:
{
[DJWActionSheet showInView:self.tabBarController.view
withTitle:nil
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@[@"High", @"Medium", @"Low"]
tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
DDLogVerbose(@"User Cancelled <%s>", __PRETTY_FUNCTION__);
} else if (tappedButtonIndex == actionSheet.destructiveButtonIndex) {
DDLogVerbose(@"Destructive button tapped <%s>", __PRETTY_FUNCTION__);
}else {
switch (tappedButtonIndex) {
case 0:
[Environment.preferences setImageUploadQuality:TSImageQualityHigh];
break;
case 1:
[Environment.preferences setImageUploadQuality:TSImageQualityMedium];
break;
case 2:
[Environment.preferences setImageUploadQuality:TSImageQualityLow];
break;
default:
DDLogWarn(@"Illegal Image Quality Tapped in <%s>", __PRETTY_FUNCTION__);
break;
}
SettingsTableViewCell * cell = (SettingsTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
[cell updateImageQualityLabel];
}
}];
break;
}
case kSendDebugLogCellRow:
[Pastelog submitLogs];

Loading…
Cancel
Save