Skip to content

Commit

Permalink
updates after release 7.0.0 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile-ads-github authored Apr 4, 2024
1 parent f38ccbb commit 68e10c9
Show file tree
Hide file tree
Showing 36 changed files with 586 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EULA is available at [EULA website] [LICENSE]
##### Add YandexMobileAds SDK:

```sh
implementation 'com.yandex.android:mobileads:6.4.1'
implementation 'com.yandex.android:mobileads:7.0.0'
```

##### Or you can use our library with all available mediations:
Expand All @@ -31,7 +31,7 @@ implementation 'com.yandex.android:mobileads:6.4.1'

dependencies {
...
implementation 'com.yandex.android:mobileads-mediation:6.4.1.0'
implementation 'com.yandex.android:mobileads-mediation:7.0.0.0'
}
```

Expand All @@ -57,7 +57,7 @@ allprojects {

// Chartboost
maven { url 'https://cboost.jfrog.io/artifactory/chartboost-ads/' }

// AppNext
maven { url 'https://dl.appnext.com/' }
}
Expand Down
2 changes: 1 addition & 1 deletion ThirdPartyMediationAdapterTemplate/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ android {
}

dependencies {
implementation("com.yandex.android:mobileads:6.4.1")
implementation("com.yandex.android:mobileads:7.0.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class YandexBaseAdapter: MediationBaseAdapter {
/**
* Yandex SDK version can be obtained that way.
*/
override fun getSDKVersionInfo(): String = MobileAds.getLibraryVersion()
override fun getSDKVersionInfo(): String = MobileAds.libraryVersion

/**
* Method for updating privacy policies.
Expand Down
2 changes: 1 addition & 1 deletion YandexMobileAdsExample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ android {

dependencies {
// Yandex Mobile Ads SDK with mediation adapters
implementation("com.yandex.android:mobileads-mediation:6.4.1.0")
implementation("com.yandex.android:mobileads-mediation:7.0.0.0")

implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-ktx:1.6.1")
Expand Down
3 changes: 3 additions & 0 deletions YandexMobileAdsExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<activity
android:name="com.yandex.ads.sample.adunits.StickyBannerAdActivity"
android:exported="false" />
<activity
android:name="com.yandex.ads.sample.adunits.FeedActivity"
android:exported="false" />
<activity android:name=".adunits.AppOpenAdActivity" android:exported="false"/>
<activity
android:name=".HomeActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.yandex.ads.sample.databinding.ActivityHomeBinding
import com.yandex.ads.sample.adunits.AppOpenAdActivity
import com.yandex.ads.sample.adunits.CustomNativeAdActivity
import com.yandex.ads.sample.adunits.FeedActivity
import com.yandex.ads.sample.adunits.InlineBannerAdActivity
import com.yandex.ads.sample.adunits.InstreamAdBinderActivity
import com.yandex.ads.sample.adunits.InstreamAdInrollActivity
Expand All @@ -26,8 +26,11 @@ import com.yandex.ads.sample.adunits.NativeTemplateAdActivity
import com.yandex.ads.sample.adunits.RewardedAdActivity
import com.yandex.ads.sample.adunits.SimpleInstreamAdActivity
import com.yandex.ads.sample.adunits.StickyBannerAdActivity
import com.yandex.ads.sample.databinding.ActivityHomeBinding
import com.yandex.ads.sample.navigation.NavigationAdapter
import com.yandex.ads.sample.navigation.NavigationItem
import com.yandex.ads.sample.navigation.NavigationItem.NavigationType.ActivityNavigation
import com.yandex.ads.sample.navigation.NavigationItem.NavigationType.DebugPanelNavigation
import com.yandex.ads.sample.settings.PoliciesActivity

class HomeActivity : AppCompatActivity(R.layout.activity_home) {
Expand Down Expand Up @@ -67,58 +70,68 @@ class HomeActivity : AppCompatActivity(R.layout.activity_home) {
NavigationItem(
R.drawable.ic_outline_ad_units_24,
R.string.sticky_banner_title,
StickyBannerAdActivity::class.java,
ActivityNavigation(StickyBannerAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_aspect_ratio_24,
R.string.inline_banner_title,
InlineBannerAdActivity::class.java,
ActivityNavigation(InlineBannerAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_fullscreen_24,
R.string.interstitial_title,
InterstitialAdActivity::class.java,
ActivityNavigation(InterstitialAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_video_library_24,
R.string.rewarded_title,
RewardedAdActivity::class.java,
ActivityNavigation(RewardedAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_developer_mode_24,
R.string.native_template_title,
NativeTemplateAdActivity::class.java,
ActivityNavigation(NativeTemplateAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_developer_board_24,
R.string.native_custom_title,
CustomNativeAdActivity::class.java,
ActivityNavigation(CustomNativeAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_movie_24,
R.string.instream_simple_title,
SimpleInstreamAdActivity::class.java,
ActivityNavigation(SimpleInstreamAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_movie_filter_24,
R.string.instream_binder_title,
InstreamAdBinderActivity::class.java,
ActivityNavigation(InstreamAdBinderActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_video_settings_24,
R.string.instream_inroll_title,
InstreamAdInrollActivity::class.java,
ActivityNavigation(InstreamAdInrollActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_child_care_24,
R.string.policies,
PoliciesActivity::class.java,
ActivityNavigation(PoliciesActivity::class.java),
),
NavigationItem(
R.drawable.ic_full_coverage_24px,
R.drawable.ic_full_coverage_24,
R.string.appopenad_title,
AppOpenAdActivity::class.java,
ActivityNavigation(AppOpenAdActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_feed_24,
R.string.feed_title,
ActivityNavigation(FeedActivity::class.java),
),
NavigationItem(
R.drawable.ic_outline_instruments_24,
R.string.debug_panel,
DebugPanelNavigation
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* This file is a part of the Yandex Advertising Network
*
* Version for Android (C) 2024 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
*/

package com.yandex.ads.sample.adunits

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import com.yandex.ads.sample.R
import com.yandex.ads.sample.databinding.ActivityFeedBinding
import com.yandex.ads.sample.feed.ScreenContentDataAdapter
import com.yandex.ads.sample.feed.LogsDialog
import com.yandex.ads.sample.utils.Logger
import com.yandex.ads.sample.utils.ScreenUtil.screenWidth
import com.yandex.mobile.ads.common.AdRequestError
import com.yandex.mobile.ads.common.ImpressionData
import com.yandex.mobile.ads.feed.FeedAd
import com.yandex.mobile.ads.feed.FeedAdAdapter
import com.yandex.mobile.ads.feed.FeedAdAppearance
import com.yandex.mobile.ads.feed.FeedAdEventListener
import com.yandex.mobile.ads.feed.FeedAdLoadListener
import com.yandex.mobile.ads.feed.FeedAdRequestConfiguration
import java.lang.StringBuilder

class FeedActivity: AppCompatActivity() {

private val eventLogger = FeedAdEventLogger()
private val loadLogger = FeedAdLoadLogger()

private val logs: StringBuilder = StringBuilder()

private var feedAdAdapter: FeedAdAdapter? = null

private var screenContentDataAdapter: ScreenContentDataAdapter? = null
private var concatAdapter: ConcatAdapter? = null

private lateinit var binding: ActivityFeedBinding
private lateinit var feedAd: FeedAd
private lateinit var logsDialog: LogsDialog

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityFeedBinding.inflate(layoutInflater)
binding.setupUiBinding()
setContentView(binding.root)

setSupportActionBar(binding.toolbar)
binding.toolbar.setNavigationOnClickListener {
logs.clear()
onBackPressedDispatcher.onBackPressed()
}

logsDialog = LogsDialog(this)

setupFeedAd()
}

private fun setupFeedAd() {
val calculatedFeedCardWidth = calculateFeedCardWidth()
val feedAdAppearance = FeedAdAppearance(
cardWidth = calculatedFeedCardWidth,
cardCornerRadius = CARD_CORNER_RADIUS_DP
)
val feedAdRequestConfiguration = FeedAdRequestConfiguration.Builder(AD_UNIT_ID).build()

feedAd = FeedAd.Builder(this, feedAdRequestConfiguration, feedAdAppearance).build()
feedAd.loadListener = loadLogger
feedAd.preloadAd()
}

private fun showFeedAdStandalone() {
logs.clear()

feedAdAdapter = FeedAdAdapter(feedAd)
feedAdAdapter?.eventListener = eventLogger

binding.feedRecyclerView.layoutManager = LinearLayoutManager(this)
binding.feedRecyclerView.adapter = feedAdAdapter
}

private fun showFeedAdWithScreenContent() {
logs.clear()

feedAdAdapter = FeedAdAdapter(feedAd)
feedAdAdapter?.eventListener = eventLogger
screenContentDataAdapter = ScreenContentDataAdapter(List(SCREEN_CONTENT_ITEMS_COUNT) {
position -> position + 1
})

concatAdapter = ConcatAdapter(listOf(screenContentDataAdapter, feedAdAdapter))

binding.feedRecyclerView.layoutManager = LinearLayoutManager(this)
binding.feedRecyclerView.adapter = concatAdapter
}

private fun ActivityFeedBinding.setupUiBinding() {
showAdButton.setOnClickListener { showFeedAdStandalone() }
showConcatAdButton.setOnClickListener { showFeedAdWithScreenContent() }
}

private fun calculateFeedCardWidth(): Int {
return screenWidth - 2 * CARD_WIDTH_MARGIN_DP
}

private inner class FeedAdLoadLogger : FeedAdLoadListener {

override fun onAdFailedToLoad(error: AdRequestError) {
val message = "Feed on ad failed to load: $error"
log(message)
}

override fun onAdLoaded() {
val message = "Feed on ad loaded"
log(message)
}
}

private inner class FeedAdEventLogger : FeedAdEventListener {

override fun onAdClicked() {
val message = "Feed on ad clicked"
log(message)
}

override fun onImpression(impressionData: ImpressionData?) {
val message = "Feed on impression: $impressionData"
log(message)
}
}

private fun log(message: String) {
logs.append("$message\n")
logsDialog.setLogs(logs.toString())
Logger.debug(message)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.feed_toolbar_menu, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.action_button -> {
logsDialog.show(logs.toString())
return true
}
}

return super.onOptionsItemSelected(item)
}

private companion object {

private const val AD_UNIT_ID = "demo-feed-yandex"
private const val CARD_WIDTH_MARGIN_DP = 24
private const val CARD_CORNER_RADIUS_DP = 14.0
private const val SCREEN_CONTENT_ITEMS_COUNT = 15
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is a part of the Yandex Advertising Network
*
* Version for Android (C) 2024 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
*/

package com.yandex.ads.sample.feed

import android.app.AlertDialog
import android.content.Context
import com.yandex.ads.sample.R

class LogsDialog(context: Context) {

private val alertDialog: AlertDialog = AlertDialog.Builder(context)
.setPositiveButton(context.getString(R.string.ok_button)) { dialog, _ ->
dialog.dismiss()
}
.create()

fun show(logs: String) {
alertDialog.apply {
setTitle(context.getString(R.string.logs))
setMessage(logs)

show()
}
}

fun setLogs(logs: String) {
alertDialog.setMessage(logs)
}
}

Loading

0 comments on commit 68e10c9

Please sign in to comment.