-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
798 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Restler-Example/Restler-Example.xcodeproj/xcshareddata/xcschemes/Restler-Example.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1210" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "8A87AEEE2400084F007FA662" | ||
BuildableName = "Restler-Example.app" | ||
BlueprintName = "Restler-Example" | ||
ReferencedContainer = "container:Restler-Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "8A87AEEE2400084F007FA662" | ||
BuildableName = "Restler-Example.app" | ||
BlueprintName = "Restler-Example" | ||
ReferencedContainer = "container:Restler-Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "8A87AEEE2400084F007FA662" | ||
BuildableName = "Restler-Example.app" | ||
BlueprintName = "Restler-Example" | ||
ReferencedContainer = "container:Restler-Example.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
52 changes: 52 additions & 0 deletions
52
Restler-Example/Restler-Example/Source/Downloads/DownloadsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// DownloadsView.swift | ||
// Restler-Example | ||
// | ||
// Created by Bartłomiej Świerad on 29/09/2020. | ||
// Copyright © 2020 Railwaymen. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct DownloadsView: View { | ||
@ObservedObject var viewModel: DownloadsViewModel | ||
|
||
var body: some View { | ||
getActiveView() | ||
} | ||
|
||
@ViewBuilder | ||
private func getActiveView() -> some View { | ||
if let progress = viewModel.progress { | ||
ProgressView(progress: progress) | ||
} else { | ||
DownloadForm(url: $viewModel.urlString, downloadAction: viewModel.download) | ||
} | ||
} | ||
} | ||
|
||
struct ProgressView: View { | ||
let progress: Progress | ||
|
||
var body: some View { | ||
VStack { | ||
Text("Downloading...") | ||
ProgressView(progress: progress) | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
private struct DownloadForm: View { | ||
@Binding var url: String | ||
let downloadAction: () -> Void | ||
|
||
var body: some View { | ||
VStack { | ||
TextField("Download URL", text: $url) | ||
.textFieldStyle(RoundedBorderTextFieldStyle()) | ||
Button("Download", action: downloadAction) | ||
} | ||
.padding() | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
Restler-Example/Restler-Example/Source/Downloads/DownloadsViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// DownloadsViewModel.swift | ||
// Restler-Example | ||
// | ||
// Created by Bartłomiej Świerad on 29/09/2020. | ||
// Copyright © 2020 Railwaymen. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import RestlerCore | ||
|
||
final class DownloadsViewModel: ObservableObject { | ||
let objectWillChange: ObservableObjectPublisher = .init() | ||
|
||
@Published var urlString: String = "" | ||
|
||
private(set) var progress: Progress? = nil { | ||
willSet { | ||
objectWillChange.send() | ||
isProgressHidden = newValue == nil | ||
} | ||
} | ||
|
||
private(set) var isProgressHidden: Bool = true { | ||
willSet { objectWillChange.send() } | ||
} | ||
|
||
private var url: URL? { | ||
URL(string: urlString) | ||
} | ||
|
||
// MARK: - Initialization | ||
init() {} | ||
|
||
// MARK: - Internal | ||
func download() { | ||
guard let url = self.url else { return } | ||
Restler(baseURL: url) | ||
.get("") | ||
.receive(on: .main) | ||
.requestDownload() | ||
.subscribe( | ||
onProgress: { [weak self] task in | ||
self?.progress = task.progress | ||
}, | ||
onSuccess: { fileURL in | ||
print("Successful download to:", fileURL) | ||
}, | ||
onError: { error in | ||
print("Download error:", error) | ||
}, | ||
onCompletion: { [weak self] _ in | ||
self?.progress = nil | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.