Browse Source

add option to select background in settings. Implement basic SettingsBackvgroundSelectionController

cyberta 3 years ago
parent
commit
bd20bf7fbe

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

@@ -75,6 +75,7 @@
 		30B0ACFA24AB5B99004D5E29 /* SettingsEphemeralMessageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30B0ACF924AB5B99004D5E29 /* SettingsEphemeralMessageController.swift */; };
 		30C0D49D237C4908008E2A0E /* CertificateCheckController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */; };
 		30C2BFFE27032375005505DA /* ChatSearchAccessoryBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30C2BFFD27032375005505DA /* ChatSearchAccessoryBar.swift */; };
+		30DAF71C275901610073C154 /* SettingsBackgroundSelectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DAF71B275901610073C154 /* SettingsBackgroundSelectionController.swift */; };
 		30E348DF24F3F819005C93D1 /* ChatTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348DE24F3F819005C93D1 /* ChatTableView.swift */; };
 		30E348E124F53772005C93D1 /* ImageTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E024F53772005C93D1 /* ImageTextCell.swift */; };
 		30E348E524F6647D005C93D1 /* FileTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E424F6647D005C93D1 /* FileTextCell.swift */; };
@@ -327,6 +328,7 @@
 		30B0ACF924AB5B99004D5E29 /* SettingsEphemeralMessageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsEphemeralMessageController.swift; sourceTree = "<group>"; };
 		30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertificateCheckController.swift; sourceTree = "<group>"; };
 		30C2BFFD27032375005505DA /* ChatSearchAccessoryBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatSearchAccessoryBar.swift; sourceTree = "<group>"; };
+		30DAF71B275901610073C154 /* SettingsBackgroundSelectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsBackgroundSelectionController.swift; sourceTree = "<group>"; };
 		30E348DE24F3F819005C93D1 /* ChatTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTableView.swift; sourceTree = "<group>"; };
 		30E348E024F53772005C93D1 /* ImageTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageTextCell.swift; sourceTree = "<group>"; };
 		30E348E424F6647D005C93D1 /* FileTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTextCell.swift; sourceTree = "<group>"; };
@@ -814,6 +816,7 @@
 				B20462E32440A4A600367A57 /* SettingsAutodelOverviewController.swift */,
 				B20462E52440C99600367A57 /* SettingsAutodelSetController.swift */,
 				302D5453268B84CB00A8B271 /* SettingsVideoChatViewController.swift */,
+				30DAF71B275901610073C154 /* SettingsBackgroundSelectionController.swift */,
 				AE76E5ED242BF2EA003CF461 /* WelcomeViewController.swift */,
 				AE8F503424753DFE007FEE0B /* GalleryViewController.swift */,
 				30734325249A280B00BF9AD1 /* MediaQualityController.swift */,
@@ -1311,6 +1314,7 @@
 				30A4149724F6EFBE00EC91EB /* InfoMessageCell.swift in Sources */,
 				302B84C6239676F0001C261F /* AvatarHelper.swift in Sources */,
 				AE77838D23E32ED20093EABD /* ContactDetailViewModel.swift in Sources */,
+				30DAF71C275901610073C154 /* SettingsBackgroundSelectionController.swift in Sources */,
 				3010968926838A050032CBA0 /* VideoInviteCell.swift in Sources */,
 				303492CB257A814200A523D0 /* DraftArea.swift in Sources */,
 				AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */,

+ 105 - 0
deltachat-ios/Controller/SettingsBackgroundSelectionController.swift

