Skip to content

Commit ffdb89b

Browse files
author
Thomas Taschauer
committed
Merge branch 'development' of github.com:TomTasche/OpenDocument.ios into feature/upgrade-firebase
2 parents d4b054a + 74f9005 commit ffdb89b

10 files changed

Lines changed: 478 additions & 123 deletions

File tree

OpenDocumentReader.xcodeproj/project.pbxproj

Lines changed: 259 additions & 27 deletions
Large diffs are not rendered by default.

OpenDocumentReader.xcodeproj/xcshareddata/xcschemes/ODR Full.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
</BuildableReference>
3838
</MacroExpansion>
3939
<Testables>
40+
<TestableReference
41+
skipped = "NO">
42+
<BuildableReference
43+
BuildableIdentifier = "primary"
44+
BlueprintIdentifier = "E22B252B2557F0E2001D0C52"
45+
BuildableName = "OpenDocumentReaderTests.xctest"
46+
BlueprintName = "OpenDocumentReaderTests"
47+
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
48+
</BuildableReference>
49+
</TestableReference>
4050
</Testables>
4151
</TestAction>
4252
<LaunchAction

OpenDocumentReader.xcodeproj/xcshareddata/xcschemes/ODR Lite.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "E22B252B2557F0E2001D0C52"
36+
BuildableName = "OpenDocumentReaderTests.xctest"
37+
BlueprintName = "OpenDocumentReaderTests"
38+
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
</TestAction>
3343
<LaunchAction

OpenDocumentReader/DocumentViewController.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class DocumentViewController: UIViewController, DocumentDelegate, GADBannerViewD
4646
@IBOutlet weak var bannerView: GADBannerView!
4747
@IBOutlet weak var bannerViewHeight: NSLayoutConstraint!
4848
@IBOutlet weak var barButtonItem: UIBarButtonItem!
49+
@IBOutlet weak var searchButton: UIBarButtonItem!
4950

5051
private var searchBarHeightWhenShown: NSLayoutConstraint?
5152
private var searchBarHeightWhenHidden: NSLayoutConstraint?
@@ -83,13 +84,21 @@ class DocumentViewController: UIViewController, DocumentDelegate, GADBannerViewD
8384

8485
document?.webview = self.webview
8586

86-
bannerView.delegate = self
87-
bannerView.adUnitID = "ca-app-pub-8161473686436957/8123543897"
88-
bannerView.rootViewController = self
89-
90-
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
91-
loadBannerAd()
92-
})
87+
if ConfigurationManager.manager.configuration == .lite {
88+
bannerView.delegate = self
89+
bannerView.adUnitID = "ca-app-pub-8161473686436957/8123543897"
90+
bannerView.rootViewController = self
91+
92+
if #available(iOS 14, *) {
93+
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
94+
DispatchQueue.main.async {
95+
self.loadBannerAd()
96+
}
97+
})
98+
} else {
99+
loadBannerAd()
100+
}
101+
}
93102
}
94103

