diff --git a/Pocket Poster/Extensions/Views/Buttons/OpaqueButton.swift b/Pocket Poster/Extensions/Views/Buttons/OpaqueButton.swift new file mode 100644 index 0000000..bdbfe00 --- /dev/null +++ b/Pocket Poster/Extensions/Views/Buttons/OpaqueButton.swift @@ -0,0 +1,39 @@ +// +// OpaqueButton.swift +// Pocket Poster +// +// Created by lemin on 6/21/25. +// + +import SwiftUI + +struct OpaqueButton: ButtonStyle { + var color: Color + var textColor: Color + var fullwidth: Bool = false + + func makeBody(configuration: Configuration) -> some View { + ZStack { + if fullwidth { + configuration.label + .padding(15) + .frame(maxWidth: .infinity) + .background(color) + .cornerRadius(8) + .foregroundColor(textColor) + } else { + configuration.label + .padding(15) + .background(color) + .cornerRadius(8) + .foregroundColor(textColor) + } + } + } + + init(color: Color = .blue, textColor: Color = .primary, fullwidth: Bool = false) { + self.color = color + self.textColor = textColor + self.fullwidth = fullwidth + } +} diff --git a/Pocket Poster/Extensions/TintedButton.swift b/Pocket Poster/Extensions/Views/Buttons/TintedButton.swift similarity index 100% rename from Pocket Poster/Extensions/TintedButton.swift rename to Pocket Poster/Extensions/Views/Buttons/TintedButton.swift diff --git a/Pocket Poster/Extensions/LoopingPlayerUIView.swift b/Pocket Poster/Extensions/Views/LoopingPlayerUIView.swift similarity index 100% rename from Pocket Poster/Extensions/LoopingPlayerUIView.swift rename to Pocket Poster/Extensions/Views/LoopingPlayerUIView.swift diff --git a/Pocket Poster/Extensions/MaterialView.swift b/Pocket Poster/Extensions/Views/MaterialView.swift similarity index 100% rename from Pocket Poster/Extensions/MaterialView.swift rename to Pocket Poster/Extensions/Views/MaterialView.swift diff --git a/Pocket Poster/Extensions/PlayerView.swift b/Pocket Poster/Extensions/Views/PlayerView.swift similarity index 100% rename from Pocket Poster/Extensions/PlayerView.swift rename to Pocket Poster/Extensions/Views/PlayerView.swift diff --git a/Pocket Poster/Localizable.xcstrings b/Pocket Poster/Localizable.xcstrings index 2219868..ebab764 100644 --- a/Pocket Poster/Localizable.xcstrings +++ b/Pocket Poster/Localizable.xcstrings @@ -418,6 +418,9 @@ } } } + }, + "Apply CarPlay Wallpapers" : { + }, "Applying Wallpapers..." : { "localizations" : { @@ -630,6 +633,15 @@ } } } + }, + "CarPlay" : { + + }, + "CarPlay Applied Wallpapers Successfully Cleared!" : { + + }, + "CarPlay Wallpapers" : { + }, "Clear App Cache" : { "localizations" : { @@ -1977,6 +1989,7 @@ } }, "Enter App Hash" : { + "extractionState" : "stale", "localizations" : { "ar" : { "stringUnit" : { @@ -2075,6 +2088,15 @@ } } } + }, + "Enter CarPlayWallpaper App Hash" : { + + }, + "Enter PosterBoard App Hash" : { + + }, + "Enter your CarPlayWallpaper app hash in Settings." : { + }, "Enter your PosterBoard app hash in Settings." : { "localizations" : { @@ -5136,6 +5158,9 @@ } } } + }, + "Reset CarPlay Applied Wallpapers" : { + }, "Reset Collections" : { "localizations" : { @@ -7008,6 +7033,9 @@ } } } + }, + "You can now choose your wallpapers in the CarPlay settings in your car." : { + }, "You can only apply %@ descriptors." : { "localizations" : { diff --git a/Pocket Poster/Views/NavigatorViews/CarPlayView.swift b/Pocket Poster/Views/NavigatorViews/CarPlayView.swift index ca2fa73..e57fcbe 100644 --- a/Pocket Poster/Views/NavigatorViews/CarPlayView.swift +++ b/Pocket Poster/Views/NavigatorViews/CarPlayView.swift @@ -29,61 +29,70 @@ struct CarPlayView: View { var body: some View { NavigationStack { - ScrollView { - if wallpapers.isEmpty { - ProgressView() - } else { - LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 250))]) { - ForEach($wallpapers) { wallpaper in - ZStack { - WallpaperView(wallpaper: wallpaper, didChange: $didChange, showDark: $showDark) - .disabled(activeWallpapers.contains(wallpaper.name.wrappedValue)) - // The checkmark - if activeWallpapers.contains(wallpaper.name.wrappedValue) { - RoundedRectangle(cornerRadius: 8) - .foregroundStyle(.black.opacity(0.4)) - Image(systemName: "checkmark.circle.fill") - .font(.title) - .foregroundStyle(.green) + ZStack { + ScrollView { + if wallpapers.isEmpty { + ProgressView() + } else { + LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 250))]) { + ForEach($wallpapers) { wallpaper in + ZStack { + WallpaperView(wallpaper: wallpaper, didChange: $didChange, showDark: $showDark) + .disabled(activeWallpapers.contains(wallpaper.name.wrappedValue)) + // The checkmark + if activeWallpapers.contains(wallpaper.name.wrappedValue) { + RoundedRectangle(cornerRadius: 8) + .foregroundStyle(.black.opacity(0.4)) + Image(systemName: "checkmark.circle.fill") + .font(.title) + .foregroundStyle(.green) + } } } } - } - .padding() - } - - if cpHash == "" { - Text("Enter your CarPlayWallpaper app hash in Settings.") .padding() - } else if didChange { - Button(action: { - UIImpactFeedbackGenerator(style: .soft).impactOccurred() - UIApplication.shared.alert(title: NSLocalizedString("Applying Wallpapers...", comment: ""), body: NSLocalizedString("Please wait", comment: ""), animated: false, withButton: false) + } + } + VStack { + Spacer() + if didChange { + Button(action: { + UIImpactFeedbackGenerator(style: .soft).impactOccurred() + UIApplication.shared.alert(title: NSLocalizedString("Applying Wallpapers...", comment: ""), body: NSLocalizedString("Please wait", comment: ""), animated: false, withButton: false) - DispatchQueue.global(qos: .userInitiated).async { - do { - try pbManager.applyCarPlay(appHash: cpHash, wallpapers: wallpapers) - SymHandler.cleanup() // just to be extra sure - UIApplication.shared.dismissAlert(animated: false) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { - activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? [] - Haptic.shared.notify(.success) - UIApplication.shared.alert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("You can now choose your wallpapers in the CarPlay settings in your car.", comment: "")) - }) - } catch CocoaError.fileWriteUnknown { - presentError(ApplyError.wrongAppHash) - } catch CocoaError.fileWriteFileExists { - presentError(ApplyError.collectionsNeedsReset) - } catch { - print(error.localizedDescription) - presentError(ApplyError.unexpected(info: error.localizedDescription)) + DispatchQueue.global(qos: .userInitiated).async { + do { + try pbManager.applyCarPlay(appHash: cpHash, wallpapers: wallpapers) + SymHandler.cleanup() // just to be extra sure + UIApplication.shared.dismissAlert(animated: false) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { + activeWallpapers = UserDefaults.standard.array(forKey: "ActiveCarPlayWallpapers") as? [String] ?? [] + Haptic.shared.notify(.success) + UIApplication.shared.alert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("You can now choose your wallpapers in the CarPlay settings in your car.", comment: "")) + }) + } catch CocoaError.fileWriteUnknown { + presentError(ApplyError.wrongAppHash) + } catch CocoaError.fileWriteFileExists { + presentError(ApplyError.collectionsNeedsReset) + } catch { + print(error.localizedDescription) + presentError(ApplyError.unexpected(info: error.localizedDescription)) + } + } + }) { + if cpHash == "" { + Text("Enter your CarPlayWallpaper app hash in Settings.") + } else { + Label("Apply CarPlay Wallpapers", systemImage: "checkmark.circle") } } - }) { - Label("Apply CarPlay Wallpapers", systemImage: "checkmark.circle") + .buttonStyle(OpaqueButton(color: cpHash == "" ? .red : .blue, fullwidth: true)) + .disabled(cpHash == "") + .padding(.vertical, 10) + .padding(.horizontal, 25) + .transition(.move(edge: .bottom)) + .animation(.easeIn, value: didChange) } - .buttonStyle(TintedButton(color: .blue, fullwidth: true)) - .padding() } } .navigationTitle("CarPlay Wallpapers") @@ -177,7 +186,9 @@ struct WallpaperView: View { } else { wallpaper.selectedImageDataLight = data } - didChange = true + withAnimation { + didChange = true + } } } }