Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.

Commit 1a34ba7

Browse files
Julian KahnertJulian Kahnert
authored andcommitted
Merge tag '3.2.0' into develop
no message
2 parents b4daf97 + 6376fd8 commit 1a34ba7

File tree

34 files changed

+900
-186
lines changed

34 files changed

+900
-186
lines changed

ArchiveCore/Sources/ArchiveBackend/ArchiveStore.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ public final class ArchiveStore: ObservableObject, ArchiveStoreAPI, Log {
2525
case uninitialized, cachedDocuments, live
2626
}
2727

28-
private static let availableProvider: [FolderProvider.Type] = [
29-
ICloudFolderProvider.self,
30-
LocalFolderProvider.self
31-
]
28+
private static let availableProvider: [FolderProvider.Type] = {
29+
if UserDefaults.standard.isInDemoMode {
30+
return [DemoFolderProvider.self]
31+
} else {
32+
return [ICloudFolderProvider.self, LocalFolderProvider.self]
33+
}
34+
}()
3235

3336
private static let fileProperties: [URLResourceKey] = [.ubiquitousItemDownloadingStatusKey, .ubiquitousItemIsDownloadingKey, .fileSizeKey, .localizedNameKey]
3437
private static let savePath: URL = {

ArchiveCore/Sources/ArchiveBackend/FolderAccess/FileChange.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ public enum FileChange {
1717
let filename: String
1818
let size: Int
1919
let downloadStatus: DownloadStatus
20+
21+
init(url: URL, filename: String, size: Int, downloadStatus: FileChange.DownloadStatus) {
22+
self.url = url
23+
self.filename = filename
24+
self.size = size
25+
self.downloadStatus = downloadStatus
26+
}
27+
28+
/// This should only be used while testing.
29+
init(fileUrl: URL, size: Int = 42, downloadStatus: FileChange.DownloadStatus = .local) {
30+
self.url = fileUrl
31+
self.filename = fileUrl.lastPathComponent
32+
self.size = size
33+
self.downloadStatus = downloadStatus
34+
}
2035
}
2136
}
2237

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// DemoFileProvider.swift
3+
//
4+
//
5+
// Created by Julian Kahnert on 08.01.21.
6+
//
7+
// swiftlint:disable force_unwrapping
8+
9+
import Foundation
10+
import Logging
11+
12+
final class DemoFolderProvider: FolderProvider, Log {
13+
private var isInitialized = false
14+
static func canHandle(_ url: URL) -> Bool {
15+
true
16+
}
17+
18+
var baseUrl: URL
19+
private var handler: FolderChangeHandler
20+
21+
init(baseUrl: URL, _ handler: @escaping FolderChangeHandler) {
22+
self.baseUrl = baseUrl
23+
self.handler = handler
24+
25+
guard !isInitialized,
26+
baseUrl.lastPathComponent != "untagged" else { return }
27+
initialize()
28+
isInitialized = true
29+
}
30+
31+
func save(data: Data, at: URL) throws {
32+
log.debug("save(data: Data, at: URL) throws")
33+
}
34+
35+
func startDownload(of: URL) throws {
36+
log.debug("startDownload(of: URL) throws")
37+
}
38+
39+
func fetch(url: URL) throws -> Data {
40+
log.debug("fetch(url: URL) throws -> Data")
41+
return Data()
42+
}
43+
44+
func delete(url: URL) throws {
45+
log.debug("delete(url: URL) throws")
46+
}
47+
48+
func rename(from: URL, to: URL) throws {
49+
log.debug("rename(from: URL, to: URL) throws")
50+
}
51+
52+
func getCreationDate(of: URL) throws -> Date? {
53+
log.debug("getCreationDate(of: URL) throws -> Date?")
54+
return nil
55+
}
56+
57+
private func initialize() {
58+
let url = Bundle.main.url(forResource: "example-bill", withExtension: "pdf")!
59+
let destination = baseUrl.appendingPathComponent("untagged").appendingPathComponent("2021 01 08 - scan1.pdf")
60+
try? FileManager.default.copyItem(at: url, to: destination)
61+
62+
let urls = [
63+
baseUrl.appendingPathComponent(NSLocalizedString("test_file1", comment: "")),
64+
baseUrl.appendingPathComponent(NSLocalizedString("test_file2", comment: "")),
65+
baseUrl.appendingPathComponent(NSLocalizedString("test_file3", comment: "")),
66+
destination
67+
]
68+
handler(self, urls.map { FileChange.added(.init(fileUrl: $0)) })
69+
}
70+
}

ArchiveCore/Sources/ArchiveBackend/ImageProcessing/ImageConverter.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ public final class ImageConverter: ObservableObject, ImageConverterAPI, Log {
106106
return
107107
}
108108

