Skip to content

Commit

Permalink
Add OversizeNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Jun 30, 2023
1 parent 2cf0dca commit 51a54ad
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
WITH_V: false
DEFAULT_BUMP: patch
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let productionDependencies: [PackageDescription.Package.Dependency] = { [
.package(url: "https://github.com/oversizedev/OversizeComponents.git", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/oversizedev/OversizeResources.git", .upToNextMajor(from: "1.3.0")),
.package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")),
.package(url: "https://github.com/oversizedev/OversizeNetwork.git", .upToNextMajor(from: "0.1.0"))
] }()

let developmentDependencies: [PackageDescription.Package.Dependency] = { [
Expand All @@ -20,6 +21,7 @@ let developmentDependencies: [PackageDescription.Package.Dependency] = { [
.package(name: "OversizeCore", path: "../OversizeCore"),
.package(name: "OversizeComponents", path: "../OversizeComponents"),
.package(name: "OversizeResources", path: "../OversizeResources"),
.package(name: "OversizeNetwork", path: "../OversizeNetwork"),
.package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")),
] }()

Expand Down Expand Up @@ -61,8 +63,10 @@ let package = Package(
name: "OversizeAdsKit",
dependencies: [
"OversizeKit",
.product(name: "Factory", package: "Factory"),
.product(name: "OversizeUI", package: "OversizeUI"),
.product(name: "OversizeServices", package: "OversizeServices"),
.product(name: "OversizeNetwork", package: "OversizeNetwork"),
]
),
.target(
Expand Down
22 changes: 16 additions & 6 deletions Sources/OversizeAdsKit/AdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import OversizeUI
import SwiftUI

public struct AdView: View {

@Environment(\.isPremium) var isPremium: Bool

@StateObject var viewModel: AdViewModel

let app = Info.all?.apps.filter { $0.id != Info.app.appStoreID }.randomElement()
@State var isShowProduct = false
public init() {}
public init() {
_viewModel = StateObject(wrappedValue: AdViewModel())
}

public var body: some View {
if isPremium { EmptyView() } else {
Expand All @@ -22,7 +26,7 @@ public struct AdView: View {
isShowProduct.toggle()
} label: {
HStack(spacing: .zero) {
AsyncImage(url: URL(string: "\(Info.links?.company.cdnString ?? "")/assets/apps/\(app?.path ?? "")/icon.png"), content: {
AsyncImage(url: URL(string: "\(Info.links?.company.cdnString ?? "")/assets/apps/\(viewModel.appAd?.path ?? "")/icon.png"), content: {
$0
.resizable()
.frame(width: 64, height: 64)
Expand All @@ -46,7 +50,7 @@ public struct AdView: View {

VStack(alignment: .leading, spacing: .xxxSmall) {
HStack {
Text(app?.name ?? "")
Text(viewModel.appAd?.name ?? "")
.subheadline(.bold)
.onSurfaceHighEmphasisForegroundColor()

Expand All @@ -56,7 +60,7 @@ public struct AdView: View {
}
}

Text(app?.title ?? "")
Text(viewModel.appAd?.title ?? "")
.subheadline()
.onSurfaceMediumEmphasisForegroundColor()
}
Expand All @@ -75,10 +79,16 @@ public struct AdView: View {
}
}
.surfaceContentInsets(.xSmall)
.appStoreOverlay(isPresent: $isShowProduct, appId: app?.id ?? "")
//.appStoreOverlay(isPresent: $isShowProduct, appId: String(viewModel.appAd?.id ?? 0))
#else
EmptyView()
#endif
}
}
}

struct AdView_Previews: PreviewProvider {
static var previews: some View {
AdView()
}
}
27 changes: 27 additions & 0 deletions Sources/OversizeAdsKit/AdViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright © 2023 Alexander Romanov
// AdViewModel.swift, created on 30.06.2023
//

import SwiftUI
import OversizeNetwork
import Factory
import OversizeServices

@MainActor
public class AdViewModel: ObservableObject {
@Injected(\.networkService) var networkService

@Published var appAd: Components.Schemas.AdBanner?

public func fetchAdBanners() async {
let status = await networkService.fetchAdsBanners()
switch status {
case .success(let banners):
appAd = banners.filter { $0.id != Int(Info.app.appStoreID ?? "") }.randomElement()
case .failure:
break
}
}

}

0 comments on commit 51a54ad

Please sign in to comment.