Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Sep 20, 2024
2 parents 70ede97 + 808702d commit 5e19bbd
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 167 deletions.
16 changes: 2 additions & 14 deletions ios/CCC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
5C693EBA25C4AFF800C9373E /* SelectCurrenciesBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C693EB925C4AFF800C9373E /* SelectCurrenciesBottomView.swift */; };
5C8FDBDD25BF3FBE00F280FF /* ObservableSEEDViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C8FDBDC25BF3FBE00F280FF /* ObservableSEEDViewModel.swift */; };
5C94AC32282FA4B2004C9B3D /* CurrencyImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C94AC31282FA4B2004C9B3D /* CurrencyImageView.swift */; };
5C9A59BB25C350DE006745B0 /* MainScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C9A59BA25C350DE006745B0 /* MainScene.swift */; };
5C9C75C82603A36A00D66FDD /* ToolbarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C9C75C72603A36A00D66FDD /* ToolbarButton.swift */; };
5CB954BF26932408007632DC /* AdaptiveBannerAdView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CB954BE26932408007632DC /* AdaptiveBannerAdView.swift */; };
5CBFC9472AC2E43800E2CE61 /* KermitExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CBFC9462AC2E43800E2CE61 /* KermitExt.swift */; };
Expand Down Expand Up @@ -129,7 +128,6 @@
5C693EB925C4AFF800C9373E /* SelectCurrenciesBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectCurrenciesBottomView.swift; sourceTree = "<group>"; };
5C8FDBDC25BF3FBE00F280FF /* ObservableSEEDViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableSEEDViewModel.swift; sourceTree = "<group>"; };
5C94AC31282FA4B2004C9B3D /* CurrencyImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyImageView.swift; sourceTree = "<group>"; };
5C9A59BA25C350DE006745B0 /* MainScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScene.swift; sourceTree = "<group>"; };
5C9C75C72603A36A00D66FDD /* ToolbarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarButton.swift; sourceTree = "<group>"; };
5CACB69328A7EF1800A2D13C /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
5CB954BE26932408007632DC /* AdaptiveBannerAdView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveBannerAdView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -201,14 +199,6 @@
path = Calculator;
sourceTree = "<group>";
};
5C31E42728141EDF008C42B9 /* Main */ = {
isa = PBXGroup;
children = (
5C9A59BA25C350DE006745B0 /* MainScene.swift */,
);
path = Main;
sourceTree = "<group>";
};
5C31E42828141EFA008C42B9 /* Slides */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -291,7 +281,6 @@
5C5D093A2562EC1300DA9C4A /* UI */ = {
isa = PBXGroup;
children = (
5C31E42728141EDF008C42B9 /* Main */,
5C31E42828141EFA008C42B9 /* Slides */,
5C31E41C28141C61008C42B9 /* Calculator */,
5C31E42B28142033008C42B9 /* Currencies */,
Expand Down Expand Up @@ -555,7 +544,6 @@
5C31E43128142110008C42B9 /* CurrenciesItemView.swift in Sources */,
5C31E42028141CA4008C42B9 /* OutputView.swift in Sources */,
5CEAF774295F2ECC0018C7FA /* DeviceUtil.swift in Sources */,
5C9A59BB25C350DE006745B0 /* MainScene.swift in Sources */,
5CBFC9472AC2E43800E2CE61 /* KermitExt.swift in Sources */,
5C34B8CC29590500009C84AB /* SnackView.swift in Sources */,
5C5D09362562EBDE00DA9C4A /* Koin.swift in Sources */,
Expand Down Expand Up @@ -804,7 +792,7 @@
repositoryURL = "https://github.com/googleads/swift-package-manager-google-mobile-ads.git";
requirement = {
kind = exactVersion;
version = 11.8.0;
version = 11.10.0;
};
};
5C5C0BA22874B8450061AEF9 /* XCRemoteSwiftPackageReference "swiftui-navigation-stack" */ = {
Expand All @@ -820,7 +808,7 @@
repositoryURL = "https://github.com/firebase/firebase-ios-sdk";
requirement = {
kind = exactVersion;
version = 11.1.0;
version = 11.2.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
8 changes: 4 additions & 4 deletions ios/CCC.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "9118aca998dbe2ceac45d64b21a91c6376928df7",
"version" : "11.1.0"
"revision" : "1fc52ab0e172e7c5a961f975a76c2611f4f22852",
"version" : "11.2.0"
}
},
{
Expand Down Expand Up @@ -122,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/googleads/swift-package-manager-google-mobile-ads.git",
"state" : {
"revision" : "ee80d8b9fb9c110c35ff0af56cfc672eee4b515e",
"version" : "11.8.0"
"revision" : "1e60477cbc4c4868ec8414524f8cd163132753ff",
"version" : "11.10.0"
}
},
{
Expand Down
125 changes: 124 additions & 1 deletion ios/CCC/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@ import FirebaseCore
import GoogleMobileAds
import Provider
import SwiftUI
import BackgroundTasks
import NavigationStack

var logger: KermitLogger = {
return LoggerKt.doInitLogger()
}()

@main
struct Application: App {
@Environment(\.scenePhase) private var scenePhase
@State private var isWatcherAlertShown = false
@StateObject var observable = ObservableSEEDViewModel<
MainState,
MainEffect,
MainEvent,
MainData,
MainViewModel
>()
private let notificationManager = NotificationManager()
private let backgroundRepository: BackgroundRepository = koin.get()

private let taskID = "com.oztechan.ccc.CCC.fetch"
private let earliestTaskPeriod: Double = 1 * 60 * 60 // 1 hour

init() {
FirebaseApp.configure()

Expand All @@ -34,9 +51,115 @@ struct Application: App {
))
UICollectionView.appearance().backgroundColor = .clear
UITableView.appearance().backgroundColor = .clear

registerAppRefresh()
}

var body: some Scene {
MainScene()
WindowGroup {
NavigationStackView(
transitionType: .default,
easing: Animation.easeInOut
) {
if observable.state.shouldOnboardUser {
IntroSlideRootView()
} else {
CalculatorRootView()
}
}.onAppear {
observable.startObserving()
}.onDisappear {
observable.stopObserving()
}.onReceive(observable.effect) {
onEffect(effect: $0)
}.alert(isPresented: $isWatcherAlertShown) {
AlertView(
title: String(\.txt_watcher_alert_title),
message: String(\.txt_watcher_alert_sub_title),
buttonText: String(\.txt_ok)
)
}
}.onChange(of: scenePhase) { phase in
onScenePhaseChange(phase: phase)
}
}

private func onScenePhaseChange(phase: ScenePhase) {
logger.i(message: { "Application onChange scenePhase \(phase)" })

switch phase {
case .active:
observable.event.onAppForeground()
case .inactive:
// only when come from active, since it visits inactive while coming from background
if scenePhase == .active {
observable.event.onAppBackground()
}
case .background:
scheduleAppRefresh()
@unknown default:
logger.w(message: { "Application unknown scenePhase \(phase)" })
}
}

private func onEffect(effect: MainEffect) {
logger.i(message: { "Application onEffect \(effect.description)" })
switch effect {
case is MainEffect.ShowInterstitialAd:
InterstitialAd().show()
default:
logger.i(message: { "Application unknown effect" })
}
}

private func scheduleAppRefresh() {
logger.i(message: { "Application scheduleAppRefresh" })

let request = BGAppRefreshTaskRequest(identifier: taskID)
request.earliestBeginDate = Date(timeIntervalSinceNow: earliestTaskPeriod)

do {
try BGTaskScheduler.shared.submit(request)
} catch {
logger.i(message: { "Application scheduleAppRefresh Could not schedule app refresh: \(error)" })
}
}

private func registerAppRefresh() {
logger.i(message: { "Application registerAppRefresh" })

BGTaskScheduler.shared.cancelAllTaskRequests()

BGTaskScheduler.shared.register(forTaskWithIdentifier: taskID, using: nil) { task in
// swiftlint:disable:next force_cast
handleAppRefresh(task: task as! BGAppRefreshTask)

task.expirationHandler = {
logger.i(message: { "Application registerAppRefresh BackgroundTask Expired" })

task.setTaskCompleted(success: false)
}
}
}

private func handleAppRefresh(task: BGAppRefreshTask) {
logger.i(message: { "Application handleAppRefresh" })

scheduleAppRefresh()

if backgroundRepository.shouldSendNotification() {
if scenePhase == .background {
self.notificationManager.sendNotification(
title: String(\.txt_watcher_alert_title),
body: String(\.txt_watcher_alert_sub_title)
)
} else {
isWatcherAlertShown.toggle()
}

task.setTaskCompleted(success: true)
} else {
task.setTaskCompleted(success: true)
}
}
}
146 changes: 0 additions & 146 deletions ios/CCC/UI/Main/MainScene.swift

This file was deleted.

4 changes: 2 additions & 2 deletions ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/firebase/firebase-ios-sdk",
from: "11.1.0"
from: "11.2.0"
),
.package(
url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git",
from: "11.8.0"
from: "11.10.0"
),
.package(
url: "https://github.com/exyte/PopupView.git",
Expand Down

0 comments on commit 5e19bbd

Please sign in to comment.