diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml index fb1699e..4c6a5a8 100644 --- a/.github/workflows/bump.yml +++ b/.github/workflows/bump.yml @@ -18,3 +18,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }} WITH_V: false + DEFAULT_BUMP: patch diff --git a/Package.swift b/Package.swift index b4f9029..62daea7 100644 --- a/Package.swift +++ b/Package.swift @@ -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] = { [ @@ -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")), ] }() @@ -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( diff --git a/Sources/OversizeAdsKit/AdView.swift b/Sources/OversizeAdsKit/AdView.swift index 6a3480b..2d7d551 100644 --- a/Sources/OversizeAdsKit/AdView.swift +++ b/Sources/OversizeAdsKit/AdView.swift @@ -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 { @@ -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) @@ -46,7 +50,7 @@ public struct AdView: View { VStack(alignment: .leading, spacing: .xxxSmall) { HStack { - Text(app?.name ?? "") + Text(viewModel.appAd?.name ?? "") .subheadline(.bold) .onSurfaceHighEmphasisForegroundColor() @@ -56,7 +60,7 @@ public struct AdView: View { } } - Text(app?.title ?? "") + Text(viewModel.appAd?.title ?? "") .subheadline() .onSurfaceMediumEmphasisForegroundColor() } @@ -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() + } +} diff --git a/Sources/OversizeAdsKit/AdViewModel.swift b/Sources/OversizeAdsKit/AdViewModel.swift new file mode 100644 index 0000000..9bacddc --- /dev/null +++ b/Sources/OversizeAdsKit/AdViewModel.swift @@ -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 + } + } + +}