Explorar o código

always set default background image in chats if loading of custom image failed

cyberta %!s(int64=3) %!d(string=hai) anos
pai
achega
a92d003871

+ 17 - 4
deltachat-ios/Chat/ChatViewController.swift

@@ -61,11 +61,16 @@ class ChatViewController: UITableViewController {
         let view = UIImageView()
         view.contentMode = .scaleAspectFill
         if let path = UserDefaults.standard.string(forKey: Constants.Keys.backgroundImageUrl) {
-            view.sd_setImage(with: URL(fileURLWithPath: path), completed: nil)
-        } else if #available(iOS 12.0, *) {
-            view.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
+            view.sd_setImage(with: URL(fileURLWithPath: path)) { [weak self] (_, error, _, _) in
+                if error != nil {
+                    logger.warning(String(describing: error))
+                    DispatchQueue.main.async {
+                        self?.setDefaultBackgroundImage(view: view)
+                    }
+                }
+            }
         } else {
-            view.image = UIImage(named: "background_light")
+            setDefaultBackgroundImage(view: view)
         }
         return view
     }()
@@ -1726,6 +1731,14 @@ class ChatViewController: UITableViewController {
             _ = handleSelection(indexPath: indexPath)
         }
     }
+
+    private func setDefaultBackgroundImage(view: UIImageView) {
+        if #available(iOS 12.0, *) {
+            view.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
+        } else {
+            view.image = UIImage(named: "background_light")
+        }
+    }
 }
 
 // MARK: - BaseMessageCellDelegate

+ 8 - 1
deltachat-ios/Controller/SettingsBackgroundSelectionController.swift

@@ -63,7 +63,14 @@ class SettingsBackgroundSelectionController: UIViewController, MediaPickerDelega
         view.translatesAutoresizingMaskIntoConstraints = false
         view.clipsToBounds = true
         if let backgroundImageURL = UserDefaults.standard.string(forKey: Constants.Keys.backgroundImageUrl) {
-            view.sd_setImage(with: URL(fileURLWithPath: backgroundImageURL), placeholderImage: nil, options: .refreshCached, completed: nil)
+            view.sd_setImage(with: URL(fileURLWithPath: backgroundImageURL), placeholderImage: nil, options: .refreshCached) { [weak self] (_, error, _, _) in
+                if error != nil {
+                    logger.warning(String.init(describing: error))
+                    DispatchQueue.main.async {
+                        self?.setDefault(view)
+                    }
+                }
+            }
         } else {
             setDefault(view)
         }