109-
let availableTags = TagStore.shared.getAvailableTags(with: [])
110109
let operation = PDFProcessing(of: mode,
111110
destinationFolder: destinationURL,
112-
tempImagePath: PathConstants.tempImageURL,
113-
archiveTags: availableTags) { progress in
111+
tempImagePath: PathConstants.tempImageURL) { progress in
114112
NotificationCenter.default.post(name: .imageProcessingQueue, object: progress)
115113
}
116114
operation.completionBlock = {

ArchiveCore/Sources/ArchiveBackend/PDFRendering/PDFProcessing.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public final class PDFProcessing: Operation, Log {
4242
private let mode: Mode
4343
private let destinationFolder: URL
4444
private let tempImagePath: URL
45-
private let archiveTags: Set<String>
4645
private let progressHandler: ProgressHandler?
4746
private let confidenceThreshold = Float(0)
4847

@@ -56,11 +55,10 @@ public final class PDFProcessing: Operation, Log {
5655
}
5756
}
5857

59-
public init(of mode: Mode, destinationFolder: URL, tempImagePath: URL, archiveTags: Set<String>, progressHandler: ProgressHandler?) {
58+
public init(of mode: Mode, destinationFolder: URL, tempImagePath: URL, progressHandler: ProgressHandler?) {
6059
self.mode = mode
6160
self.destinationFolder = destinationFolder
6261
self.tempImagePath = tempImagePath
63-
self.archiveTags = archiveTags
6462
self.progressHandler = progressHandler
6563
}
6664

ArchiveCore/Sources/ArchiveBackend/PathManager/PathManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ public final class PathManager: Log {
7878
}
7979

8080
public func getArchiveUrl() throws -> URL {
81-
let archiveURL = try archivePathType.getArchiveUrl()
81+
let archiveURL: URL
82+
if UserDefaults.standard.isInDemoMode {
83+
archiveURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
84+
} else {
85+
archiveURL = try archivePathType.getArchiveUrl()
86+
}
8287
try FileManager.default.createFolderIfNotExists(archiveURL)
8388
return archiveURL
8489
}

ArchiveCore/Sources/ArchiveBackend/TagStore.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ public final class TagStore {
2727
.store(in: &disposables)
2828
}
2929

30-
public func getAvailableTags(with searchterms: [String]) -> Set<String> {
30+
public func getAvailableTags(with searchTerms: [String]) -> Set<String> {
3131

3232
// search in filename of the documents
33-
let filteredDocuments = ArchiveStore.shared.documents.fuzzyMatchSorted(by: searchterms)
33+
let filteredDocuments = ArchiveStore.shared.documents.fuzzyMatchSorted(by: searchTerms)
3434

3535
// get a set of all document tags
3636
let allDocumentTags = filteredDocuments.reduce(into: Set<String>()) { result, document in
3737
result.formUnion(document.tags)
3838
}
3939

4040
let filteredTags: Set<String>
41-
if searchterms.isEmpty {
41+
if searchTerms.isEmpty {
4242
filteredTags = allDocumentTags
4343
} else {
4444
// filter the tags that match any searchterm
4545
filteredTags = allDocumentTags.filter { tag in
46-
searchterms.contains { tag.lowercased().contains($0.lowercased()) }
46+
searchTerms.contains { tag.lowercased().contains($0.lowercased()) }
4747
}
4848
}
4949

ArchiveCore/Sources/ArchiveSharedConstants/UserDefaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ extension UserDefaults: Log {
3030
public static let defaultQualityIndex = 1 // e.g. "good"
3131
}
3232

33+
public var isInDemoMode: Bool {
34+
UserDefaults.standard.bool(forKey: "demoMode")
35+
}
36+
3337
public var tutorialShown: Bool {
3438
get {
3539
bool(forKey: Names.tutorialShown.rawValue)

ArchiveCore/Sources/ArchiveViews/Helper/MissingViews/Stack.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ struct Stack<Content: View>: View {
3838
VStack(alignment: .center, spacing: spacing) {
3939
content
4040
}
41-
// TODO: do we really need this?
4241
.frame(maxWidth: .infinity, maxHeight: .infinity)
4342
}
4443

4544
var horizontal: some View {
4645
HStack(alignment: .center, spacing: spacing) {
4746
content
4847
}
49-
// TODO: do we really need this?
5048
.frame(maxWidth: .infinity, maxHeight: .infinity)
5149
}
5250
}

ArchiveCore/Sources/ArchiveViews/IAPView.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import SwiftUI
1010
import SwiftUIX
1111

1212
struct IAPView: View {
13+
#if os(macOS)
14+
private static let maxHeight: CGFloat? = 600
15+
#else
16+
private static let maxHeight: CGFloat? = nil
17+
#endif
1318

1419
@ObservedObject var viewModel: IAPViewModel
1520
@Environment(\.presentationMode) private var presentationMode
1621

1722
var body: some View {
1823
LazyView {
19-
VStack(alignment: .leading, spacing: 32.0) {
24+
VStack(alignment: .leading, spacing: 16) {
2025
Spacer()
2126
title
2227
features
@@ -26,7 +31,7 @@ struct IAPView: View {
2631
Spacer()
2732
}
2833
.padding()
29-
.maxWidth(600)
34+
.frame(maxWidth: 600, maxHeight: Self.maxHeight)
3035
.onAppear {
3136
#if !os(macOS)
3237
Keyboard.main.dismiss()
@@ -36,7 +41,7 @@ struct IAPView: View {
3641
}
3742

3843
private var title: some View {
39-
HStack(spacing: 24) {
44+
HStack(spacing: 12) {
4045
Image("Logo")
4146
.resizable()
4247
.frame(width: 75.0, height: 75.0, alignment: .center)
@@ -47,13 +52,13 @@ struct IAPView: View {
4752
.font(.title)
4853
}
4954
.foregroundColor(.paDarkGray)
50-
}.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
55+
}.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 16))
5156
}
5257

5358
private var features: some View {
5459
VStack(alignment: .center, spacing: 8) {
5560
WidthSyncedRow(spacing: 8) {
56-
VStack(alignment: .leading, spacing: 8) {
61+
VStack(alignment: .leading, spacing: 6) {
5762
Label("Search PDFs" as LocalizedStringKey, systemImage: .magnifyingglass)
5863
Label("iCloud Sync" as LocalizedStringKey, systemImage: .cloud)
5964
Label("Open Source" as LocalizedStringKey, systemImage: .lockOpen)
@@ -63,8 +68,8 @@ struct IAPView: View {
6368
.background(Color.paDarkGray.opacity(0.125))
6469
.cornerRadius(8)
6570
ZStack(alignment: .topTrailing) {
66-
VStack(alignment: .leading, spacing: 8) {
67-
Label("Scan Documents" as LocalizedStringKey, systemImage: .docTextViewfinder)
71+
VStack(alignment: .leading, spacing: 6) {
72+
Label("Scanner" as LocalizedStringKey, systemImage: .docTextViewfinder)
6873
Label("Searchable PDFs" as LocalizedStringKey, systemImage: .docTextMagnifyingglass)
6974
Label("Tag PDFs" as LocalizedStringKey, systemImage: .tag)
7075
}
@@ -86,7 +91,7 @@ struct IAPView: View {
8691
}
8792
}
8893

89-
HStack(spacing: 12) {
94+
HStack(spacing: 8) {
9095
Image(systemName: .heartFill)
9196
.foregroundColor(.paDarkRed)
9297
Text("Support further development of a 1 person team.")
@@ -100,16 +105,16 @@ struct IAPView: View {
100105
}
101106

102107
private var subscriptionButtons: some View {
103-
HStack(spacing: 16.0) {
108+
HStack(spacing: 8) {
104109
Button(action: {
105110
self.viewModel.tapped(button: .level1, presentationMode: self.presentationMode)
106111
}, label: {
107-
VStack(spacing: 8) {
112+
VStack(spacing: 4) {
108113
Text("Monthly")
109114
.font(.headline)
110115
Text(self.viewModel.level1Name)
111116
}
112-
.padding(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))
117+
.padding(.vertical, 4)
113118
})
114119
.buttonStyle(SubscriptionButtonStyle(isPreferred: false))
115120

@@ -121,23 +126,23 @@ struct IAPView: View {
121126
.font(.headline)
122127
Text(self.viewModel.level2Name)
123128
}
124-
.padding(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))
129+
.padding(.vertical, 4)
125130
})
126131
.buttonStyle(SubscriptionButtonStyle(isPreferred: true))
127132
}
128133
}
129134

130135
private var text: some View {
131136
ScrollView {
132-
Text("• Try the app for free! You can try the app in a free trial period of 1 month by choosing a subscription. You can try the app without any costs in this period.\n• Your Apple account will be charged for the next subscription period within the final 24 hours of the current period.\n• The subscription will renew automatically if you do not deactivate the renewal in the account setting in iTunes or the App Store at least 24 hours before the end of the subscription period.")
137+
Text("• Try the app for free! You can try the app in a free trial period of 2 weeks by choosing a subscription. You can try the app without any costs in this period.\n• Your Apple account will be charged for the next subscription period within the final 24 hours of the current period.\n• The subscription will renew automatically if you do not deactivate the renewal in the account setting in iTunes or the App Store at least 24 hours before the end of the subscription period.")
133138
.font(.caption)
134139
.foregroundColor(.paLightGray)
135140
}
136141
.maxHeight(200)
137142
}
138143

139144
private var otherButtons: some View {
140-
HStack(spacing: 16.0) {
145+
HStack(spacing: 8) {
141146
Button(action: {
142147
self.viewModel.tapped(button: .restore, presentationMode: self.presentationMode)
143148
}, label: {
@@ -163,6 +168,8 @@ struct IAPView_Previews: PreviewProvider {
163168
@State static var viewModel = IAPViewModel(iapService: MockIAPService())
164169
static var previews: some View {
165170
IAPView(viewModel: viewModel)
171+
//.previewDevice("Mac")
172+
.makeForPreviewProvider()
166173
}
167174
}
168175

0 commit comments

Comments
 (0)