Explorar el Código

Removal of watch image feature

Jonas Björkert hace 2 años
padre
commit
3c59f1e057

+ 0 - 4
LoopFollow.xcodeproj/project.pbxproj

@@ -40,7 +40,6 @@
 		FC16A97D24996747003D6245 /* Alarms.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC16A97C24996747003D6245 /* Alarms.swift */; };
 		FC16A97F249969E2003D6245 /* Graphs.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC16A97E249969E2003D6245 /* Graphs.swift */; };
 		FC16A98124996C07003D6245 /* DateTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC16A98024996C07003D6245 /* DateTime.swift */; };
-		FC1BB3A8252CA4C5003839C2 /* UIImageExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC1BB3A7252CA4C5003839C2 /* UIImageExtension.swift */; };
 		FC1BDD2B24A22650001B652C /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC1BDD2A24A22650001B652C /* Stats.swift */; };
 		FC1BDD2D24A23204001B652C /* StatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC1BDD2C24A23204001B652C /* StatsView.swift */; };
 		FC1BDD3224A2585C001B652C /* DataStructs.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC1BDD2E24A232A3001B652C /* DataStructs.swift */; };
@@ -225,7 +224,6 @@
 		FC16A97C24996747003D6245 /* Alarms.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alarms.swift; sourceTree = "<group>"; };
 		FC16A97E249969E2003D6245 /* Graphs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Graphs.swift; sourceTree = "<group>"; };
 		FC16A98024996C07003D6245 /* DateTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTime.swift; sourceTree = "<group>"; };
-		FC1BB3A7252CA4C5003839C2 /* UIImageExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImageExtension.swift; sourceTree = "<group>"; };
 		FC1BDD2A24A22650001B652C /* Stats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = "<group>"; };
 		FC1BDD2C24A23204001B652C /* StatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsView.swift; sourceTree = "<group>"; };
 		FC1BDD2E24A232A3001B652C /* DataStructs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStructs.swift; sourceTree = "<group>"; };
@@ -448,7 +446,6 @@
 			children = (
 				DD98F54324BCEFEE0007425A /* ShareClientExtension.swift */,
 				DDCF979324C0D380002C9752 /* UIViewExtension.swift */,
-				FC1BB3A7252CA4C5003839C2 /* UIImageExtension.swift */,
 				DD7FFAFC2A72953000C3A304 /* EKEventStore+Extensions.swift */,
 			);
 			path = Extensions;
@@ -964,7 +961,6 @@
 				DDF9676E2AD08C6E00C5EB95 /* SiteChange.swift in Sources */,
 				DDCF979C24C14EFB002C9752 /* AdvancedSettingsViewController.swift in Sources */,
 				FC97881C2485969B00A7906C /* MainViewController.swift in Sources */,
-				FC1BB3A8252CA4C5003839C2 /* UIImageExtension.swift in Sources */,
 				DD493AD52ACF2109009A6922 /* ResumePump.swift in Sources */,
 				DDCF979624C1443C002C9752 /* GeneralSettingsViewController.swift in Sources */,
 				FCC0FAC224922A22003E610E /* DictionaryKeyPath.swift in Sources */,

+ 0 - 53
LoopFollow/Extensions/UIImageExtension.swift

@@ -1,53 +0,0 @@
-//
-//  UIImageExtension.swift
-//  LoopFollow
-//
-//  Created by Jon Fawcett on 10/6/20.
-//  Copyright © 2020 Jon Fawcett. All rights reserved.
-//
-
-import Foundation
-import UIKit
-
-extension UIImage {
-    func resizeImage(_ dimension: CGFloat, landscape: Bool, opaque: Bool, contentMode: UIView.ContentMode = .scaleAspectFit) -> UIImage {
-        var width: CGFloat
-        var height: CGFloat
-            var newImage: UIImage
-
-            let size = self.size
-            let aspectRatio =  size.width/size.height
-
-            switch contentMode {
-                case .scaleAspectFit:
-                    if landscape {                            // Landscape image
-                        width = dimension
-                        height = dimension / aspectRatio
-                    } else {                                        // Portrait image
-                        height = dimension
-                        width = dimension * aspectRatio
-                    }
-
-            default:
-                width = 368.0
-                height = 448.0
-            }
-
-            if #available(iOS 10.0, *) {
-                let renderFormat = UIGraphicsImageRendererFormat.default()
-                renderFormat.opaque = opaque
-                let renderer = UIGraphicsImageRenderer(size: CGSize(width: width, height: height), format: renderFormat)
-                newImage = renderer.image {
-                    (context) in
-                    self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
-                }
-            } else {
-                UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), opaque, 0)
-                    self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
-                    newImage = UIGraphicsGetImageFromCurrentImageContext()!
-                UIGraphicsEndImageContext()
-            }
-
-            return newImage
-        }
-    }