95104
func setVCconstraints() {
@@ -447,6 +456,7 @@ class DocumentViewController: UIViewController, DocumentDelegate, GADBannerViewD
447456
self.webview.loadFileURL(doc.fileURL, allowingReadAccessTo: doc.fileURL)
448457

449458
progressBar.isHidden = true
459+
searchButton.isEnabled = false
450460

451461
Analytics.logEvent("load_success", parameters: [
452462
AnalyticsParameterItemName: doc.shortenedDocumentUrl,

OpenDocumentReader/Main.storyboard

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17132" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<device id="retina6_5" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17105.1"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17124"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -118,6 +118,7 @@
118118
<outlet property="menuButton" destination="Vsd-IL-ujz" id="GoN-tp-egn"/>
119119
<outlet property="progressBar" destination="ePk-bQ-fV8" id="nz6-qw-ouf"/>
120120
<outlet property="searchBar" destination="A5V-8n-dvk" id="AIb-1s-JO6"/>
121+
<outlet property="searchButton" destination="fGi-i7-iOR" id="77J-cW-TAe"/>
121122
<outlet property="segmentedControl" destination="sIx-zo-9kG" id="pCn-x0-Z01"/>
122123
<outlet property="toolBar" destination="N1x-QM-Qks" id="db4-aA-GH6"/>
123124
<outlet property="webview" destination="VF5-Do-xh9" id="25W-hb-tHy"/>
@@ -144,10 +145,10 @@
144145
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
145146
<subviews>
146147
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="83" translatesAutoresizingMaskIntoConstraints="NO" id="nfe-JJ-89b">
147-
<rect key="frame" x="-59.333333333333343" y="813" width="532.66666666666663" height="39"/>
148+
<rect key="frame" x="-72" y="813" width="558" height="39"/>
148149
<subviews>
149150
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="uLV-WY-zIj">
150-
<rect key="frame" x="0.0" y="0.0" width="122.33333333333333" height="39"/>
151+
<rect key="frame" x="0.0" y="0.0" width="130.66666666666666" height="39"/>
151152
<fontDescription key="fontDescription" type="system" pointSize="22"/>
152153
<state key="normal" title="Skip">
153154
<color key="titleColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -158,12 +159,12 @@
158159
</connections>
159160
</button>
160161
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="Eq9-2L-Y0h">
161-
<rect key="frame" x="205.33333333333337" y="0.0" width="122" height="39"/>
162+
<rect key="frame" x="213.66666666666669" y="0.0" width="130.66666666666669" height="39"/>
162163
<color key="pageIndicatorTintColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
163164
<color key="currentPageIndicatorTintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
164165
</pageControl>
165166
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BJ9-WO-km9">
166-
<rect key="frame" x="410.33333333333331" y="0.0" width="122.33333333333331" height="39"/>
167+
<rect key="frame" x="427.33333333333331" y="0.0" width="130.66666666666669" height="39"/>
167168
<fontDescription key="fontDescription" type="system" pointSize="22"/>
168169
<state key="normal" title="Next">
169170
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

OpenDocumentReaderTests/Info.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>1</string>
21+
</dict>
22+
</plist>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// OpenDocumentReaderTests.swift
3+
// OpenDocumentReaderTests
4+
//
5+
// Created by Thomas Taschauer on 08.11.20.
6+
// Copyright © 2020 Thomas Taschauer. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
@testable import OpenDocumentReader
12+
13+
class OpenDocumentReaderTests: XCTestCase {
14+
15+
private var saveURL: URL?
16+
17+
override func setUpWithError() throws {
18+
let url = URL(string: "https://api.libreoffice.org/examples/cpp/DocumentLoader/test.odt")
19+
20+
let documentsURL = try
21+
FileManager.default.url(for: .documentDirectory,
22+
in: .userDomainMask,
23+
appropriateFor: nil,
24+
create: false)
25+
26+
saveURL = documentsURL.appendingPathComponent(url!.lastPathComponent)
27+
28+
if (FileManager.default.fileExists(atPath: saveURL!.path)) {
29+
return
30+
}
31+
32+
let downloadTask = URLSession.shared.downloadTask(with: url!) {
33+
urlOrNil, responseOrNil, errorOrNil in
34+
// check for and handle errors:
35+
// * errorOrNil should be nil
36+
// * responseOrNil should be an HTTPURLResponse with statusCode in 200..<299
37+
38+
guard let fileURL = urlOrNil else { return }
39+
do {
40+
try FileManager.default.moveItem(at: fileURL, to: self.saveURL!)
41+
} catch {
42+
print ("file error: \(error)")
43+
}
44+
}
45+
downloadTask.resume()
46+
}
47+
48+
func testExample() throws {
49+
measure {
50+
let coreWrapper = CoreWrapper()
51+
52+
var translatePath = URL(fileURLWithPath: NSTemporaryDirectory())
53+
translatePath.appendPathComponent("translate.html")
54+
55+
coreWrapper.translate(saveURL?.path, into: translatePath.path, at: 0, with: nil, editable: true)
56+
XCTAssert(coreWrapper.errorCode == nil)
57+
58+
var backTranslatePath = URL(fileURLWithPath: NSTemporaryDirectory())
59+
backTranslatePath.appendPathComponent("backtranslate.html")
60+
61+
let diff = "{\"modifiedText\":{\"3\":\"This is a simple test document to demonstrate the DocumentLoadewwwwr example!\"}}"
62+
63+
coreWrapper.backTranslate(diff, into: backTranslatePath.path)
64+
XCTAssert(coreWrapper.errorCode == nil)
65+
}
66+
}
67+
}

Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ target 'OpenDocumentReader' do
1010
pod 'Google-Mobile-Ads-SDK'
1111
pod 'Firebase/Crashlytics'
1212
pod 'Firebase/Analytics'
13+
14+
target 'OpenDocumentReaderTests' do
15+
inherit! :search_paths
16+
end
1317
end

0 commit comments

Comments
 (0)