Skip to content

Commit a091598

Browse files
authored
Merge pull request #52 from opendocument-app/feature/lite-version
Add Lite version with Ads.
2 parents c699598 + 8699b7e commit a091598

12 files changed

Lines changed: 378 additions & 14 deletions

File tree

.github/workflows/ios_main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
destination: ['platform=iOS Simulator,name=iPhone 11']
11-
scheme: [OpenDocumentReader]
11+
scheme: [ODR Full]
1212
steps:
1313
- uses: actions/checkout@v1
1414
- name: Checkout submodule

OpenDocumentReader.xcodeproj/project.pbxproj

Lines changed: 213 additions & 4 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
</AnalyzeAction>
8383
<ArchiveAction
8484
buildConfiguration = "Release"
85+
customArchiveName = "OpenDocumentReader Full"
8586
revealArchiveInOrganizer = "YES">
8687
</ArchiveAction>
8788
</Scheme>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1130"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "E2F7ED4E220B54D600D63515"
18+
BuildableName = "OpenDocumentReader.app"
19+
BlueprintName = "OpenDocumentReader"
20+
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug Lite"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug Lite"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "E2F7ED4E220B54D600D63515"
48+
BuildableName = "OpenDocumentReader.app"
49+
BlueprintName = "OpenDocumentReader"
50+
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release Lite"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "E2F7ED4E220B54D600D63515"
65+
BuildableName = "OpenDocumentReader.app"
66+
BlueprintName = "OpenDocumentReader"
67+
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug Lite">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release Lite"
76+
customArchiveName = "OpenDocumentReader Lite"
77+
revealArchiveInOrganizer = "YES">
78+
</ArchiveAction>
79+
</Scheme>