+ 0 - 4
LoopFollow/Info.plist

@@ -32,10 +32,6 @@
 	<true/>
 	<key>NSCalendarsUsageDescription</key>
 	<string>Loop Follow would like to access your calendar to save BG readings</string>
-	<key>NSPhotoLibraryAddUsageDescription</key>
-	<string>Loop Follow would like to access to your photo library to save graph images</string>
-	<key>NSPhotoLibraryUsageDescription</key>
-	<string>Loop Follow would like to access to your photo library to save graph images</string>
 	<key>UIApplicationSceneManifest</key>
 	<dict>
 		<key>UIApplicationSupportsMultipleScenes</key>

+ 1 - 147
LoopFollow/ViewControllers/MainViewController.swift

@@ -11,7 +11,7 @@ import Charts
 import EventKit
 import ShareClient
 import UserNotifications
-import Photos
+import AVFAudio
 
 class MainViewController: UIViewController, UITableViewDataSource, ChartViewDelegate, UNUserNotificationCenterDelegate, UIScrollViewDelegate {
     
@@ -503,146 +503,7 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
         graphics:[String:String]=["Flat":"→","DoubleUp":"↑↑","SingleUp":"↑","FortyFiveUp":"↗","FortyFiveDown":"↘︎","SingleDown":"↓","DoubleDown":"↓↓","None":"-","NONE":"-","NOT COMPUTABLE":"-","RATE OUT OF RANGE":"-", "": "-"]
         return graphics[value]!
     }
-    
-    // Test code to save an image of graph for viewing on watch
-    func saveChartImage() {
-        var originalColor = BGChart.backgroundColor
-        BGChart.backgroundColor = NSUIColor.black
-        guard var image = BGChart.getChartImage(transparent: true) else {
-            BGChart.backgroundColor = originalColor
-            return }
-        var newImage = image.resizeImage(448.0, landscape: false, opaque: false, contentMode: .scaleAspectFit)
-        createAlbums(name1: "Loop Follow", name2: "Loop Follow Old")
-        if let collection1 = fetchAssetCollection("Loop Follow"), let collection2 = fetchAssetCollection("Loop Follow Old") {
-            deleteExistingImagesFromCollection(collection: collection1)
-            saveImageToAssetCollection(image, collection1: collection1, collection2: collection2)
-        }
-        
-        BGChart.backgroundColor = originalColor
-    }
-    
-    func createAlbums(name1: String, name2: String) {
-        if let collection1 = fetchAssetCollection(name1) {
-        } else {
-            // Album does not exist, create it and attempt to save the image
-            PHPhotoLibrary.shared().performChanges({
-                PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: name1)
-            }, completionHandler: { (success: Bool, error: Error?) in
-                guard success == true && error == nil else {
-                    NSLog("Could not create the album")
-                    if let err = error {
-                        NSLog("Error: \(err)")
-                    }
-                    return
-                }
-
-                if let newCollection1 = self.fetchAssetCollection(name1) {
-                }
-            })
-        }
-        
-        if let collection2 = fetchAssetCollection(name2) {
-        } else {
-            // Album does not exist, create it and attempt to save the image
-            PHPhotoLibrary.shared().performChanges({
-                PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: name2)
-            }, completionHandler: { (success: Bool, error: Error?) in
-                guard success == true && error == nil else {
-                    NSLog("Could not create the album")
-                    if let err = error {
-                        NSLog("Error: \(err)")
-                    }
-                    return
-                }
-
-                if let newCollection2 = self.fetchAssetCollection(name2) {
-                }
-            })
-        }
-    }
-    
-    func fetchAssetCollection(_ name: String) -> PHAssetCollection? {
-
-        let fetchOption = PHFetchOptions()
-        fetchOption.predicate = NSPredicate(format: "title == '" + name + "'")
-
-        let fetchResult = PHAssetCollection.fetchAssetCollections(
-            with: PHAssetCollectionType.album,
-            subtype: PHAssetCollectionSubtype.albumRegular,
-            options: fetchOption)
-
-        return fetchResult.firstObject
-    }
-    
-    func deleteOldImages() {
-        if let collection = fetchAssetCollection("Loop Follow Old") {
-            let library = PHPhotoLibrary.shared()
-            library.performChanges({
-                let fetchOptions = PHFetchOptions()
-                let allPhotos = PHAsset.fetchAssets(in: collection, options: .none)
-                PHAssetChangeRequest.deleteAssets(allPhotos)
-            }, completionHandler: { (success: Bool, error: Error?) in
-                guard success == true && error == nil else {
-                    NSLog("Could not delete the image")
-                    if let err = error {
-                        NSLog("Error: " + err.localizedDescription)
-                    }
-                    return
-                }
-            })
-        }
         
-        self.sendGeneralNotification(self, title: "Watch Face Cleanup", subtitle: "", body: "Delete old watch face graph images", timer: 86400)
-        
-        
-    }
-    
-    func deleteExistingImagesFromCollection(collection: PHAssetCollection) {
-        
-        // This code removes existing photos from collection but does not delete them
-        if collection.estimatedAssetCount < 1 { return }
-
-        PHPhotoLibrary.shared().performChanges( {
-
-            if let request = PHAssetCollectionChangeRequest(for: collection) {
-                request.removeAssets(at: [0])
-            }
-
-        }, completionHandler: { (success: Bool, error: Error?) in
-            guard success == true && error == nil else {
-                NSLog("Could not delete the image")
-                if let err = error {
-                    NSLog("Error: " + err.localizedDescription)
-                }
-                return
-            }
-        })
-    }
-
-    func saveImageToAssetCollection(_ image: UIImage, collection1: PHAssetCollection, collection2: PHAssetCollection) {
-        
-        PHPhotoLibrary.shared().performChanges({
-            
-            let creationRequest = PHAssetCreationRequest.creationRequestForAsset(from: image)
-            if let request = PHAssetCollectionChangeRequest(for: collection1),
-               let placeHolder = creationRequest.placeholderForCreatedAsset {
-                request.addAssets([placeHolder] as NSFastEnumeration)
-            }
-            if let request2 = PHAssetCollectionChangeRequest(for: collection2),
-               let placeHolder2 = creationRequest.placeholderForCreatedAsset {
-                request2.addAssets([placeHolder2] as NSFastEnumeration)
-            }
-        }, completionHandler: { (success: Bool, error: Error?) in
-            guard success == true && error == nil else {
-                NSLog("Could not save the image")
-                if let err = error {
-                    NSLog("Error: " + err.localizedDescription)
-                }
-                return
-            }
-        })
-    }
-
     func writeCalendar() {
         if UserDefaultsRepository.debugLog.value {
             self.writeDebugLog(value: "Write calendar start")
@@ -766,13 +627,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
                 // Display error to user
                 //if UserDefaultsRepository.debugLog.value { self.writeDebugLog(value: "Error: Calendar Write") }
             }
-        
-        if UserDefaultsRepository.saveImage.value {
-            DispatchQueue.main.async {
-                self.saveChartImage()
-            }
-                
-        }
     }
     
     

