From d172df68e3cb8b662d2848ac73befa42458abdde Mon Sep 17 00:00:00 2001 From: Duong Thai Date: Fri, 13 Oct 2023 23:18:55 +0700 Subject: [PATCH] move and fix the `NotInstalledStateButtonsView` --- Xcodes.xcodeproj/project.pbxproj | 4 ++ Xcodes/Frontend/InfoPane/InfoPane.swift | 6 +- .../NotInstalledStateButtonsView.swift | 68 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Xcodes/Frontend/InfoPane/NotInstalledStateButtonsView.swift diff --git a/Xcodes.xcodeproj/project.pbxproj b/Xcodes.xcodeproj/project.pbxproj index 82ec9d9..1198295 100644 --- a/Xcodes.xcodeproj/project.pbxproj +++ b/Xcodes.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ B0403CF42AD9381D00137C09 /* SDKsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF32AD9381D00137C09 /* SDKsView.swift */; }; B0403CF62AD9849E00137C09 /* CompilersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF52AD9849E00137C09 /* CompilersView.swift */; }; B0403CF82AD991F800137C09 /* UnselectedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF72AD991F800137C09 /* UnselectedView.swift */; }; + B0403CFA2AD9942A00137C09 /* NotInstalledStateButtonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */; }; B0C6AD042AD6E65700E64698 /* ReleaseDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */; }; B0C6AD0B2AD9178E00E64698 /* IdenticalBuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */; }; B0C6AD0D2AD91D7900E64698 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C6AD0C2AD91D7900E64698 /* IconView.swift */; }; @@ -205,6 +206,7 @@ B0403CF32AD9381D00137C09 /* SDKsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKsView.swift; sourceTree = ""; }; B0403CF52AD9849E00137C09 /* CompilersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompilersView.swift; sourceTree = ""; }; B0403CF72AD991F800137C09 /* UnselectedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnselectedView.swift; sourceTree = ""; }; + B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotInstalledStateButtonsView.swift; sourceTree = ""; }; B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReleaseDateView.swift; sourceTree = ""; }; B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdenticalBuildView.swift; sourceTree = ""; }; B0C6AD0C2AD91D7900E64698 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = ""; }; @@ -637,6 +639,7 @@ B0403CF12AD934B600137C09 /* CompatibilityView.swift */, CAFBDC67259A308B003DCC5A /* InfoPane.swift */, B0403CF72AD991F800137C09 /* UnselectedView.swift */, + B0403CF92AD9942A00137C09 /* NotInstalledStateButtonsView.swift */, E8E98A9525D863D700EC89A0 /* InstallationStepDetailView.swift */, B0C6AD032AD6E65700E64698 /* ReleaseDateView.swift */, B0C6AD0A2AD9178E00E64698 /* IdenticalBuildView.swift */, @@ -925,6 +928,7 @@ CABFA9CF2592EEEA00380FEE /* Process.swift in Sources */, CAFFFED8259CDA5000903F81 /* XcodeListViewRow.swift in Sources */, CABFA9C72592EEEA00380FEE /* Entry+.swift in Sources */, + B0403CFA2AD9942A00137C09 /* NotInstalledStateButtonsView.swift in Sources */, CAE424B4259A764700B8B246 /* AppState+Install.swift in Sources */, CAE42487259A68A300B8B246 /* XcodeListCategory.swift in Sources */, CAA858C425A2BE4E00ACF8C0 /* Downloader.swift in Sources */, diff --git a/Xcodes/Frontend/InfoPane/InfoPane.swift b/Xcodes/Frontend/InfoPane/InfoPane.swift index 9cb9abe..5125ab1 100644 --- a/Xcodes/Frontend/InfoPane/InfoPane.swift +++ b/Xcodes/Frontend/InfoPane/InfoPane.swift @@ -21,8 +21,10 @@ struct InfoPane: View { switch xcode.installState { case .notInstalled: - InstallButton(xcode: xcode) - downloadFileSize(for: xcode) + NotInstalledStateButtonsView( + downloadFileSizeString: xcode.downloadFileSizeString, + id: xcode.id + ) case let .installing(installationStep): InstallationStepDetailView(installationStep: installationStep) .fixedSize(horizontal: false, vertical: true) diff --git a/Xcodes/Frontend/InfoPane/NotInstalledStateButtonsView.swift b/Xcodes/Frontend/InfoPane/NotInstalledStateButtonsView.swift new file mode 100644 index 0000000..4935362 --- /dev/null +++ b/Xcodes/Frontend/InfoPane/NotInstalledStateButtonsView.swift @@ -0,0 +1,68 @@ +// +// NotInstalledStateButtonsView.swift +// Xcodes +// +// Created by Duong Thai on 13/10/2023. +// Copyright © 2023 Robots and Pencils. All rights reserved. +// + +import SwiftUI +import Version + +struct NotInstalledStateButtonsView: View { + let downloadFileSizeString: String? + let id: Version + + @EnvironmentObject var appState: AppState + + var body: some View { + VStack(alignment: .leading) { + Button { + appState.checkMinVersionAndInstall(id: id) + } label: { + Text("Install") .help("Install") + } + if let size = downloadFileSizeString { + + Text("DownloadSize") + .font(.headline) + Text(size) + .font(.subheadline) + } else { + EmptyView() + } + } + } +} + +struct NotInstalledStateButtonsView_Preview: PreviewProvider { + static var previews: some View { + WrapperView() + } +} + +private struct WrapperView: View { + @State var isSizeNil = false + + var downloadFileSizeString: String? { + isSizeNil + ? nil + : "1,19 GB" + } + + var body: some View { + VStack { + NotInstalledStateButtonsView( + downloadFileSizeString: downloadFileSizeString, + id: Version(major: 12, minor: 3, patch: 0) + ) + .border(.red) + Spacer() + Toggle(isOn: $isSizeNil) { + Text("Is Size Nil?") + } + } + .frame(width: 200, height: 100) + .padding() + } +}