From 14390035a30702d781e6632337839b20a24f25a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Thu, 6 Nov 2025 19:17:23 +0100 Subject: [PATCH] Refactoring --- NearbyShare/Model/DataModel.swift | 30 ++++++++++++++++++++++++++ QuickDrop/ViewModel/ReceiveModel.swift | 29 ++----------------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/NearbyShare/Model/DataModel.swift b/NearbyShare/Model/DataModel.swift index 7200f78..ff0dc61 100644 --- a/NearbyShare/Model/DataModel.swift +++ b/NearbyShare/Model/DataModel.swift @@ -133,6 +133,36 @@ public struct TransferMetadata { case text case url } + + private func getSummary() -> String { + if let textTitle = textDescription { + return textTitle + } else if files.count == 1 { + return files[0].name + } else { + return String.localizedStringWithFormat("NFiles".localized(), files.count) + } + } + + public func getDescription(deviceName: String, alreadyAccepted: Bool) -> String { + + let fileStr = getSummary() + + switch type { + case .file: + return String(format: (alreadyAccepted ? "DeviceCurrentlySendingFiles" : "DeviceSendingFiles").localized(), arguments: [deviceName, fileStr]) + + case .text: + return String(format: (alreadyAccepted ? "DeviceCurrentlySendingText" : "DeviceSendingText").localized(), arguments: [deviceName, fileStr]) + + case .url: + return String(format: (alreadyAccepted ? "DeviceCurrentlySendingUrl" : "DeviceSendingUrl").localized(), arguments: [deviceName, fileStr]) + } + } + + public func getPinCodeMessage() -> String { + return String(format: "PinCode".localized(), arguments: [pinCode ?? "?"]) + } } diff --git a/QuickDrop/ViewModel/ReceiveModel.swift b/QuickDrop/ViewModel/ReceiveModel.swift index 6ba52ef..d179b55 100644 --- a/QuickDrop/ViewModel/ReceiveModel.swift +++ b/QuickDrop/ViewModel/ReceiveModel.swift @@ -47,33 +47,8 @@ class ReceiveModel: ObservableObject, InboundAppDelegate { AudioManager.playIncomingFileSound() #endif - let fileStr: String - - if let textTitle = transfer.textDescription { - fileStr = textTitle - } else if transfer.files.count == 1 { - fileStr = transfer.files[0].name - } else { - fileStr = String.localizedStringWithFormat("NFiles".localized(), transfer.files.count) - } - - - let mainMessage: String - let name = device.name ?? "Android" - - switch transfer.type { - case .file: - mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingFiles" : "DeviceSendingFiles").localized(), arguments: [name, fileStr]) - - case .text: - mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingText" : "DeviceSendingText").localized(), arguments: [name, fileStr]) - - case .url: - mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingUrl" : "DeviceSendingUrl").localized(), arguments: [name, fileStr]) - } - - - let pinCodeMessage = String(format: "PinCode".localized(), arguments: [transfer.pinCode ?? "?"]) + let mainMessage = transfer.getDescription(deviceName: device.name ?? "Android", alreadyAccepted: acceptAutomatically) + let pinCodeMessage = transfer.getPinCodeMessage() let transferID = transfer.id #if os(macOS)