+ 0 - 10
LoopFollow/ViewControllers/SettingsViewController.swift

@@ -228,16 +228,6 @@ class SettingsViewController: FormViewController {
            ), onDismiss: nil)
             
         }
-            <<< LabelRow("Clear Images"){ row in
-                row.title = "Delete Watch Face Images"
-            }.onCellSelection{ cell,row  in
-                if UserDefaultsRepository.saveImage.value {
-                    guard let mainScreen = self.tabBarController!.viewControllers?[0] as? MainViewController else { return }
-                    
-                    mainScreen.deleteOldImages()
-                    mainScreen.saveChartImage()
-                }
-            }
         
        +++ Section("Advanced Settings")
         <<< ButtonRow() {

+ 0 - 8
LoopFollow/ViewControllers/WatchSettingsViewController.swift

@@ -119,14 +119,6 @@ class WatchSettingsViewController: FormViewController {
                 guard let value = row.value else { return }
                 UserDefaultsRepository.watchLine2.value = value
             }
-            <<< SwitchRow("saveImage"){ row in
-                row.title = "Save Graph Image for Watch Face"
-                row.value = UserDefaultsRepository.saveImage.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.saveImage.value = value
-            }
-            
         
         
             +++ Section(header: "Available Variables", footer: "")

+ 0 - 1
LoopFollow/repository/UserDefaults.swift

@@ -112,7 +112,6 @@ class UserDefaultsRepository {
     static let writeCalendarEvent = UserDefaultsValue<Bool>(key: "writeCalendarEvent", default: false)
     static let watchLine1 = UserDefaultsValue<String>(key: "watchLine1", default: "%BG% %DIRECTION% %DELTA% %MINAGO%")
     static let watchLine2 = UserDefaultsValue<String>(key: "watchLine2", default: "C:%COB% I:%IOB% B:%BASAL%")
-    static let saveImage = UserDefaultsValue<Bool>(key: "saveImage", default: false)
     
     // Alarm Settings
     static let systemOutputVolume = UserDefaultsValue<Float>(key: "systemOutputVolume", default: 0.5)