Skip to content

Commit

Permalink
Merge pull request #4721 from vector-im/doug/4479_media_size_selection
Browse files Browse the repository at this point in the history
Media size selection
  • Loading branch information
pixlwave authored Sep 7, 2021
2 parents 1090b2a + e8bc470 commit c6e7df5
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 51 deletions.
1 change: 1 addition & 0 deletions Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ final class BuildSettings: NSObject {
static let settingsScreenShowThreepidExplanatory: Bool = true
static let settingsScreenShowDiscoverySettings: Bool = true
static let settingsScreenAllowIdentityServerConfig: Bool = true
static let settingsScreenShowConfirmMediaSize: Bool = true
static let settingsScreenShowAdvancedSettings: Bool = true
static let settingsScreenShowLabSettings: Bool = true
static let settingsScreenAllowChangingRageshakeSettings: Bool = true
Expand Down
4 changes: 4 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ Tap the + to start adding people.";
"settings_config_user_id" = "Logged in as %@";

"settings_user_settings" = "USER SETTINGS";
"settings_sending_media" = "SENDING IMAGES AND VIDEOS";
"settings_notifications" = "NOTIFICATIONS";
"settings_calls_settings" = "CALLS";
"settings_discovery_settings" = "DISCOVERY";
Expand Down Expand Up @@ -489,6 +490,9 @@ Tap the + to start adding people.";
"settings_three_pids_management_information_part2" = "Discovery";
"settings_three_pids_management_information_part3" = ".";

"settings_confirm_media_size" = "Confirm size when sending";
"settings_confirm_media_size_description" = "When this is on, you’ll be asked to confirm what size images and videos will be sent as.";

"settings_security" = "SECURITY";

"settings_enable_push_notif" = "Notifications on this device";
Expand Down
12 changes: 12 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4078,6 +4078,14 @@ internal enum VectorL10n {
internal static func settingsConfigUserId(_ p1: String) -> String {
return VectorL10n.tr("Vector", "settings_config_user_id", p1)
}
/// Confirm size when sending
internal static var settingsConfirmMediaSize: String {
return VectorL10n.tr("Vector", "settings_confirm_media_size")
}
/// When this is on, you’ll be asked to confirm what size images and videos will be sent as.
internal static var settingsConfirmMediaSizeDescription: String {
return VectorL10n.tr("Vector", "settings_confirm_media_size_description")
}
/// confirm password
internal static var settingsConfirmPassword: String {
return VectorL10n.tr("Vector", "settings_confirm_password")
Expand Down Expand Up @@ -4546,6 +4554,10 @@ internal enum VectorL10n {
internal static var settingsSendCrashReport: String {
return VectorL10n.tr("Vector", "settings_send_crash_report")
}
/// SENDING IMAGES AND VIDEOS
internal static var settingsSendingMedia: String {
return VectorL10n.tr("Vector", "settings_sending_media")
}
/// Show decrypted content
internal static var settingsShowDecryptedContent: String {
return VectorL10n.tr("Vector", "settings_show_decrypted_content")
Expand Down
5 changes: 5 additions & 0 deletions Riot/Managers/Settings/RiotSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ final class RiotSettings: NSObject {
@UserDefault(key: "allowInviteExernalUsers", defaultValue: BuildSettings.allowInviteExernalUsers, storage: defaults)
var allowInviteExernalUsers

/// When set to false the original image is sent and a 1080p preset is used for videos.
/// If `BuildSettings.roomInputToolbarCompressionMode` has a value other than prompt, the build setting takes priority for images.
@UserDefault(key: "showMediaCompressionPrompt", defaultValue: false, storage: defaults)
var showMediaCompressionPrompt

// MARK: - Main Tabs

@UserDefault(key: "homeScreenShowFavouritesTab", defaultValue: BuildSettings.homeScreenShowFavouritesTab, storage: defaults)
Expand Down
1 change: 1 addition & 0 deletions Riot/Modules/Camera/CameraPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import AVFoundation
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerController.SourceType.camera
imagePickerController.mediaTypes = mediaTypes
imagePickerController.videoQuality = .typeHigh
imagePickerController.allowsEditing = false

return imagePickerController
Expand Down
71 changes: 57 additions & 14 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@

#import "TypingUserInfo.h"

#import "MXSDKOptions.h"

#import "Riot-Swift.h"

NSNotificationName const RoomCallTileTappedNotification = @"RoomCallTileTappedNotification";
Expand Down Expand Up @@ -2004,6 +2006,46 @@ - (void)roomInputToolbarViewDidTapFileUpload
self.documentPickerPresenter = documentPickerPresenter;
}

/**
Send a video asset via the room input toolbar prompting the user for the conversion preset to use
if the `showMediaCompressionPrompt` setting has been enabled.
@param videoAsset The video asset to send
@param isPhotoLibraryAsset Whether the asset was picked from the user's photo library.
*/
- (void)sendVideoAsset:(AVAsset *)videoAsset isPhotoLibraryAsset:(BOOL)isPhotoLibraryAsset
{
RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (!roomInputToolbarView)
{
return;
}

if (RiotSettings.shared.showMediaCompressionPrompt)
{
// Show the video conversion prompt for the user to select what size video they would like to send.
UIAlertController *compressionPrompt = [MXKTools videoConversionPromptForVideoAsset:videoAsset
withCompletion:^(NSString *presetName) {
// When the preset name is missing, the user cancelled.
if (!presetName)
{
return;
}

// Set the chosen preset and send the video (conversion takes place in the SDK).
[MXSDKOptions sharedInstance].videoConversionPresetName = presetName;
[roomInputToolbarView sendSelectedVideoAsset:videoAsset isPhotoLibraryAsset:isPhotoLibraryAsset];
}];

[self presentViewController:compressionPrompt animated:YES completion:nil];
}
else
{
// Otherwise default to 1080p and send the video.
[MXSDKOptions sharedInstance].videoConversionPresetName = AVAssetExportPreset1920x1080;
[roomInputToolbarView sendSelectedVideoAsset:videoAsset isPhotoLibraryAsset:isPhotoLibraryAsset];
}
}

#pragma mark - Dialpad

- (void)openDialpad
Expand Down Expand Up @@ -6071,7 +6113,10 @@ - (void)cameraPresenter:(CameraPresenter *)cameraPresenter didSelectImageData:(N
RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (roomInputToolbarView)
{
[roomInputToolbarView sendSelectedImage:imageData withMimeType:uti.mimeType andCompressionMode:BuildSettings.roomInputToolbarCompressionMode isPhotoLibraryAsset:NO];
[roomInputToolbarView sendSelectedImage:imageData
withMimeType:uti.mimeType
andCompressionMode:MediaCompressionHelper.defaultCompressionMode
isPhotoLibraryAsset:NO];
}
}

Expand All @@ -6080,12 +6125,8 @@ - (void)cameraPresenter:(CameraPresenter *)cameraPresenter didSelectVideoAt:(NSU
[cameraPresenter dismissWithAnimated:YES completion:nil];
self.cameraPresenter = nil;

RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (roomInputToolbarView)
{
AVURLAsset *selectedVideo = [AVURLAsset assetWithURL:url];
[roomInputToolbarView sendSelectedVideoAsset:selectedVideo isPhotoLibraryAsset:NO];
}
AVURLAsset *selectedVideo = [AVURLAsset assetWithURL:url];
[self sendVideoAsset:selectedVideo isPhotoLibraryAsset:NO];
}

#pragma mark - MediaPickerCoordinatorBridgePresenterDelegate
Expand All @@ -6104,7 +6145,10 @@ - (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePrese
RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (roomInputToolbarView)
{
[roomInputToolbarView sendSelectedImage:imageData withMimeType:uti.mimeType andCompressionMode:BuildSettings.roomInputToolbarCompressionMode isPhotoLibraryAsset:YES];
[roomInputToolbarView sendSelectedImage:imageData
withMimeType:uti.mimeType
andCompressionMode:MediaCompressionHelper.defaultCompressionMode
isPhotoLibraryAsset:YES];
}
}

Expand All @@ -6113,11 +6157,7 @@ - (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePrese
[coordinatorBridgePresenter dismissWithAnimated:YES completion:nil];
self.mediaPickerPresenter = nil;

RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (roomInputToolbarView)
{
[roomInputToolbarView sendSelectedVideoAsset:videoAsset isPhotoLibraryAsset:YES];
}
[self sendVideoAsset:videoAsset isPhotoLibraryAsset:YES];
}

- (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePresenter *)coordinatorBridgePresenter didSelectAssets:(NSArray<PHAsset *> *)assets
Expand All @@ -6128,7 +6168,10 @@ - (void)mediaPickerCoordinatorBridgePresenter:(MediaPickerCoordinatorBridgePrese
RoomInputToolbarView *roomInputToolbarView = [self inputToolbarViewAsRoomInputToolbarView];
if (roomInputToolbarView)
{
[roomInputToolbarView sendSelectedAssets:assets withCompressionMode:BuildSettings.roomInputToolbarCompressionMode];
// Set a 1080p video conversion preset as compression mode only has an effect on the images.
[MXSDKOptions sharedInstance].videoConversionPresetName = AVAssetExportPreset1920x1080;

[roomInputToolbarView sendSelectedAssets:assets withCompressionMode:MediaCompressionHelper.defaultCompressionMode];
}
}

Expand Down
45 changes: 45 additions & 0 deletions Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
{
SECTION_TAG_SIGN_OUT = 0,
SECTION_TAG_USER_SETTINGS,
SECTION_TAG_SENDING_MEDIA,
SECTION_TAG_SECURITY,
SECTION_TAG_NOTIFICATIONS,
SECTION_TAG_CALLS,
Expand Down Expand Up @@ -86,6 +87,12 @@
USER_SETTINGS_PHONENUMBERS_OFFSET = 1000
};

enum
{
SENDING_MEDIA_CONFIRM_SIZE = 0,
SENDING_MEDIA_CONFIRM_SIZE_DESCRIPTION,
};

enum
{
NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX = 0,
Expand Down Expand Up @@ -354,6 +361,15 @@ - (void)updateSections
sectionUserSettings.headerTitle = NSLocalizedStringFromTable(@"settings_user_settings", @"Vector", nil);
[tmpSections addObject:sectionUserSettings];

if (BuildSettings.settingsScreenShowConfirmMediaSize)
{
Section *sectionMedia = [Section sectionWithTag:SECTION_TAG_SENDING_MEDIA];
[sectionMedia addRowWithTag:SENDING_MEDIA_CONFIRM_SIZE];
[sectionMedia addRowWithTag:SENDING_MEDIA_CONFIRM_SIZE_DESCRIPTION];
sectionMedia.headerTitle = NSLocalizedStringFromTable(@"settings_sending_media", @"Vector", nil);
[tmpSections addObject:sectionMedia];
}

Section *sectionSecurity = [Section sectionWithTag:SECTION_TAG_SECURITY];
[sectionSecurity addRowWithTag:SECURITY_BUTTON_INDEX];
sectionSecurity.headerTitle = NSLocalizedStringFromTable(@"settings_security", @"Vector", nil);
Expand Down Expand Up @@ -1827,6 +1843,30 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = passwordCell;
}
}
else if (section == SECTION_TAG_SENDING_MEDIA)
{
if (row == SENDING_MEDIA_CONFIRM_SIZE)
{
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];

labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_confirm_media_size", @"Vector", nil);
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.showMediaCompressionPrompt;
labelAndSwitchCell.mxkSwitch.onTintColor = ThemeService.shared.theme.tintColor;
labelAndSwitchCell.mxkSwitch.enabled = YES;
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleConfirmMediaSize:) forControlEvents:UIControlEventTouchUpInside];

cell = labelAndSwitchCell;
}
else if (row == SENDING_MEDIA_CONFIRM_SIZE_DESCRIPTION)
{
MXKTableViewCell *infoCell = [self getDefaultTableViewCell:tableView];
infoCell.textLabel.text = NSLocalizedStringFromTable(@"settings_confirm_media_size_description", @"Vector", nil);
infoCell.textLabel.numberOfLines = 0;
infoCell.selectionStyle = UITableViewCellSelectionStyleNone;

cell = infoCell;
}
}
else if (section == SECTION_TAG_NOTIFICATIONS)
{
if (row == NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX)
Expand Down Expand Up @@ -2896,6 +2936,11 @@ - (void)onRemove3PID:(NSIndexPath*)indexPath
}
}

