Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GT-2489 state enum for language download icon #2386

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions godtools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@
D4960CD82CE6934E0090B114 /* ResumeLessonProgressModalViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4960CD72CE6934E0090B114 /* ResumeLessonProgressModalViewModel.swift */; };
D4960CDA2CE694280090B114 /* GetResumeLessonProgressModalInterfaceStringsRepositoryInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4960CD92CE694280090B114 /* GetResumeLessonProgressModalInterfaceStringsRepositoryInterface.swift */; };
D4960CDC2CE694F00090B114 /* GetResumeLessonProgressModalInterfaceStringsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4960CDB2CE694F00090B114 /* GetResumeLessonProgressModalInterfaceStringsUseCase.swift */; };
D4960CDE2D2E0BCD0090B114 /* LanguageDownloadIconState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4960CDD2D2E0BCD0090B114 /* LanguageDownloadIconState.swift */; };
D496B9062A9E702200CBEA19 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D496B9052A9E702200CBEA19 /* SearchBar.swift */; };
D4997E0E28D4CED800205B4C /* YouTubeiOSPlayerHelper in Frameworks */ = {isa = PBXBuildFile; productRef = D4997E0D28D4CED800205B4C /* YouTubeiOSPlayerHelper */; };
D4AFA4452BAC93B400318023 /* ToolFilterLanguagesInterfaceStringsDomainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AFA4442BAC93B400318023 /* ToolFilterLanguagesInterfaceStringsDomainModel.swift */; };
Expand Down Expand Up @@ -3241,6 +3242,7 @@
D4960CD72CE6934E0090B114 /* ResumeLessonProgressModalViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResumeLessonProgressModalViewModel.swift; sourceTree = "<group>"; };
D4960CD92CE694280090B114 /* GetResumeLessonProgressModalInterfaceStringsRepositoryInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetResumeLessonProgressModalInterfaceStringsRepositoryInterface.swift; sourceTree = "<group>"; };
D4960CDB2CE694F00090B114 /* GetResumeLessonProgressModalInterfaceStringsUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetResumeLessonProgressModalInterfaceStringsUseCase.swift; sourceTree = "<group>"; };
D4960CDD2D2E0BCD0090B114 /* LanguageDownloadIconState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageDownloadIconState.swift; sourceTree = "<group>"; };
D496B9052A9E702200CBEA19 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
D4AFA4442BAC93B400318023 /* ToolFilterLanguagesInterfaceStringsDomainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolFilterLanguagesInterfaceStringsDomainModel.swift; sourceTree = "<group>"; };
D4AFA4462BAC950800318023 /* GetToolFilterLanguagesInterfaceStringsRepositoryInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetToolFilterLanguagesInterfaceStringsRepositoryInterface.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8076,6 +8078,7 @@
children = (
45AC9DE82B28A9CD00DEEBFE /* DownloadableLanguageItemView.swift */,
45AC9DE92B28A9CD00DEEBFE /* LanguageDownloadIcon.swift */,
D4960CDD2D2E0BCD0090B114 /* LanguageDownloadIconState.swift */,
);
path = Subviews;
sourceTree = "<group>";
Expand Down Expand Up @@ -13592,6 +13595,7 @@
45BDA64C2954FF08007E259B /* WebArchiveOperationError.swift in Sources */,
4535BE162B348BF100A8B62F /* ReviewShareShareableView.swift in Sources */,
45F88B102860BA8800C8027F /* Array+ResourceModel.swift in Sources */,
D4960CDE2D2E0BCD0090B114 /* LanguageDownloadIconState.swift in Sources */,
45C0FAE12A8A7CFB009A7E71 /* PullToRefreshScrollView.swift in Sources */,
45325F26285CF8B40078D932 /* VideoViewRepresentable.swift in Sources */,
45FA155E2B48BAC4005F986D /* AppLottieBarItem.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct DownloadableLanguageItemView: View {

} label: {

LanguageDownloadIcon(languageDownloadStatus: downloadableLanguage.downloadStatus, animationDownloadProgress: animationDownloadProgress, shouldConfirmDownloadRemoval: shouldConfirmDownloadRemoval)
LanguageDownloadIcon(state: getLanguageDownloadIconState())
}
}
.onChange(of: downloadableLanguage.downloadStatus, perform: { newDownloadStatus in
Expand Down Expand Up @@ -115,6 +115,43 @@ struct DownloadableLanguageItemView: View {
}
}

private func getLanguageDownloadIconState() -> LanguageDownloadIconState {

switch downloadableLanguage.downloadStatus {
case .notDownloaded:
return .notDownloaded

case .downloading(let progress):

if let downloadProgress = animationDownloadProgress ?? progress {

return .downloading(progress: downloadProgress)
} else {
return .notDownloaded
}

case .downloaded:
if shouldConfirmDownloadRemoval {
return .remove

} else if shouldFinishDownloadAnimation(), let animationDownloadProgress = animationDownloadProgress {

return .downloading(progress: animationDownloadProgress)

} else {
return .downloaded
}
}
}

private func shouldFinishDownloadAnimation() -> Bool {
guard let animationDownloadProgress = animationDownloadProgress else {
return false
}

return animationDownloadProgress <= 1
}

private func didTapItem() {

switch downloadableLanguage.downloadStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ struct LanguageDownloadIcon: View {

private static let lightGrey = Color.getColorWithRGB(red: 151, green: 151, blue: 151, opacity: 1)

private let languageDownloadStatus: LanguageDownloadStatusDomainModel
private let animationDownloadProgress: Double?
private let shouldConfirmDownloadRemoval: Bool
private let state: LanguageDownloadIconState

init(languageDownloadStatus: LanguageDownloadStatusDomainModel, animationDownloadProgress: Double?, shouldConfirmDownloadRemoval: Bool) {
self.languageDownloadStatus = languageDownloadStatus
self.animationDownloadProgress = animationDownloadProgress
self.shouldConfirmDownloadRemoval = shouldConfirmDownloadRemoval
init(state: LanguageDownloadIconState) {
self.state = state
}

var body: some View {
Expand All @@ -37,45 +33,24 @@ struct LanguageDownloadIcon: View {

@ViewBuilder private func innerIcon() -> some View {

switch languageDownloadStatus {
switch state {
case .notDownloaded:

notDownloadedIcon()
Image(systemName: "arrow.down.to.line")
.imageScale(.small)

case .downloading(let progress):
drawProgressInCircle(progress: progress)

if let downloadProgress = self.animationDownloadProgress ?? progress {

drawProgressInCircle(progress: downloadProgress)

} else {

notDownloadedIcon()
}

case .downloaded:
Image(systemName: "checkmark")
.imageScale(.small)

if shouldConfirmDownloadRemoval {

Image(systemName: "xmark")
.imageScale(.small)

} else if shouldFinishAnimatingDownloadProgress(), let animationDownloadProgress = animationDownloadProgress {

drawProgressInCircle(progress: animationDownloadProgress)

} else {
Image(systemName: "checkmark")
.imageScale(.small)
}
case .remove:
Image(systemName: "xmark")
.imageScale(.small)
}
}

@ViewBuilder private func notDownloadedIcon() -> some View {
Image(systemName: "arrow.down.to.line")
.imageScale(.small)
}

@ViewBuilder private func drawProgressInCircle(progress: Double) -> some View {

GeometryReader { geometry in
Expand Down Expand Up @@ -105,36 +80,19 @@ struct LanguageDownloadIcon: View {
}

private func iconColor() -> Color {
switch languageDownloadStatus {

switch state {
case .notDownloaded:
return LanguageDownloadIcon.lightGrey

case .downloading(let progress):

let downloadProgress = self.animationDownloadProgress ?? progress
if downloadProgress != nil {
return ColorPalette.gtBlue.color
} else {
return LanguageDownloadIcon.lightGrey
}
case .downloading:
return ColorPalette.gtBlue.color

case .downloaded:
return ColorPalette.gtBlue.color

if shouldConfirmDownloadRemoval {
return Color(.sRGB, red: 229 / 255, green: 91 / 255, blue: 54 / 255, opacity: 1.0)
} else {
return ColorPalette.gtBlue.color
}
case .remove:
return Color(.sRGB, red: 229 / 255, green: 91 / 255, blue: 54 / 255, opacity: 1.0)
}
}

private func shouldFinishAnimatingDownloadProgress() -> Bool {

guard let animationDownloadProgress = animationDownloadProgress else {
return false
}

return animationDownloadProgress <= 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// LanguageDownloadIconState.swift
// godtools
//
// Created by Rachael Skeath on 1/7/25.
// Copyright © 2025 Cru. All rights reserved.
//

import Foundation

enum LanguageDownloadIconState {
case notDownloaded
case downloading(progress: Double)
case downloaded
case remove
}
Loading