Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 12 | Autoría | Ultima modificación | Ver Log |

//
//  AppData.swift
//  twogetskills
//
//  Created by Efrain Yanez Recanatini on 8/7/22.
//

import Foundation

class AppData {
    private let standardPreference = UserDefaults.standard


    
    var deviceUuid : String = ""
    var devicePassword : String = ""
    var deviceAes : String = ""
    
    var userUuid : String = ""
    var userEmail : String = ""
    var userFirstname : String = ""
    var userLastname : String = ""
    var userImage : String = ""
    
    var topicUuidActive : String = ""
    var capsuleUuidActive : String = ""
    var capsuleUuidOld : String = ""
    var slideUuidActive : String = ""
    var companyUuidActive : String = ""
    
    var fcmToken : String = ""
    var lastCheckChanges : String = ""
    var maxDateChanges : String = ""
    var urlExternalDownloaded : String = ""
    
    var refreshContentMessage : String = ""
    var refreshContentMessageShowPending : Bool = false
    var refreshContentActionRequired : Bool = false
    var signoutActionRequired : Bool = false

    
        /*
        private let appDao = AppDao.sharedInstance

*/
    static let sharedInstance: AppData = {
           let instance = AppData()

           return instance
    }()

    init() {
        load()
    }
    
    func load() -> Void
    {
        
        
        
        
       // let appModel = appDao.selectOne()
        
        self.deviceUuid = standardPreference.string(forKey: Constants.PREFERENCE_DEVICE_UUID) ?? ""
        self.devicePassword = standardPreference.string(forKey: Constants.PREFERENCE_DEVICE_PASSWORD) ?? ""
        self.deviceAes = standardPreference.string(forKey: Constants.PREFERENCE_DEVICE_AES) ?? ""
        
        self.userUuid = standardPreference.string(forKey: Constants.PREFERENCE_USER_UUID) ?? ""
        self.userEmail = standardPreference.string(forKey: Constants.PREFERENCE_USER_EMAIL) ?? ""
        self.userFirstname = standardPreference.string(forKey: Constants.PREFERENCE_USER_FIRSTNAME) ?? ""
        self.userLastname = standardPreference.string(forKey: Constants.PREFERENCE_USER_LASTNAME) ?? ""
        self.userImage = standardPreference.string(forKey: Constants.PREFERENCE_USER_IMAGE) ?? ""
 
        self.topicUuidActive =  standardPreference.string(forKey: Constants.PREFERENCE_TOPIC_UUID_ACTIVE) ?? ""
        self.capsuleUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_CAPSULE_UUID_ACTIVE) ?? ""
        self.capsuleUuidOld = standardPreference.string(forKey: Constants.PREFERENCE_CAPSULE_UUID_OLD) ?? ""
        self.slideUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_SLIDE_UUID_ACTIVE) ?? ""
        self.companyUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_COMPANY_UUID_ACTIVE) ?? ""
        
        self.fcmToken = standardPreference.string(forKey: Constants.PREFERENCE_FCM_TOKEN) ?? ""
        self.lastCheckChanges = standardPreference.string(forKey: Constants.PREFERENCE_LAST_CHECK_CHANGES) ?? ""
        self.maxDateChanges = standardPreference.string(forKey: Constants.PREFERENCE_MAX_DATE_CHANGES) ?? ""
        self.urlExternalDownloaded = standardPreference.string(forKey: Constants.PREFERENCE_URL_EXTERNAL_DOWNLOADED) ?? ""
        
        self.refreshContentMessage = standardPreference.string(forKey: Constants.PREFERENCE_REFRESH_CONTENT_MESSAGE) ?? ""
        self.refreshContentMessageShowPending = standardPreference.bool(forKey: Constants.PREFERENCE_REFRESH_CONTENT_MESSAGE_SHOW_PENDING)
        self.refreshContentActionRequired = standardPreference.bool(forKey: Constants.PREFERENCE_REFRESH_CONTENT_ACTION_REQUIRED)
        
        self.signoutActionRequired = standardPreference.bool(forKey: Constants.PREFERENCE_SIGNOUT_ACTION_REQUIRED)
 
        /*
        print("AppData Load Device UUID : \(self.deviceUuid)")
        print("AppData Load Device AES : \(self.deviceAes)")
        print("AppData Load Device Password : \(self.devicePassword)")
        
        print("AppData Load User UUID: \(self.userUuid)")
        print("AppData Load Email : \(self.userEmail)")
        print("AppData Load First Name : \(self.userFirstname)")
        print("AppData Load Last Name : \(self.userLastname)")
        print("AppData Load Image : \(self.userImage)")

        print("AppData Load Topic UUID Active : \(self.topicUuidActive)")
        print("AppData Load Capsule UUID Active : \(self.capsuleUuidActive)")
        print("AppData Load Slide UUID Active : \(self.slideUuidActive)")
        print("AppData Load Capsule UUID OLD : \(self.capsuleUuidOld)")
        print("AppData Load Company UUID Active: \(self.companyUuidActive)")
        
        print("AppData Load FCM Token : \(self.fcmToken)")
        print("AppData Load LastCheckChanges : \(self.lastCheckChanges)")
        print("AppData Load MaxDateChanges : \(self.maxDateChanges)")
        print("AppData Load UrlExternalDownloaded : \(self.urlExternalDownloaded)")
        
        print("AppData Save RefreshContentMessage : \(self.refreshContentMessage)")
        print("AppData Save RrefreshContentMessageShowPending : \(self.refreshContentMessageShowPending)")
        print("AppData Save RefreshContentActionRequired : \(self.refreshContentActionRequired)")
         */
        
        print("AppData Save SignoutActionRequired : \(self.signoutActionRequired)")
        
    }
    
    func save() -> Void
    {
        /*
        print("AppData Save Device UUID : \(self.deviceUuid)")
        print("AppData Save Device AES : \(self.deviceAes)")
        print("AppData Save Device Password : \(self.devicePassword)")
        
        print("AppData Save User UUID: \(self.userUuid)")
        print("AppData Save Email : \(self.userEmail)")
        print("AppData Save First Name : \(self.userFirstname)")
        print("AppData Save Last Name : \(self.userLastname)")
        print("AppData Save Image : \(self.userImage)")
        
        print("AppData Save Topic UUID Active : \(self.topicUuidActive)")
        print("AppData Save Capsule UUID Active : \(self.capsuleUuidActive)")
        print("AppData Save Capsule UUID Old : \(self.capsuleUuidOld)")
        print("AppData Save Slide UUID Active : \(self.slideUuidActive)")
        print("AppData Save Company UUID Active: \(self.companyUuidActive)")
            
        print("AppData Save FCM Token : \(self.fcmToken)")
        print("AppData Save LastCheckChanges : \(self.lastCheckChanges)")
        print("AppData Save MaxDateChanges : \(self.maxDateChanges)")
        print("AppData Save UrlExternalDownloaded : \(self.urlExternalDownloaded)")
        
        print("AppData Save RefreshContentMessage : \(self.refreshContentMessage)")
        print("AppData Save RrefreshContentMessageShowPending : \(self.refreshContentMessageShowPending)")
        print("AppData Save RefreshContentActionRequired : \(self.refreshContentActionRequired)")
        
        print("AppData Save SignoutActionRequired : \(self.signoutActionRequired)")
        */
        

        standardPreference.set(self.deviceUuid, forKey: Constants.PREFERENCE_DEVICE_UUID)
        
        standardPreference.set(self.devicePassword, forKey: Constants.PREFERENCE_DEVICE_PASSWORD)
        standardPreference.set(self.deviceAes, forKey: Constants.PREFERENCE_DEVICE_AES)
        standardPreference.set(self.userUuid, forKey: Constants.PREFERENCE_USER_UUID)
        standardPreference.set(self.userEmail, forKey: Constants.PREFERENCE_USER_EMAIL)
        standardPreference.set(self.userFirstname, forKey: Constants.PREFERENCE_USER_FIRSTNAME)
        standardPreference.set(self.userLastname, forKey: Constants.PREFERENCE_USER_LASTNAME)
        standardPreference.set(self.userImage, forKey: Constants.PREFERENCE_USER_IMAGE)
 
        standardPreference.set(self.topicUuidActive, forKey: Constants.PREFERENCE_TOPIC_UUID_ACTIVE)
        standardPreference.set(self.capsuleUuidActive, forKey: Constants.PREFERENCE_CAPSULE_UUID_ACTIVE)
        standardPreference.set(self.capsuleUuidOld, forKey: Constants.PREFERENCE_CAPSULE_UUID_OLD)
        standardPreference.set(self.slideUuidActive, forKey: Constants.PREFERENCE_SLIDE_UUID_ACTIVE)
        standardPreference.set(self.companyUuidActive, forKey: Constants.PREFERENCE_COMPANY_UUID_ACTIVE)
        standardPreference.set(self.fcmToken, forKey: Constants.PREFERENCE_FCM_TOKEN)
        standardPreference.set(self.lastCheckChanges, forKey: Constants.PREFERENCE_LAST_CHECK_CHANGES)
        standardPreference.set(self.maxDateChanges, forKey: Constants.PREFERENCE_MAX_DATE_CHANGES)
        standardPreference.set(self.urlExternalDownloaded, forKey: Constants.PREFERENCE_URL_EXTERNAL_DOWNLOADED)
        
        standardPreference.set(self.refreshContentMessage, forKey: Constants.PREFERENCE_REFRESH_CONTENT_MESSAGE)
        standardPreference.set(self.refreshContentMessageShowPending, forKey: Constants.PREFERENCE_REFRESH_CONTENT_MESSAGE_SHOW_PENDING)
        standardPreference.set(self.refreshContentActionRequired, forKey: Constants.PREFERENCE_REFRESH_CONTENT_ACTION_REQUIRED)
        
        standardPreference.set(self.signoutActionRequired, forKey: Constants.PREFERENCE_SIGNOUT_ACTION_REQUIRED)
    }
}