OpenDocumentReader/AppType.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
enum AppType: String {
4+
case full = "at.tomtasche.reader"
5+
case lite = "at.tomtasche.reader.lite1"
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
3+
struct ConfigurationManager {
4+
static let manager = ConfigurationManager()
5+
6+
private(set) var configuration: AppType!
7+
8+
private init () {
9+
10+
if let productId = Bundle.main.bundleIdentifier {
11+
configuration = AppType(rawValue: productId.lowercased()) ?? .lite
12+
}
13+
}
14+
}

OpenDocumentReader/Constants.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ class Constants {
2222
static let onboarding_image_2 = "onboard2"
2323
static let onboarding_image_3 = "onboard3"
2424
static let key_was_intro_watched = "wasIntroWatched"
25+
static let configurationFull = "Full"
26+
static let configurationLite = "Lite"
2527
}

OpenDocumentReader/DocumentViewController.swift

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import WebKit
1010
import ScrollableSegmentedControl
1111
import UIKit.UIPrinter
1212
import Firebase
13+
import GoogleMobileAds
1314

1415
// taken from: https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser-based_app
15-
class DocumentViewController: UIViewController, DocumentDelegate {
16+
class DocumentViewController: UIViewController, DocumentDelegate, GADBannerViewDelegate {
1617

1718
private var browserTransition: DocumentBrowserTransitioningDelegate?
1819
public var transitionController: UIDocumentBrowserTransitionController? {
@@ -37,8 +38,9 @@ class DocumentViewController: UIViewController, DocumentDelegate {
3738

3839
@IBOutlet weak var webview: WKWebView!
3940
@IBOutlet weak var progressBar: UIProgressView!
40-
4141
@IBOutlet weak var menuButton: UIBarButtonItem!
42+
@IBOutlet weak var bannerView: GADBannerView!
43+
@IBOutlet weak var bannerViewHeight: NSLayoutConstraint!
4244

4345
private var isFullscreen = false
4446

@@ -61,8 +63,41 @@ class DocumentViewController: UIViewController, DocumentDelegate {
6163
initialSelect = false
6264

6365
document?.webview = self.webview
66+
67+
bannerView.delegate = self
68+
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
69+
bannerView.rootViewController = self
70+
71+
loadBannerAd()
72+
}
73+
74+
func loadBannerAd() {
75+
if ConfigurationManager.manager.configuration == .lite {
76+
let frame = { () -> CGRect in
77+
if #available(iOS 11.0, *) {
78+
return view.frame.inset(by: view.safeAreaInsets)
79+
} else {
80+
return view.frame
81+
}
82+
}()
83+
let viewWidth = frame.size.width
84+
85+
bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth)
86+
bannerView.load(GADRequest())
87+
} else {
88+
hideBannerView()
89+
}
90+
}
91+
92+
func hideBannerView() {
93+
bannerView.isHidden = true
94+
bannerViewHeight.constant = 0.0
6495
}
6596

97+
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
98+
hideBannerView()
99+
}
100+
66101
override func viewDidAppear(_ animated: Bool) {
67102
super.viewDidAppear(animated)
68103
}

OpenDocumentReader/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
66
<string>$(DEVELOPMENT_LANGUAGE)</string>
7-
<key>CFBundleDisplayName</key>
8-
<string>OpenDocument Reader</string>
97
<key>CFBundleDocumentTypes</key>
108
<array>
119
<dict>
@@ -54,6 +52,8 @@
5452
<string>$(MARKETING_VERSION)</string>
5553
<key>CFBundleVersion</key>
5654
<string>$(CURRENT_PROJECT_VERSION)</string>
55+
<key>GADApplicationIdentifier</key>
56+
<string>ca-app-pub-3940256099942544~1458002511</string>
5757
<key>LSRequiresIPhoneOS</key>
5858
<true/>
5959
<key>UILaunchStoryboardName</key>

OpenDocumentReader/Main.storyboard

Lines changed: 16 additions & 4 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="15505" 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="15705" 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="15510"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
@@ -71,31 +71,43 @@
7171
</subviews>
7272
</stackView>
7373
<wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VF5-Do-xh9">
74-
<rect key="frame" x="0.0" y="88" width="414" height="808"/>
74+
<rect key="frame" x="0.0" y="138" width="414" height="758"/>
7575
<color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
7676
<wkWebViewConfiguration key="configuration">
7777
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
7878
<wkPreferences key="preferences"/>
7979
</wkWebViewConfiguration>
8080
</wkWebView>
81+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="yut-lR-gq5" customClass="GADBannerView">
82+
<rect key="frame" x="0.0" y="88" width="414" height="50"/>
83+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
84+
<constraints>
85+
<constraint firstAttribute="height" constant="50" id="dMZ-rD-IOK"/>
86+
</constraints>
87+
</view>
8188
</subviews>
8289
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
8390
<constraints>
91+
<constraint firstItem="VF5-Do-xh9" firstAttribute="top" secondItem="yut-lR-gq5" secondAttribute="bottom" id="2UY-wY-5ad"/>
8492
<constraint firstItem="9mi-yf-jXf" firstAttribute="leading" secondItem="HAk-oU-gAF" secondAttribute="leading" id="5Hh-GZ-aPw"/>
85-
<constraint firstItem="VF5-Do-xh9" firstAttribute="top" secondItem="9mi-yf-jXf" secondAttribute="bottom" id="8K3-ke-I1G"/>
8693
<constraint firstItem="sKS-nk-f6M" firstAttribute="top" secondItem="SIE-Uh-Zny" secondAttribute="top" id="HjQ-CN-3cF"/>
94+
<constraint firstItem="HAk-oU-gAF" firstAttribute="trailing" secondItem="yut-lR-gq5" secondAttribute="trailing" id="NMY-4I-DYB"/>
8795
<constraint firstItem="VF5-Do-xh9" firstAttribute="leading" secondItem="HAk-oU-gAF" secondAttribute="leading" id="OvL-SW-INd"/>
8896
<constraint firstItem="VF5-Do-xh9" firstAttribute="trailing" secondItem="HAk-oU-gAF" secondAttribute="trailing" id="Qyj-ei-4NG"/>
97+
<constraint firstItem="yut-lR-gq5" firstAttribute="leading" secondItem="HAk-oU-gAF" secondAttribute="leading" id="WhK-2N-j4f"/>
8998
<constraint firstItem="N1x-QM-Qks" firstAttribute="top" secondItem="9mi-yf-jXf" secondAttribute="top" id="Yiq-pe-hl5"/>
9099
<constraint firstItem="N1x-QM-Qks" firstAttribute="bottom" secondItem="sKS-nk-f6M" secondAttribute="bottom" constant="44" id="fDF-Mx-Nxy"/>
91100
<constraint firstItem="VF5-Do-xh9" firstAttribute="bottom" secondItem="SIE-Uh-Zny" secondAttribute="bottom" id="ftB-8D-F6n"/>
92101
<constraint firstItem="sKS-nk-f6M" firstAttribute="bottom" secondItem="HAk-oU-gAF" secondAttribute="top" id="gWh-EO-FK9"/>
93102
<constraint firstItem="9mi-yf-jXf" firstAttribute="top" secondItem="SIE-Uh-Zny" secondAttribute="top" id="rED-wA-6gv"/>
94103
<constraint firstItem="9mi-yf-jXf" firstAttribute="trailing" secondItem="HAk-oU-gAF" secondAttribute="trailing" id="tPc-vX-Egd"/>
104+
<constraint firstItem="yut-lR-gq5" firstAttribute="top" secondItem="9mi-yf-jXf" secondAttribute="bottom" id="yhh-1s-AmR"/>
95105
</constraints>
96106
<viewLayoutGuide key="safeArea" id="HAk-oU-gAF"/>
97107
</view>
98108
<connections>
109+
<outlet property="bannerView" destination="yut-lR-gq5" id="28Z-1b-NAN"/>
110+
<outlet property="bannerViewHeight" destination="dMZ-rD-IOK" id="pi7-sH-NwC"/>
99111
<outlet property="menuButton" destination="Vsd-IL-ujz" id="GoN-tp-egn"/>
100112
<outlet property="progressBar" destination="ePk-bQ-fV8" id="nz6-qw-ouf"/>
101113
<outlet property="segmentedControl" destination="sIx-zo-9kG" id="pCn-x0-Z01"/>

0 commit comments

Comments
 (0)