-
Notifications
You must be signed in to change notification settings - Fork 0
feat: AdMob 배너 광고 기능 추가 #115
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.kuit.findu.presentation.ui.common | ||
|
|
||
| import android.os.Bundle | ||
| import android.util.Log | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.viewinterop.AndroidView | ||
| import com.google.android.gms.ads.AdListener | ||
| import com.google.android.gms.ads.AdRequest | ||
| import com.google.android.gms.ads.AdSize | ||
| import com.google.android.gms.ads.AdView | ||
| import com.google.android.gms.ads.LoadAdError | ||
| import com.google.firebase.analytics.FirebaseAnalytics | ||
| import com.kuit.findu.BuildConfig | ||
| import com.kuit.findu.analytics.AnalyticsEvent | ||
|
|
||
| private val AD_UNIT_ID = BuildConfig.ADMOB_BANNER_ID | ||
|
|
||
| @Composable | ||
| fun AdBanner( | ||
| modifier: Modifier = Modifier, | ||
| adLocation: String = "unknown" | ||
| ) { | ||
| AndroidView( | ||
| modifier = modifier.fillMaxWidth(), | ||
| factory = { context -> | ||
| val analytics = FirebaseAnalytics.getInstance(context) | ||
|
|
||
| AdView(context).apply { | ||
| setAdSize(AdSize.BANNER) | ||
| adUnitId = AD_UNIT_ID | ||
| adListener = object : AdListener() { | ||
| override fun onAdClicked() { | ||
| analytics.logEvent(AnalyticsEvent.AD_CLICK, Bundle().apply { | ||
| putString(AnalyticsEvent.AD_LOCATION, adLocation) | ||
| }) | ||
| } | ||
|
|
||
| override fun onAdImpression() { | ||
| analytics.logEvent(AnalyticsEvent.AD_IMPRESSION, Bundle().apply { | ||
| putString(AnalyticsEvent.AD_LOCATION, adLocation) | ||
| }) | ||
| } | ||
|
|
||
| override fun onAdFailedToLoad(error: LoadAdError) { | ||
| Log.e("AdBanner", "광고 로드 실패: ${error.code} - ${error.message}") | ||
| } | ||
|
|
||
| override fun onAdLoaded() { | ||
| Log.d("AdBanner", "광고 로드 성공") | ||
| } | ||
| } | ||
| loadAd(AdRequest.Builder().build()) | ||
| } | ||
|
Comment on lines
+3
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: For an AdMob
Compose example (recommended pattern)`@Composable`
fun BannerAd(
adUnitId: String,
adSize: AdSize,
modifier: Modifier = Modifier,
) {
val lifecycleOwner = LocalLifecycleOwner.current
AndroidView(
modifier = modifier,
factory = { context ->
AdView(context).apply {
setAdUnitId(adUnitId)
setAdSize(adSize)
loadAd(AdRequest.Builder().build())
}
},
update = { adView ->
// Optional: attach lifecycle-driven pause/resume
val lifecycle = lifecycleOwner.lifecycle
val observer = LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> adView.resume()
Lifecycle.Event.ON_PAUSE -> adView.pause()
else -> Unit
}
}
// Ensure we don't accumulate observers across recompositions
adView.setTag(R.id.adview_lifecycle_observer, observer)
lifecycle.addObserver(observer)
},
onReset = { adView ->
// If you opt into reuse, reset transient state here (don’t destroy).
adView.pause()
},
onRelease = { adView ->
// Permanent removal: free resources here.
adView.destroy()
}
)
}Key point: use Citations:
🌐 Web query:
💡 Result: In What runs when
|
||
| } | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -462,6 +462,13 @@ | |
|
|
||
| </ScrollView> | ||
|
|
||
| <com.google.android.gms.ads.AdView | ||
| android:id="@+id/ad_view_my" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| app:adSize="BANNER" | ||
| app:adUnitId="ca-app-pub-7675272869453438/1213424875" | ||
| app:layout_constraintBottom_toBottomOf="parent" /> | ||
|
Comment on lines
+465
to
+471
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스크롤 영역과 광고가 겹칠 수 있습니다. 현재 ScrollView가 parent 하단까지 차지하고 AdView도 하단에 붙어 있어서, 콘텐츠가 광고 뒤로 가려질 수 있어요. ScrollView의 하단 제약을 AdView 상단으로 옮겨 주세요. 🛠️ 수정 제안- <ScrollView
+ <ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
- app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintBottom_toTopOf="@id/ad_view_my"
app:layout_constraintTop_toBottomOf="@id/cl_my_top_container"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="72dp">🤖 Prompt for AI Agents |
||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: FindYou-Kuit/FindYou-Android
Length of output: 2875
🌐 Web query:
Google Play Services Ads SDK latest version 2025 Android💡 Result:
The latest Google Play services Ads SDK artifact (
com.google.android.gms:play-services-ads) released in 2025 is24.9.0(released 2025‑12‑11). [1][2]Gradle:
implementation "com.google.android.gms:play-services-ads:24.9.0"[2]
AdMob SDK 버전을 업데이트하고 버전 카탈로그 사용을 권장해요.
AdMob SDK 버전 23.1.0은 현재 많이 구버전이고, 최신 버전은 24.9.0입니다. 또한 다른 의존성들은
libs.*버전 카탈로그를 사용하고 있는데, AdMob SDK만 하드코딩된 문자열로 되어 있어서 일관성 차원에서도 개선이 필요해요.🔧 제안하는 수정
gradle/libs.versions.toml에 추가:그 후
app/build.gradle.kts에서:🤖 Prompt for AI Agents