pushdeer/ios/PushDeer-iOS/PushDeer/View/DeviceItemView.swift
hext 2136883536 支持微信登录, 修复一些bug:
支持微信登录, 支持同时绑定微信和苹果账号;
解决markdown标题文字显示不全的问题;
markdown中的链接支持内嵌浏览器打开;
增加是否使用内置浏览器的设置项;
改名输入框, 失去焦点的时候也保存;
2022-02-27 23:02:58 +08:00

109 lines
3.1 KiB
Swift

//
// DeviceItemView.swift
// PushDeer
//
// Created by HEXT on 2021/12/26.
//
import SwiftUI
/// View
struct DeviceItemView: View {
@State var deviceItem: DeviceItem
@EnvironmentObject private var store: AppState
var body: some View {
CardView {
HStack{
ZStack{
Image(systemName: getSystemName(deviceName: deviceItem.name))
.resizable()
.scaledToFit()
.frame(width: 40, height: 40, alignment: .center)
if deviceItem.is_clip == 1 {
Image(systemName: "appclip")
.resizable()
.scaledToFit()
.frame(width: 12, height: 12, alignment: .center)
}
}
.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 8))
EditableText(placeholder: NSLocalizedString("输入设备名称", comment: ""), value: deviceItem.name) { value in
if deviceItem.name == value {
return
}
Task {
//
_ = try await HttpRequest.renameDevice(id: deviceItem.id, name: value)
HToast.showSuccess(NSLocalizedString("已修改设备名称", comment: ""))
deviceItem.name = value
// Item
let index = store.devices.firstIndex { $0.id == deviceItem.id }
if let index = index {
// Item
store.devices[index].name = value
}
}
}
Text(getInfo(deviceItem: deviceItem))
.font(.system(size: 20))
Spacer(minLength: 12)
}
.frame(height: 80)
}
}
func getInfo(deviceItem: DeviceItem) -> String {
var name = ""
// if deviceItem.is_clip == 1 {
// name += " [Clip]"
// }
if deviceItem.device_id == store.deviceToken {
name += NSLocalizedString("(当前设备)", comment: "在设备列表中标识当前设备")
}
return name
}
func getSystemName(deviceName: String) -> String {
var deviceName = deviceName.lowercased()
deviceName = deviceName.replacingOccurrences(of: " ", with: "")
// if deviceName.contains("clip") {
// return "appclip"
// }
if deviceName.contains("iphone") {
return "iphone"
}
if deviceName.contains("ipad") {
return "ipad.landscape"
}
if deviceName.contains("macbook") {
return "laptopcomputer"
}
if deviceName.contains("imac") {
return "desktopcomputer"
}
if deviceName.contains("macpro") {
return "macpro.gen3"
}
if deviceName.contains("macmini") {
return "macmini"
}
if deviceName.contains("mac") {
return "macwindow"
}
if #available(iOS 15.0, *) {
return "ipad.and.iphone"
}
return "laptopcomputer.and.iphone"
}
}
struct DeviceItemView_Previews: PreviewProvider {
static var previews: some View {
DeviceItemView(deviceItem: DeviceItem(id: 0, uid: "", name: "Hext's iPhone 11", type: "", device_id: "", is_clip: 1))
.environmentObject(AppState.shared)
}
}