Skip to content

Commit

Permalink
Merge 01aa4bb into 38df3ab
Browse files Browse the repository at this point in the history
  • Loading branch information
sprzenus committed Nov 9, 2020
2 parents 38df3ab + 01aa4bb commit 4d1b131
Show file tree
Hide file tree
Showing 26 changed files with 798 additions and 73 deletions.
15 changes: 3 additions & 12 deletions .swiftpm/xcode/xcshareddata/xcschemes/Restler Release.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Restler"
BuildableName = "Restler"
BlueprintName = "Restler"
BlueprintIdentifier = "RestlerCore"
BuildableName = "RestlerCore"
BlueprintName = "RestlerCore"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
Expand Down Expand Up @@ -47,15 +47,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Restler"
BuildableName = "Restler"
BlueprintName = "Restler"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1210"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -14,23 +14,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Restler"
BuildableName = "Restler"
BlueprintName = "Restler"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RestlerTests"
BuildableName = "RestlerTests"
BlueprintName = "RestlerTests"
BlueprintIdentifier = "RestlerCore"
BuildableName = "RestlerCore"
BlueprintName = "RestlerCore"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -40,8 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down Expand Up @@ -75,9 +60,9 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Restler"
BuildableName = "Restler"
BlueprintName = "Restler"
BlueprintIdentifier = "RestlerCore"
BuildableName = "RestlerCore"
BlueprintName = "RestlerCore"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
Expand Down
1 change: 0 additions & 1 deletion Mintfile

This file was deleted.

32 changes: 20 additions & 12 deletions Restler-Example/Restler-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
8A9D33AD241F8333002C99DF /* ImgurEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A9D33AC241F8333002C99DF /* ImgurEndpoint.swift */; };
8AAAE2C5240FD7D3004C70BE /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AAAE2C4240FD7D3004C70BE /* Endpoint.swift */; };
8AC1C89C2403D3E500FF329E /* PostComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AC1C89B2403D3E500FF329E /* PostComment.swift */; };
8AD434042523063500186599 /* DownloadsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AD434032523063500186599 /* DownloadsView.swift */; };
8AD434082523064E00186599 /* DownloadsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AD434072523064E00186599 /* DownloadsViewModel.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -49,6 +51,8 @@
8AAAE2C4240FD7D3004C70BE /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
8AC1C89B2403D3E500FF329E /* PostComment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostComment.swift; sourceTree = "<group>"; };
8AC1C89D2403D67100FF329E /* Restler-Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Restler-Example.entitlements"; sourceTree = "<group>"; };
8AD434032523063500186599 /* DownloadsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadsView.swift; sourceTree = "<group>"; };
8AD434072523064E00186599 /* DownloadsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadsViewModel.swift; sourceTree = "<group>"; };
8ADC306224E6973D00FD49AD /* restler */ = {isa = PBXFileReference; lastKnownFileType = folder; name = restler; path = ..; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -74,13 +78,6 @@
name = Frameworks;
sourceTree = "<group>";
};
7C258D7F6F9EB17C0F3D70F6 /* Pods */ = {
isa = PBXGroup;
children = (
);
path = Pods;
sourceTree = "<group>";
};
8A41B55E240E6CC300D96084 /* Comment */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -113,7 +110,6 @@
children = (
8A87AEF12400084F007FA662 /* Restler-Example */,
8A87AEF02400084F007FA662 /* Products */,
7C258D7F6F9EB17C0F3D70F6 /* Pods */,
65676EA07F1AB6EB79937005 /* Frameworks */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -175,12 +171,22 @@
isa = PBXGroup;
children = (
8A41B55E240E6CC300D96084 /* Comment */,
8A5820DD2403CEA200BC197B /* Post */,
8AD434022523061400186599 /* Downloads */,
8A5820DA2403CDBC00BC197B /* List */,
8A5820DD2403CEA200BC197B /* Post */,
);
path = Source;
sourceTree = "<group>";
};
8AD434022523061400186599 /* Downloads */ = {
isa = PBXGroup;
children = (
8AD434032523063500186599 /* DownloadsView.swift */,
8AD434072523064E00186599 /* DownloadsViewModel.swift */,
);
path = Downloads;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -273,7 +279,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which mint >/dev/null; then\n mint run swiftlint\nelse\n echo \"warning: Mint not installed, download from https://github.com/yonaskolb/Mint\"\nfi\n";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand All @@ -284,6 +290,7 @@
files = (
8A41B560240E6CD200D96084 /* CommentView.swift in Sources */,
8A9D33AB241F6558002C99DF /* ImgurImageEncoder.swift in Sources */,
8AD434042523063500186599 /* DownloadsView.swift in Sources */,
8A87AEF32400084F007FA662 /* AppDelegate.swift in Sources */,
8A9D33AD241F8333002C99DF /* ImgurEndpoint.swift in Sources */,
8A5820DF2403CEB200BC197B /* PostViewModel.swift in Sources */,
Expand All @@ -295,6 +302,7 @@
8A41B562240E6D4400D96084 /* CommentViewModel.swift in Sources */,
8AAAE2C5240FD7D3004C70BE /* Endpoint.swift in Sources */,
8A87AF0D24000E76007FA662 /* ContentViewModel.swift in Sources */,
8AD434082523064E00186599 /* DownloadsViewModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -363,7 +371,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -419,7 +427,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
RE_DEVELOPMENT_TEAM_ID = "$(RE_DEVELOPMENT_TEAM_ID)";
Expand Down
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>
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()
}
}
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
})
}
}
4 changes: 4 additions & 0 deletions Restler-Example/Restler-Example/Source/List/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ struct ContentView: View {
List(self.viewModel.posts) { [viewModel = self.viewModel] post in
NavigationLink(post.title, destination: PostView(viewModel: viewModel.createPostViewModel(post: post)))
}
.navigationBarItems(
trailing: NavigationLink(
"Downloads",
destination: DownloadsView(viewModel: viewModel.createDownloadsViewModel())))
}
}

0 comments on commit 4d1b131

Please sign in to comment.