@@ -0,0 +1,105 @@
+import Foundation
+import UIKit
+import DcCore
+
+class SettingsBackgroundSelectionController: UIViewController {
+    let dcContext: DcContext
+
+    lazy var selectBackgroundButton: DynamicFontButton = {
+        let btn = DynamicFontButton()
+        btn.translatesAutoresizingMaskIntoConstraints = false
+        btn.setTitle(String.localized("pref_background_btn_gallery"), for: .normal)
+        btn.accessibilityLabel = String.localized("pref_background_btn_gallery")
+        btn.translatesAutoresizingMaskIntoConstraints = false
+        btn.setTitleColor(.systemBlue, for: .normal)
+        btn.setTitleColor(.gray, for: .highlighted)
+        btn.titleLabel?.lineBreakMode = .byWordWrapping
+        btn.titleLabel?.textAlignment = .center
+        btn.contentHorizontalAlignment = .center
+        btn.titleLabel?.font = UIFont.preferredFont(for: .body, weight: .regular)
+        btn.titleLabel?.adjustsFontForContentSizeCategory = true
+        return btn
+    }()
+
+    lazy var selectDefaultButton: DynamicFontButton = {
+        let btn = DynamicFontButton()
+        btn.translatesAutoresizingMaskIntoConstraints = false
+        btn.setTitle(String.localized("pref_background_btn_default"), for: .normal)
+        btn.accessibilityLabel = String.localized("pref_background_btn_gallery")
+        btn.translatesAutoresizingMaskIntoConstraints = false
+        btn.setTitleColor(.systemBlue, for: .normal)
+        btn.setTitleColor(.gray, for: .highlighted)
+        btn.titleLabel?.lineBreakMode = .byWordWrapping
+        btn.titleLabel?.textAlignment = .center
+        btn.contentHorizontalAlignment = .center
+        //btn.addTarget(self, action: #selector(onActionButtonTapped), for: .touchUpInside)
+        btn.titleLabel?.font = UIFont.preferredFont(for: .body, weight: .regular)
+        btn.titleLabel?.adjustsFontForContentSizeCategory = true
+        return btn
+    }()
+
+    lazy var container: UIStackView = {
+        let container = UIStackView(arrangedSubviews: [selectDefaultButton, selectBackgroundButton])
+        container.translatesAutoresizingMaskIntoConstraints = false
+        container.distribution = .fillEqually
+        container.axis = .horizontal
+        container.alignment = .fill
+        container.backgroundColor = DcColors.systemMessageBackgroundColor
+        return container
+    }()
+
+    public lazy var backgroundContainer: UIImageView = {
+        let view = UIImageView()
+        view.contentMode = .scaleAspectFill
+        view.translatesAutoresizingMaskIntoConstraints = false
+        if #available(iOS 12.0, *) {
+            view.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
+        } else {
+            view.image = UIImage(named: "background_light")
+        }
+        return view
+    }()
+
+    init(dcContext: DcContext) {
+        self.dcContext = dcContext
+        super.init(nibName: nil, bundle: nil)
+        hidesBottomBarWhenPushed = true
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    override func viewDidLoad() {
+        setupSubviews()
+    }
+
+    func setupSubviews() {
+        view.addSubview(backgroundContainer)
+        view.addSubview(container)
+
+        view.addConstraints([
+            container.constraintAlignBottomTo(view),
+            container.constraintAlignLeadingTo(view),
+            container.constraintAlignTrailingTo(view),
+            backgroundContainer.constraintAlignBottomTo(view),
+            backgroundContainer.constraintAlignLeadingTo(view),
+            backgroundContainer.constraintAlignTrailingTo(view),
+            backgroundContainer.constraintAlignTopTo(view)
+        ])
+
+        if #available(iOS 15, *) {
+            self.navigationController?.navigationBar.isTranslucent = true
+            self.navigationController?.toolbar.isTranslucent = true
+            self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
+        }
+     }
+
+    override func viewDidLayoutSubviews() {
+        super.viewDidLayoutSubviews()
+        let bottomSafeArea = view.safeAreaInsets.bottom
+        selectBackgroundButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 8, bottom: bottomSafeArea + 12, right: 8)
+        selectDefaultButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 8, bottom: bottomSafeArea + 12, right: 8)
+    }
+
+}

+ 21 - 1
deltachat-ios/Controller/SettingsController.swift

@@ -29,6 +29,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         case switchAccount = 14
         case videoChat = 15
         case connectivity = 16
+        case selectBackground = 17
     }
 
     private var dcContext: DcContext
@@ -217,6 +218,14 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         return cell
     }()
 
+    private lazy var selectBackgroundCell: UITableViewCell = {
+        let cell = UITableViewCell()
+        cell.tag = CellTags.selectBackground.rawValue
+        cell.textLabel?.text = String.localized("pref_background")
+        cell.accessoryType = .disclosureIndicator
+        return cell
+    }()
+
     private lazy var sections: [SectionConfigs] = {
         var appNameAndVersion = "Delta Chat"
         if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
@@ -233,6 +242,11 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
             cells: [showArchiveCell, showEmailsCell, blockedContactsCell, mediaQualityCell, downloadOnDemandCell,
                     autodelCell, videoChatInstanceCell, notificationCell, receiptConfirmationCell]
         )
+        let appearanceSection = SectionConfigs(
+            headerTitle: String.localized("pref_appearance"),
+            footerTitle: nil,
+            cells: [selectBackgroundCell]
+        )
         let autocryptSection = SectionConfigs(
             headerTitle: String.localized("autocrypt"),
             footerTitle: String.localized("autocrypt_explain"),
@@ -247,7 +261,8 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
             footerTitle: appNameAndVersion,
             cells: [connectivityCell, helpCell]
         )
-        return [profileSection, preferencesSection, autocryptSection, backupSection, helpSection]
+
+        return [profileSection, preferencesSection, appearanceSection, autocryptSection, backupSection, helpSection]
     }()
 
     init(dcAccounts: DcAccounts) {
@@ -356,6 +371,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         case .switchAccount: showSwitchAccountMenu()
         case .help: showHelp()
         case .connectivity: showConnectivity()
+        case .selectBackground: selectBackground()
         }
     }
 
@@ -653,6 +669,10 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         navigationController?.pushViewController(ConnectivityViewController(dcContext: dcContext), animated: true)
     }
 
+    private func selectBackground() {
+        navigationController?.pushViewController(SettingsBackgroundSelectionController(dcContext: dcContext), animated: true)
+    }
+
     public static func showDebugToolkit(dcContext: DcContext) {
         var info = ""