Pārlūkot izejas kodu

Merge pull request #794 from deltachat/media_quality

implement media quality settings
nayooti 5 gadi atpakaļ
vecāks
revīzija
bb978503b5

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -92,6 +92,7 @@
 		3060119C22DDE24000C1CE6F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3060119E22DDE24000C1CE6F /* Localizable.strings */; };
 		306011B622E5E7FB00C1CE6F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 306011B422E5E7FB00C1CE6F /* Localizable.stringsdict */; };
 		306C32322445CDE9001D89F3 /* DcLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 306C32312445CDE9001D89F3 /* DcLogger.swift */; };
+		30734326249A280B00BF9AD1 /* MediaQualityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30734325249A280B00BF9AD1 /* MediaQualityController.swift */; };
 		307D822E241669C7006D2490 /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307D822D241669C7006D2490 /* LocationManager.swift */; };
 		308FEA4C2462F11300FCEAD6 /* FileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 308FEA4B2462F11300FCEAD6 /* FileView.swift */; };
 		308FEA50246AB67100FCEAD6 /* FileMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 308FEA4F246AB67100FCEAD6 /* FileMessageCell.swift */; };
@@ -369,6 +370,7 @@
 		306011C822E5E83100C1CE6F /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
 		306011C922E5E83500C1CE6F /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = uk; path = uk.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
 		306C32312445CDE9001D89F3 /* DcLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DcLogger.swift; sourceTree = "<group>"; };
+		30734325249A280B00BF9AD1 /* MediaQualityController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaQualityController.swift; sourceTree = "<group>"; };
 		307D822D241669C7006D2490 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
 		308FEA4B2462F11300FCEAD6 /* FileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileView.swift; sourceTree = "<group>"; };
 		308FEA4F246AB67100FCEAD6 /* FileMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileMessageCell.swift; sourceTree = "<group>"; };
@@ -915,6 +917,7 @@
 				B20462E52440C99600367A57 /* SettingsAutodelSetController.swift */,
 				AE76E5ED242BF2EA003CF461 /* WelcomeViewController.swift */,
 				AE8F503424753DFE007FEE0B /* GalleryViewController.swift */,
+				30734325249A280B00BF9AD1 /* MediaQualityController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -1356,6 +1359,7 @@
 				3040F462234F550300FA34D5 /* AudioPlayerView.swift in Sources */,
 				AE52EA19229EB53C00C586C9 /* ContactDetailHeader.swift in Sources */,
 				78E45E4421D3F14A00D4B15E /* UIImage+Extension.swift in Sources */,
+				30734326249A280B00BF9AD1 /* MediaQualityController.swift in Sources */,
 				3040F460234F419400FA34D5 /* BasicAudioController.swift in Sources */,
 				30A2EC36247D72720024ADD8 /* AnimatedImageMessageCell.swift in Sources */,
 				305962082346125100C80F33 /* MediaMessageSizeCalculator.swift in Sources */,

+ 72 - 0
deltachat-ios/Controller/MediaQualityController.swift

@@ -0,0 +1,72 @@
+import UIKit
+import DcCore
+class MediaQualityController: UITableViewController {
+
+    private var dcContext: DcContext
+
+    private var options: [Int]
+
+    private lazy var staticCells: [UITableViewCell] = {
+        return options.map({
+            let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
+            cell.textLabel?.text = MediaQualityController.getValString(val: $0)
+            cell.selectionStyle = .none
+            return cell
+        })
+    } ()
+
+    init(dcContext: DcContext) {
+        self.dcContext = dcContext
+        self.options = [Int(DC_MEDIA_QUALITY_BALANCED), Int(DC_MEDIA_QUALITY_WORSE)]
+        super.init(style: .grouped)
+        self.title = String.localized("pref_outgoing_media_quality")
+        hidesBottomBarWhenPushed = true
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+    }
+
+    static func getValString(val: Int) -> String {
+        switch Int32(val) {
+        case DC_MEDIA_QUALITY_BALANCED:
+            return String.localized("pref_outgoing_balanced")
+        case DC_MEDIA_QUALITY_WORSE:
+            return String.localized("pref_outgoing_worse")
+        default:
+            return "Err"
+        }
+    }
+
+    // MARK: - Table view data source
+
+    override func numberOfSections(in tableView: UITableView) -> Int {
+        return 1
+    }
+
+    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        return options.count
+    }
+
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let oldSelectedCell = tableView.cellForRow(at: IndexPath.init(row: dcContext.getConfigInt("media_quality"), section: 0))
+        oldSelectedCell?.accessoryType = .none
+
+        let newSelectedCell = tableView.cellForRow(at: IndexPath.init(row: indexPath.row, section: 0))
+        newSelectedCell?.accessoryType = .checkmark
+
+        dcContext.setConfigInt("media_quality", indexPath.row)
+    }
+
+    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let cell = staticCells[indexPath.row]
+        if options[indexPath.row] == dcContext.getConfigInt("media_quality") {
+            cell.accessoryType = .checkmark
+        }
+        return cell
+    }
+}

