Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: BannerView #21

Merged
merged 12 commits into from
Sep 16, 2024
3 changes: 3 additions & 0 deletions TopsortAnalytics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ dependencies {
//JodaTime
implementation group: 'joda-time', name: 'joda-time', version: '2.12.5'

// Image Loading for Banners
implementation 'io.coil-kt:coil:2.7.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20200518'
testImplementation 'org.assertj:assertj-core:3.26.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.topsort.analytics.banners

import android.content.Context
import android.widget.ImageView
import coil.load
import com.topsort.analytics.Analytics
import com.topsort.analytics.model.Placement
import com.topsort.analytics.model.auctions.EntityType

class BannerView(
context: Context,
config: BannerConfig,
path: String,
location: String,
clickCallback: (String, EntityType) -> Unit
) : ImageView(context) {
init {
val result = runBannerAuction(config)
if (result != null) {
this.load(result.url)
this.viewTreeObserver.addOnGlobalLayoutListener {
Analytics.reportImpressionPromoted(
resolvedBidId = result.resolvedBidId,
placement = Placement(path = path, location = location)
)
}
this.setOnClickListener {
Analytics.reportClickPromoted(
resolvedBidId = result.resolvedBidId,
placement = Placement(path = path, location = location)
)
clickCallback(result.id, result.type)
}
}
}
}