- (void)toggleConfirmMediaSize:(UISwitch *)sender
{
RiotSettings.shared.showMediaCompressionPrompt = sender.on;
}

- (void)togglePushNotifications:(UISwitch *)sender
{
// Check first whether the user allow notification from system settings
Expand Down
32 changes: 32 additions & 0 deletions Riot/Utils/MediaCompressionHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright 2021 New Vector 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 Foundation

/// A collection of helpful functions for media compression.
class MediaCompressionHelper: NSObject {
/// The default compression mode taking into account the `roomInputToolbarCompressionMode` build setting
/// and the `showMediaCompressionPrompt` Riot setting.
@objc static var defaultCompressionMode: MXKRoomInputToolbarCompressionMode {
// When the compression mode build setting hasn't been customised, use the media compression prompt setting to determine what to do.
if BuildSettings.roomInputToolbarCompressionMode == MXKRoomInputToolbarCompressionModePrompt {
return RiotSettings.shared.showMediaCompressionPrompt ? MXKRoomInputToolbarCompressionModePrompt : MXKRoomInputToolbarCompressionModeNone
} else {
// Otherwise use the compression mode defined in the build settings.
return BuildSettings.roomInputToolbarCompressionMode
}
}
}
Loading

0 comments on commit c6e7df5

Please sign in to comment.