Skip to content

Commit

Permalink
5472
Browse files Browse the repository at this point in the history
  • Loading branch information
Velkonost committed Jan 27, 2024
1 parent f423ea0 commit 6551141
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import java.util.Locale

@Composable
fun AdView(
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
slotId: Int
) {


PrimaryBox(
modifier = modifier
.padding(PaddingValues(horizontal = 20.dp))
Expand Down Expand Up @@ -74,7 +74,7 @@ fun AdView(
.clip(MaterialTheme.shapes.small),
factory = {
val view = MyTargetView(it)
view.setSlotId(1494645)
view.setSlotId(slotId)
view.setAdSize(AdSize.ADSIZE_300x250)

view.listener = object : MyTargetView.MyTargetViewListener {
Expand All @@ -96,55 +96,10 @@ fun AdView(
}
}


view.load()
view
}
)


// AndroidView(
// modifier = modifier
// .clip(MaterialTheme.shapes.medium),
// factory = {
// BannerAdView(it)
// },
// update = {
// it.apply {
// setAdSize(adSize)
// setAdUnitId("R-M-5517748-1")
// setBannerAdEventListener(object : BannerAdEventListener {
// override fun onAdLoaded() {
// }
//
// override fun onAdFailedToLoad(adRequestError: AdRequestError) {
// }
//
// override fun onAdClicked() {
// // Called when a click is recorded for an ad.
// }
//
// override fun onLeftApplication() {
// // Called when user is about to leave application (e.g., to go to the browser), as a result of clicking on the ad.
// }
//
// override fun onReturnedToApplication() {
// // Called when user returned to application after click.
// }
//
// override fun onImpression(impressionData: ImpressionData?) {
// // Called when an impression is recorded for an ad.
// }
// })
// loadAd(
// AdRequest.Builder()
// // Methods in the AdRequest.Builder class can be used here to specify individual options settings.
// .build()
// )
// }
//
// }
// )
Spacer(modifier.weight(1f))
}
Spacer(modifier.weight(1f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fun SocialScreen(
generalFeedState = state.generalFeed,
areasFeedState = state.areasFeed,
adPosition = state.adPosition,
adSlotId = state.adId.toInt(),
noteClick = {
viewModel.dispatch(SocialAction.NoteClick(it))
},
Expand Down Expand Up @@ -135,6 +136,7 @@ fun SocialScreenContent(
generalFeedState: FeedViewState,
areasFeedState: FeedViewState,
adPosition: Int,
adSlotId: Int,
noteClick: (Note) -> Unit,
noteLikeClick: (Note) -> Unit,
generalFeedLoadNextPage: () -> Unit,
Expand All @@ -156,6 +158,7 @@ fun SocialScreenContent(
emptyText = stringResource(resource = SharedR.strings.placeholder_social_all),
items = generalFeedState.items,
adPosition = adPosition,
adSlotId = adSlotId,
itemClick = noteClick,
itemLikeClick = noteLikeClick,
onBottomReach = generalFeedLoadNextPage,
Expand All @@ -169,6 +172,7 @@ fun SocialScreenContent(
emptyText = stringResource(resource = SharedR.strings.placeholder_social_areas),
items = areasFeedState.items,
adPosition = adPosition,
adSlotId = adSlotId,
itemClick = noteClick,
itemLikeClick = noteLikeClick,
onBottomReach = areasFeedLoadNextPage,
Expand All @@ -188,6 +192,7 @@ fun SocialFeedView(
isRefreshing: Boolean,
items: List<Note>,
adPosition: Int,
adSlotId: Int,
itemClick: (Note) -> Unit,
itemLikeClick: (Note) -> Unit,
onBottomReach: () -> Unit,
Expand Down Expand Up @@ -226,7 +231,7 @@ fun SocialFeedView(
)

if (index % adPosition == 0 && index != 0) {
AdView()
AdView(slotId = adSlotId)
}
}

Expand Down
Binary file not shown.
13 changes: 2 additions & 11 deletions iosApp/iosApp/Core/Components/ad/AdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SharedSDK
import YandexMobileAds

struct AdView: View {

var body: some View {
PrimaryBox(
padding: .init(top: .zero, leading: .zero, bottom: .zero, trailing: .zero)
Expand Down Expand Up @@ -44,15 +45,13 @@ struct AdBannerView: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: InlineBannerViewController, context: Context) {
// Updates the state of the specified view controller with new information from SwiftUI.
}


}

final class InlineBannerViewController: UIViewController {
private lazy var adView: YMAAdView = {
let adSize = YMABannerAdSize.inlineSize(withWidth: UIScreen.screenWidth - 40, maxHeight: 300)

let adView = YMAAdView(adUnitID: "R-M-5517759-1", adSize: adSize)
let adView = YMAAdView(adUnitID: UtilBuildKonfig.shared.AD_ID, adSize: adSize)
adView.delegate = self
adView.translatesAutoresizingMaskIntoConstraints = false
return adView
Expand All @@ -62,14 +61,6 @@ final class InlineBannerViewController: UIViewController {
adView.loadAd()
view.addSubview(adView)
}

func showAd() {

// NSLayoutConstraint.activate([
// adView.topAnchor.constraint(equalTo: loadButton.bottomAnchor, constant: 100),
// adView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
// ])
}
}

extension InlineBannerViewController: YMAAdViewDelegate {
Expand Down
7 changes: 4 additions & 3 deletions shared/core/util/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("DSL_SCOPE_VIOLATION")

import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.INT
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
import com.velkonost.getbetter.SHARED_PACKAGE
import com.velkonost.getbetter.join

Expand Down Expand Up @@ -42,18 +43,18 @@ buildkonfig {
exposeObjectWithName = "UtilBuildKonfig"

defaultConfigs {
buildConfigField(INT, "AD_ID", "")
buildConfigField(STRING, "AD_ID", "")
buildConfigField(INT, "RUSTORE_AD_ID", 1494678.toString())
}

targetConfigs {
create("android") {
buildConfigField(INT, "AD_ID", 1494645.toString())
buildConfigField(STRING, "AD_ID", 1494645.toString())
buildConfigField(INT, "RUSTORE_AD_ID", 1494678.toString())
}

create("ios") {
buildConfigField(INT, "AD_ID", 5517759.toString())
buildConfigField(STRING, "AD_ID", "R-M-5517759-1")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.velkonost.getbetter.shared.core.util

import com.velkonost.getbetter.BuildKonfig
import com.velkonost.getbetter.shared.resources.SharedR
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class SocialViewState(
val generalFeed: FeedViewState = FeedViewState(),
val areasFeed: FeedViewState = FeedViewState(),
val adPosition: Int = (6..10).random(),
val adId: Int = UtilBuildKonfig.AD_ID//UtilBuildKonfig.RUSTORE_AD_ID
val adId: String = UtilBuildKonfig.AD_ID//UtilBuildKonfig.RUSTORE_AD_ID
) : UIContract.State

data class FeedViewState(
Expand Down

0 comments on commit 6551141

Please sign in to comment.