Skip to content

Commit

Permalink
Merge pull request #336 from TortugaPower/develop
Browse files Browse the repository at this point in the history
Release 3.3.0
  • Loading branch information
GianniCarlo authored Mar 30, 2019
2 parents 6be02e1 + 267c138 commit ef5cc17
Show file tree
Hide file tree
Showing 245 changed files with 7,278 additions and 1,811 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ disabled_rules:
- switch_case_alignment
- identifier_name
- trailing_comma
- private_over_fileprivate
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
language: swift
osx_image: xcode10
xcode_project: BookPlayer.xcodeproj
xcode_scheme: BookPlayer
xcode_destination: platform=iOS Simulator,OS=11.3,name=iPhone 5s
cache:
directories:
- Carthage
- $HOME/Library/Caches/Homebrew
before_install:
- brew update
- brew outdated carthage || brew upgrade carthage
before_script:
# bootstrap the dependencies for the project
# you can remove if you don't have dependencies
- carthage bootstrap --verbose --no-use-binaries --platform iOS --cache-builds
script:
- swiftlint
- xcodebuild -project BookPlayer.xcodeproj -scheme BookPlayer -destination 'platform=iOS Simulator,OS=11.3,name=iPhone 5s' test
- carthage bootstrap --no-use-binaries --platform iOS --cache-builds
- swiftlint
401 changes: 368 additions & 33 deletions BookPlayer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

83 changes: 64 additions & 19 deletions BookPlayer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import AVFoundation
import DirectoryWatcher
import MediaPlayer
import Sentry
import SwiftyStoreKit
import UIKit

@UIApplicationMain
Expand All @@ -17,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var wasPlayingBeforeInterruption: Bool = false
var watcher: DirectoryWatcher?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let defaults: UserDefaults = UserDefaults.standard

Expand All @@ -31,47 +33,50 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Appearance
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor(hex: "#37454E")
NSAttributedString.Key.foregroundColor: UIColor(hex: "#37454E")
]

if #available(iOS 11, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedStringKey.foregroundColor: UIColor(hex: "#37454E")
NSAttributedString.Key.foregroundColor: UIColor(hex: "#37454E")
]
}

try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeSpokenAudio, options: [])
try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode(rawValue: convertFromAVAudioSessionMode(AVAudioSession.Mode.spokenAudio)), options: [])

// register to audio-interruption notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioInterruptions(_:)), name: NSNotification.Name.AVAudioSessionInterruption, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioInterruptions(_:)), name: AVAudioSession.interruptionNotification, object: nil)

// register to audio-route-change notifications
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioRouteChange(_:)), name: NSNotification.Name.AVAudioSessionRouteChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.handleAudioRouteChange(_:)), name: AVAudioSession.routeChangeNotification, object: nil)

// register for remote events
self.setupMPRemoteCommands()
// register document's folder listener
self.setupDocumentListener()
// load themes if necessary
DataManager.setupDefaultTheme()
// setup store required listeners
self.setupStoreListener()

if let activityDictionary = launchOptions?[.userActivityDictionary] as? [UIApplicationLaunchOptionsKey: Any],
if let activityDictionary = launchOptions?[.userActivityDictionary] as? [UIApplication.LaunchOptionsKey: Any],
let activityType = activityDictionary[.userActivityType] as? String,
activityType == Constants.UserActivityPlayback {
defaults.set(true, forKey: activityType)
}

// Create a Sentry client and start crash handler
Client.shared = try? Client(dsn: "https://23b4d02f7b044c10adb55a0cc8de3881@sentry.io/1414296")
((try? Client.shared?.startCrashHandler()) as ()??)

return true
}

// Handles audio file urls, like when receiving files through AirDrop
// Also handles custom URL scheme 'bookplayer://'
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
guard url.isFileURL else {
if PlayerManager.shared.isLoaded {
PlayerManager.shared.play()
} else {
UserDefaults.standard.set(true, forKey: Constants.UserActivityPlayback)
}

self.playLastBook()
return true
}

Expand All @@ -80,7 +85,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
PlayerManager.shared.play()
return true
}
Expand Down Expand Up @@ -110,7 +115,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Check if the app is on the PlayerViewController
// TODO: Check if this still works as expected given the new storyboard structure
guard let navigationVC = UIApplication.shared.keyWindow?.rootViewController!, navigationVC.childViewControllers.count > 1 else {
guard let navigationVC = UIApplication.shared.keyWindow?.rootViewController!, navigationVC.children.count > 1 else {
return
}

Expand All @@ -122,11 +127,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
self.playLastBook()
}

func playLastBook() {
if PlayerManager.shared.isLoaded {
PlayerManager.shared.play()
} else {
UserDefaults.standard.set(true, forKey: Constants.UserActivityPlayback)
}
}

// Playback may be interrupted by calls. Handle pause
@objc func handleAudioInterruptions(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt,
let type = AVAudioSessionInterruptionType(rawValue: typeValue) else {
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else {
return
}

Expand All @@ -140,10 +157,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}

let options = AVAudioSessionInterruptionOptions(rawValue: optionsValue)
let options = AVAudioSession.InterruptionOptions(rawValue: optionsValue)
if options.contains(.shouldResume) {
PlayerManager.shared.play()
}
@unknown default:
break
}
}

Expand All @@ -152,7 +171,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
guard PlayerManager.shared.isPlaying,
let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSessionRouteChangeReason(rawValue: reasonValue) else {
let reason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else {
return
}

Expand Down Expand Up @@ -244,4 +263,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}

func setupStoreListener() {
SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {
guard purchase.transaction.transactionState == .purchased
|| purchase.transaction.transactionState == .restored
else { continue }

UserDefaults.standard.set(true, forKey: Constants.UserDefaults.donationMade.rawValue)
NotificationCenter.default.post(name: .donationMade, object: nil)

if purchase.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
}
}

SwiftyStoreKit.shouldAddStorePaymentHandler = { _, _ in
true
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromAVAudioSessionMode(_ input: AVAudioSession.Mode) -> String {
return input.rawValue
}
23 changes: 23 additions & 0 deletions BookPlayer/Assets.xcassets/appIconMask.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "appIconMask.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "appIconMask@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "appIconMask@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions BookPlayer/Assets.xcassets/artworkControls/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "playerIconForwardArrowShadow.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "playerIconForwardArrowShadow@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "playerIconForwardArrowShadow@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "playerIconRewindArrowShadow.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "playerIconRewindArrowShadow@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "playerIconRewindArrowShadow@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "playerIconShadow.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "playerIconShadow@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "playerIconShadow@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "currentScreenBrightnessIndicator.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "currentScreenBrightnessIndicator@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "currentScreenBrightnessIndicator@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "libraryIconDelete.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "libraryIconDelete@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "libraryIconDelete@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading

0 comments on commit ef5cc17

Please sign in to comment.