+ 18 - 3
deltachat-ios/Controller/SettingsController.swift

@@ -23,6 +23,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         case advanced = 9
         case help = 10
         case autodel = 11
+        case mediaQuality = 12
     }
 
     private var dcContext: DcContext
@@ -90,6 +91,15 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         return cell
     }()
 
+    private lazy var mediaQualityCell: UITableViewCell = {
+        let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
+        cell.tag = CellTags.mediaQuality.rawValue
+        cell.textLabel?.text = String.localized("pref_outgoing_media_quality")
+        cell.accessoryType = .disclosureIndicator
+        cell.detailTextLabel?.text = MediaQualityController.getValString(val: dcContext.getConfigInt("media_quality"))
+        return cell
+    }()
+
     private var notificationSwitch: UISwitch = {
         let switchControl = UISwitch()
         switchControl.isOn = !UserDefaults.standard.bool(forKey: "notifications_disabled")
@@ -183,7 +193,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         let preferencesSection = SectionConfigs(
             headerTitle: nil,
             footerTitle: String.localized("pref_read_receipts_explain"),
-            cells: [showEmailsCell, contactRequestCell, blockedContactsCell, autodelCell, notificationCell, receiptConfirmationCell]
+            cells: [showEmailsCell, contactRequestCell, blockedContactsCell, autodelCell, mediaQualityCell, notificationCell, receiptConfirmationCell]
         )
         let autocryptSection = SectionConfigs(
             headerTitle: String.localized("autocrypt"),
@@ -226,7 +236,6 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
     }
 
     override func viewDidAppear(_ animated: Bool) {
-
         super.viewDidAppear(animated)
         addProgressAlertListener(progressName: dcNotificationImexProgress) { [weak self] in
             guard let self = self else { return }
@@ -236,7 +245,6 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
-
         let nc = NotificationCenter.default
         if let backupProgressObserver = self.progressObserver {
             nc.removeObserver(backupProgressObserver)
@@ -270,6 +278,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         case .showEmails: showClassicMail()
         case .blockedContacts: showBlockedContacts()
         case .autodel: showAutodelOptions()
+        case .mediaQuality: showMediaQuality()
         case .notifications: break
         case .receiptConfirmation: break
         case .autocryptPreferences: break
@@ -402,6 +411,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         profileCell.update(contact: selfContact, displayName: displayName, address: email)
 
         showEmailsCell.detailTextLabel?.text = SettingsClassicViewController.getValString(val: dcContext.showEmails)
+        mediaQualityCell.detailTextLabel?.text = MediaQualityController.getValString(val: dcContext.getConfigInt("media_quality"))
 
         autodelCell.detailTextLabel?.text = autodelSummary()
     }
@@ -417,6 +427,11 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         navigationController?.pushViewController(settingsClassicViewController, animated: true)
     }
 
+    private func  showMediaQuality() {
+        let mediaQualityController = MediaQualityController(dcContext: dcContext)
+        navigationController?.pushViewController(mediaQualityController, animated: true)
+    }
+
     private func showBlockedContacts() {
         let blockedContactsController = BlockedContactsViewController()
         navigationController?.pushViewController(blockedContactsController, animated: true)