Update QRCodeParser, CreateQRCodeView, and SocialInputView to support new Spotify search format; enhance input handling for artist and song information, and update documentation for improved user guidance and consistency across the application.

main
v504 2 months ago
parent a1cd994334
commit 5592ff6f3c

@ -178,7 +178,7 @@ class QRCodeParser {
} }
// Spotify // Spotify
if trimmedContent.hasPrefix("spotify:") { if trimmedContent.hasPrefix("spotify:search:") {
return parseSpotify(trimmedContent) return parseSpotify(trimmedContent)
} }
@ -538,12 +538,12 @@ class QRCodeParser {
// MARK: - Spotify // MARK: - Spotify
private static func parseSpotify(_ content: String) -> ParsedQRData { private static func parseSpotify(_ content: String) -> ParsedQRData {
let trackId = content.replacingOccurrences(of: "spotify:track:", with: "") let searchQuery = content.replacingOccurrences(of: "spotify:search:", with: "")
return ParsedQRData( return ParsedQRData(
type: .spotify, type: .spotify,
title: "Spotify", title: "Spotify",
subtitle: "曲目ID: \(trackId)", subtitle: "搜索: \(searchQuery)",
icon: "music.note" icon: "music.note"
) )
} }

@ -282,7 +282,7 @@ struct InputComponentFactory {
case .facebook: case .facebook:
return "输入Facebook用户ID或链接..." return "输入Facebook用户ID或链接..."
case .spotify: case .spotify:
return "输入Spotify信息..." return "输入艺术家和歌曲信息..."
case .twitter: case .twitter:
return "输入X信息..." return "输入X信息..."
case .whatsapp: case .whatsapp:

@ -103,22 +103,62 @@ struct SocialInputView: View {
.fill(Color.blue.opacity(0.1)) .fill(Color.blue.opacity(0.1))
) )
// / () //
VStack(alignment: .leading, spacing: 8) { if platform == .spotify {
HStack { // SpotifyArtistSong
// VStack(alignment: .leading, spacing: 12) {
Text(getInputLabel()) // Artist
.font(.subheadline) VStack(alignment: .leading, spacing: 8) {
.foregroundColor(.primary) HStack {
Text("*") Text("艺术家")
.foregroundColor(.red) .font(.subheadline)
Spacer() .foregroundColor(.primary)
Text("*")
.foregroundColor(.red)
Spacer()
}
TextField("输入艺术家名称", text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
.autocapitalization(.none)
.focused($focusedField, equals: .username)
}
// Song
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("歌曲名称")
.font(.subheadline)
.foregroundColor(.primary)
Text("*")
.foregroundColor(.red)
Spacer()
}
TextField("输入歌曲名称", text: $message)
.textFieldStyle(RoundedBorderTextFieldStyle())
.autocapitalization(.none)
.focused($focusedField, equals: .message)
}
}
} else {
//
VStack(alignment: .leading, spacing: 8) {
HStack {
//
Text(getInputLabel())
.font(.subheadline)
.foregroundColor(.primary)
Text("*")
.foregroundColor(.red)
Spacer()
}
TextField(platform.placeholder, text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
.autocapitalization(.none)
.focused($focusedField, equals: .username)
} }
TextField(platform.placeholder, text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
.autocapitalization(.none)
.focused($focusedField, equals: .username)
} }
@ -200,7 +240,7 @@ struct SocialInputView: View {
case .viber: case .viber:
return "• 输入Viber电话号码+1234567890\n• 将生成viber://add?number=格式\n• 用户扫描后可直接添加Viber联系人" return "• 输入Viber电话号码+1234567890\n• 将生成viber://add?number=格式\n• 用户扫描后可直接添加Viber联系人"
case .spotify: case .spotify:
return "• 输入歌曲或播放列表链接\n• 或输入Spotify ID" return "• 输入艺术家名称和歌曲名称\n• 将生成spotify:search:艺术家;歌曲格式\n• 用户扫描后可直接在Spotify中搜索"
} }
} }
} }

@ -511,7 +511,7 @@ struct CreateQRCodeView: View {
let facebookId = extractFacebookId(from: socialUsername) let facebookId = extractFacebookId(from: socialUsername)
return "fb://profile/\(facebookId)" return "fb://profile/\(facebookId)"
case .spotify: case .spotify:
return "https://open.spotify.com/track/\(socialUsername)" return "spotify:search:\(socialUsername);\(socialMessage)"
case .twitter: case .twitter:
return "twitter://user?screen_name=\(socialUsername)" return "twitter://user?screen_name=\(socialUsername)"
case .whatsapp: case .whatsapp:
@ -535,7 +535,7 @@ struct CreateQRCodeView: View {
let facebookId = extractFacebookId(from: socialUsername) let facebookId = extractFacebookId(from: socialUsername)
return "fb://profile/\(facebookId)" return "fb://profile/\(facebookId)"
case .spotify: case .spotify:
return "https://open.spotify.com/track/\(socialUsername)" return "spotify:search:\(socialUsername);\(socialMessage)"
case .twitter: case .twitter:
return "twitter://user?screen_name=\(socialUsername)" return "twitter://user?screen_name=\(socialUsername)"
case .whatsapp: case .whatsapp:
@ -670,6 +670,6 @@ struct CreateQRCodeView: View {
#Preview { #Preview {
NavigationView { NavigationView {
CreateQRCodeView(selectedQRCodeType: .sms) CreateQRCodeView(selectedQRCodeType: .spotify)
} }
} }

@ -92,7 +92,7 @@ END:VEVENT
// 社交媒体 // 社交媒体
Instagram: instagram://user?username=<用户名> Instagram: instagram://user?username=<用户名>
Facebook: fb://profile/<用户ID> Facebook: fb://profile/<用户ID>
Spotify: spotify:track:<曲目ID> Spotify: spotify:search:<艺术家>;<歌曲>
X: twitter://user?screen_name=<用户名> X: twitter://user?screen_name=<用户名>
WhatsApp: whatsapp://send?phone=<电话号码> WhatsApp: whatsapp://send?phone=<电话号码>
Viber: viber://add?number=<电话号码> Viber: viber://add?number=<电话号码>

Loading…
Cancel
Save