Skip to content

Commit

Permalink
Merge branch 'release/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBonus committed Mar 9, 2018
2 parents 569aab1 + 2ddd91f commit 3fcf1be
Show file tree
Hide file tree
Showing 29 changed files with 1,005 additions and 343 deletions.
28 changes: 28 additions & 0 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
E9256F7E2039B29D00DE86E9 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E9256F802039B29D00DE86E9 /* InfoPlist.strings */; };
E93B0D742028B21400126346 /* ChatsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93B0D732028B21400126346 /* ChatsProvider.swift */; };
E93B0D762028B28E00126346 /* AdamantChatsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93B0D752028B28E00126346 /* AdamantChatsProvider.swift */; };
E93D7ABE2052CEE1005D19DC /* NotificationsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93D7ABD2052CEE1005D19DC /* NotificationsService.swift */; };
E93D7AC02052CF63005D19DC /* AdamantNotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93D7ABF2052CF63005D19DC /* AdamantNotificationService.swift */; };
E93D7AC22052EE21005D19DC /* SettingsViewController+StayIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93D7AC12052EE21005D19DC /* SettingsViewController+StayIn.swift */; };
E93D7AC520530F76005D19DC /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = E93D7AC720530F76005D19DC /* Localizable.stringsdict */; };
E93EFE13200D1156000BB482 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E93EFE12200D1156000BB482 /* ChatViewController.swift */; };
E9452A4C20344834005BA34C /* Account.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E9452A4E20344834005BA34C /* Account.storyboard */; };
E94883E7203F07CD00F6E1B0 /* PassphraseValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = E94883E6203F07CD00F6E1B0 /* PassphraseValidation.swift */; };
Expand Down Expand Up @@ -209,6 +213,11 @@
E9256F7F2039B29D00DE86E9 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/InfoPlist.strings; sourceTree = "<group>"; };
E93B0D732028B21400126346 /* ChatsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatsProvider.swift; sourceTree = "<group>"; };
E93B0D752028B28E00126346 /* AdamantChatsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantChatsProvider.swift; sourceTree = "<group>"; };
E93D7ABD2052CEE1005D19DC /* NotificationsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsService.swift; sourceTree = "<group>"; };
E93D7ABF2052CF63005D19DC /* AdamantNotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantNotificationService.swift; sourceTree = "<group>"; };
E93D7AC12052EE21005D19DC /* SettingsViewController+StayIn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsViewController+StayIn.swift"; sourceTree = "<group>"; };
E93D7AC620530F76005D19DC /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ru; path = ru.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
E93D7AC920530F8E005D19DC /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = Base; path = Base.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
E93EFE12200D1156000BB482 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
E9452A4D20344834005BA34C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Account.storyboard; sourceTree = "<group>"; };
E94883E6203F07CD00F6E1B0 /* PassphraseValidation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PassphraseValidation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -398,6 +407,7 @@
E9E7CDAE2002B8A100DFC4DB /* Router.swift */,
E905D39C204C13B900DDB504 /* SecuredStore.swift */,
E90A494C204DA932009F6A65 /* LocalAuthentication.swift */,
E93D7ABD2052CEE1005D19DC /* NotificationsService.swift */,
);
path = ServiceProtocols;
sourceTree = "<group>";
Expand All @@ -410,6 +420,7 @@
E9E7CD922002740500DFC4DB /* AdamantAccountService.swift */,
E9E7CDBF2003AF6D00DFC4DB /* AdamantCellFactory.swift */,
E9E7CD8E20026CD300DFC4DB /* AdamantDialogService.swift */,
E93D7ABF2052CF63005D19DC /* AdamantNotificationService.swift */,
E913C9161FFFAF76001A83F7 /* JSAdamantCore.swift */,
E9E7CDB42002BA6900DFC4DB /* SwinjectedRouter.swift */,
E950273F202E257E002C1098 /* RepeaterService.swift */,
Expand Down Expand Up @@ -456,6 +467,7 @@
E913C8F81FFFA51D001A83F7 /* Assets.xcassets */,
E9256F802039B29D00DE86E9 /* InfoPlist.strings */,
E9256F7B2039B29A00DE86E9 /* Localizable.strings */,
E93D7AC720530F76005D19DC /* Localizable.stringsdict */,
E9256F752039A9A200DE86E9 /* LaunchScreen.storyboard */,
E9C51EEC2011416E00385EB7 /* adamant-core.js */,
);
Expand Down Expand Up @@ -564,6 +576,7 @@
E948E04D20278D5600975D6B /* SettingsDependencies.swift */,
E948E03A20235E2300975D6B /* SettingsRoutes.swift */,
E982F69B20235B4D00566AC7 /* SettingsViewController.swift */,
E93D7AC12052EE21005D19DC /* SettingsViewController+StayIn.swift */,
E9942B7F203C058C00C163AF /* QRGeneratorViewController.swift */,
);
path = Settings;
Expand Down Expand Up @@ -789,6 +802,7 @@
E9256F632034E7DE00DE86E9 /* Settings.storyboard in Resources */,
E9EC341C200524CA00C0E546 /* Roboto_400_italic.ttf in Resources */,
E9256F792039B29A00DE86E9 /* Localizable.strings in Resources */,
E93D7AC520530F76005D19DC /* Localizable.stringsdict in Resources */,
E9EC3415200524CA00C0E546 /* Exo+2_100_normal.ttf in Resources */,
E9EC341A200524CA00C0E546 /* Exo+2_700_normal.ttf in Resources */,
E9EC341D200524CA00C0E546 /* Roboto_400_normal.ttf in Resources */,
Expand Down Expand Up @@ -831,6 +845,7 @@
"${BUILT_PRODUCTS_DIR}/MessageKit/MessageKit.framework",
"${BUILT_PRODUCTS_DIR}/MyLittlePinpad/MyLittlePinpad.framework",
"${BUILT_PRODUCTS_DIR}/QRCodeReader.swift/QRCodeReader.framework",
"${BUILT_PRODUCTS_DIR}/RNCryptor/RNCryptor.framework",
"${BUILT_PRODUCTS_DIR}/Swinject/Swinject.framework",
"${BUILT_PRODUCTS_DIR}/SwinjectStoryboard/SwinjectStoryboard.framework",
);
Expand All @@ -845,6 +860,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MessageKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MyLittlePinpad.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QRCodeReader.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNCryptor.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Swinject.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwinjectStoryboard.framework",
);
Expand Down Expand Up @@ -903,6 +919,7 @@
E9E7CD8D20026B6600DFC4DB /* DialogService.swift in Sources */,
E9E7CDB72003994E00DFC4DB /* AdamantUtilities.swift in Sources */,
E9147B6320505C7500145913 /* QRCodeReader+adamant.swift in Sources */,
E93D7AC22052EE21005D19DC /* SettingsViewController+StayIn.swift in Sources */,
E9942B80203C058C00C163AF /* QRGeneratorViewController.swift in Sources */,
E948E0462024DAE800975D6B /* AdamantUserInfoKeys.swift in Sources */,
E9E7CD9120026FA100DFC4DB /* SwinjectDependencies.swift in Sources */,
Expand Down Expand Up @@ -968,12 +985,14 @@
E9CE7789202B9DC2009CF70D /* ChatTransaction+CoreDataClass.swift in Sources */,
E9E7CDBE2003AEFB00DFC4DB /* CellFactory.swift in Sources */,
E9CAE8D62018AC5300345E76 /* AdamantApi+Transactions.swift in Sources */,
E93D7ABE2052CEE1005D19DC /* NotificationsService.swift in Sources */,
E972206B201F44CA004F2AAD /* TransfersProvider.swift in Sources */,
E9722068201F42CC004F2AAD /* InMemoryCoreDataStack.swift in Sources */,
E9C51EF12013F18000385EB7 /* NewChatViewController.swift in Sources */,
E913C9171FFFAF76001A83F7 /* JSAdamantCore.swift in Sources */,
E95F856520067A030070534A /* GlobalConstants.swift in Sources */,
E9502740202E257E002C1098 /* RepeaterService.swift in Sources */,
E93D7AC02052CF63005D19DC /* AdamantNotificationService.swift in Sources */,
E93B0D762028B28E00126346 /* AdamantChatsProvider.swift in Sources */,
E90A4943204C5ED6009F6A65 /* EurekaPassphraseRow.swift in Sources */,
E95F8589200900B10070534A /* ChatType.swift in Sources */,
Expand Down Expand Up @@ -1060,6 +1079,15 @@
name = InfoPlist.strings;
sourceTree = "<group>";
};
E93D7AC720530F76005D19DC /* Localizable.stringsdict */ = {
isa = PBXVariantGroup;
children = (
E93D7AC620530F76005D19DC /* ru */,
E93D7AC920530F8E005D19DC /* Base */,
);
name = Localizable.stringsdict;
sourceTree = "<group>";
};
E9452A4E20344834005BA34C /* Account.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
97 changes: 95 additions & 2 deletions Adamant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var repeater: RepeaterService!

weak var accountService: AccountService?
weak var notificationService: NotificationsService?

// MARK: - Lifecycle

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// MARK: 1. Initiating Swinject
let container = SwinjectStoryboard.defaultContainer
Container.loggingFunction = nil // Logging currently not supported with SwinjectStoryboards.
Expand All @@ -29,6 +31,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
container.registerAdamantChatsStory()
container.registerAdamantSettingsStory()

accountService = container.resolve(AccountService.self)
notificationService = container.resolve(NotificationsService.self)


// MARK: 2. Prepare UI
self.window = UIWindow(frame: UIScreen.main.bounds)
Expand Down Expand Up @@ -65,8 +70,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
repeater.registerForegroundCall(label: "chatsProvider", interval: 3, queue: DispatchQueue.global(qos: .utility), callback: chatsProvider.update)


// MARK: 4. On logout, pop all navigators to root.
// MARK: 4. Notifications
if let service = container.resolve(NotificationsService.self) {
if service.notificationsEnabled {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
} else {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalNever)
}

NotificationCenter.default.addObserver(forName: Notification.Name.adamantShowNotificationsChanged, object: service, queue: OperationQueue.main) { _ in
if service.notificationsEnabled {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
} else {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalNever)
}
}
}


// MARK: 5. Logout reset
NotificationCenter.default.addObserver(forName: Notification.Name.adamantUserLoggedOut, object: nil, queue: OperationQueue.main) { [weak self] _ in
// On logout, pop all navigators to root.
guard let tbc = self?.window?.rootViewController as? UITabBarController, let vcs = tbc.viewControllers else {
return
}
Expand All @@ -79,6 +103,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

// MARK: Timers

func applicationWillResignActive(_ application: UIApplication) {
repeater.pauseAll()
}
Expand All @@ -89,5 +115,72 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func applicationDidBecomeActive(_ application: UIApplication) {
repeater.resumeAll()

if accountService?.account != nil {
notificationService?.removeAllDeliveredNotifications()
}
}

// MARK: Background fetch

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let container = Container()
container.registerAdamantBackgroundFetchServices()

guard let securedStore = container.resolve(SecuredStore.self),
let apiService = container.resolve(ApiService.self),
let notificationsService = container.resolve(NotificationsService.self) else {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalNever)
completionHandler(.failed)
return
}

guard let address = securedStore.get(StoreKey.chatProvider.address) else {
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalNever)
completionHandler(.failed)
return
}

var lastHeight: Int64?
if let raw = securedStore.get(StoreKey.chatProvider.receivedLastHeight) {
lastHeight = Int64(raw)
} else {
lastHeight = nil
}

var notifiedCount = 0
if let raw = securedStore.get(StoreKey.chatProvider.notifiedLastHeight), let notifiedHeight = Int64(raw), let h = lastHeight {
if h < notifiedHeight {
lastHeight = notifiedHeight

if let raw = securedStore.get(StoreKey.chatProvider.notifiedMessagesCount), let count = Int(raw) {
notifiedCount = count
}
}
}


apiService.getChatTransactions(address: address, height: lastHeight, offset: nil) { result in
switch result {
case .success(let transactions):
if transactions.count > 0 {
let total = transactions.count + notifiedCount
securedStore.set(String(total), for: StoreKey.chatProvider.notifiedMessagesCount)

if let newLastHeight = transactions.map({$0.height}).sorted().last {
securedStore.set(String(newLastHeight), for: StoreKey.chatProvider.notifiedLastHeight)
}


notificationsService.showNotification(title: String.adamantLocalized.notifications.newMessageTitle, body: String.localizedStringWithFormat(String.adamantLocalized.notifications.newMessageBody, total), type: .newMessages(count: total))
completionHandler(.newData)
} else {
completionHandler(.noData)
}

case .failure(_):
completionHandler(.failed)
}
}
}
}
22 changes: 22 additions & 0 deletions Adamant/Assets/Base.lproj/Localizable.stringsdict
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>You have %d new message(s)</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@messages@</string>
<key>messages</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>You have %d new message</string>
<key>other</key>
<string>You have %d new messages</string>
</dict>
</dict>
</dict>
</plist>
Loading

0 comments on commit 3fcf1be

Please sign in to comment.