Skip to content

Commit 718aa4a

Browse files
committed
feat: 이런저런 광고 추가
1 parent eefe195 commit 718aa4a

File tree

12 files changed

+327
-157
lines changed

12 files changed

+327
-157
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ dependencies {
187187
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3")
188188
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
189189
implementation(platform("com.google.firebase:firebase-bom:32.7.0"))
190+
implementation("com.google.android.gms:play-services-ads:22.0.0")
190191
implementation(project(":widget"))
191192
kapt("com.google.dagger:dagger-compiler:2.49")
192193
kapt("com.google.dagger:hilt-android-compiler:2.49")

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<profileable
3535
android:shell="true"
3636
tools:targetApi="29" />
37+
<meta-data
38+
android:name="com.google.android.gms.ads.APPLICATION_ID"
39+
android:value="ca-app-pub-7835112884789455~6071626275"/>
3740
<activity
3841
android:name=".MainActivity"
3942
android:exported="true"

app/src/main/java/com/no5ing/bbibbi/BBiBBiApplication.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import coil.ImageLoader
55
import coil.ImageLoaderFactory
66
import coil.disk.DiskCache
77
import coil.memory.MemoryCache
8+
import com.google.android.gms.ads.MobileAds
89
import com.google.firebase.Firebase
910
import com.google.firebase.FirebaseApp
1011
import com.google.firebase.appcheck.appCheck
@@ -31,6 +32,9 @@ class BBiBBiApplication : Application(), ImageLoaderFactory {
3132
PlayIntegrityAppCheckProviderFactory.getInstance(),
3233
)
3334
KakaoSdk.init(this, BuildConfig.kakaoApiKey)
35+
Thread {
36+
MobileAds.initialize(this)
37+
}.start()
3438
}
3539

3640
override fun newImageLoader(): ImageLoader {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.no5ing.bbibbi.presentation.component
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.foundation.layout.wrapContentSize
5+
import androidx.compose.material3.Text
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Alignment
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.platform.LocalInspectionMode
10+
import androidx.compose.ui.viewinterop.AndroidView
11+
import androidx.lifecycle.compose.LifecycleResumeEffect
12+
import com.google.android.gms.ads.AdView
13+
14+
/**
15+
* A composable function to display a banner advertisement.
16+
*
17+
* @param adView The banner [AdView].
18+
* @param modifier The modifier to apply to the banner ad.
19+
*/
20+
@Composable
21+
fun BannerAd(adView: AdView, modifier: Modifier = Modifier) {
22+
// Ad load does not work in preview mode because it requires a network connection.
23+
if (LocalInspectionMode.current) {
24+
Box { Text(text = "Google Mobile Ads preview banner.", modifier.align(Alignment.Center)) }
25+
return
26+
}
27+
28+
AndroidView(modifier = modifier.wrapContentSize(), factory = { adView })
29+
30+
// Pause and resume the AdView when the lifecycle is paused and resumed.
31+
LifecycleResumeEffect(adView) {
32+
adView.resume()
33+
onPauseOrDispose { adView.pause() }
34+
}
35+
}

app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/common/CameraView.kt

Lines changed: 89 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import androidx.compose.foundation.layout.Box
2121
import androidx.compose.foundation.layout.Column
2222
import androidx.compose.foundation.layout.Row
2323
import androidx.compose.foundation.layout.Spacer
24+
import androidx.compose.foundation.layout.WindowInsets
2425
import androidx.compose.foundation.layout.aspectRatio
2526
import androidx.compose.foundation.layout.fillMaxSize
2627
import androidx.compose.foundation.layout.fillMaxWidth
2728
import androidx.compose.foundation.layout.height
2829
import androidx.compose.foundation.layout.padding
2930
import androidx.compose.foundation.layout.size
31+
import androidx.compose.foundation.layout.systemBars
32+
import androidx.compose.foundation.layout.windowInsetsPadding
3033
import androidx.compose.foundation.shape.RoundedCornerShape
3134
import androidx.compose.material3.MaterialTheme
3235
import androidx.compose.runtime.Composable
@@ -50,11 +53,16 @@ import androidx.compose.ui.viewinterop.AndroidView
5053
import com.google.accompanist.permissions.ExperimentalPermissionsApi
5154
import com.google.accompanist.permissions.isGranted
5255
import com.google.accompanist.permissions.rememberPermissionState
56+
import com.google.android.gms.ads.AdRequest
57+
import com.google.android.gms.ads.AdSize
58+
import com.google.android.gms.ads.AdView
5359
import com.no5ing.bbibbi.R
5460
import com.no5ing.bbibbi.presentation.component.BBiBBiSurface
61+
import com.no5ing.bbibbi.presentation.component.BannerAd
5562
import com.no5ing.bbibbi.presentation.component.ClosableTopBar
5663
import com.no5ing.bbibbi.presentation.component.button.CameraCaptureButton
5764
import com.no5ing.bbibbi.presentation.theme.bbibbiScheme
65+
import com.no5ing.bbibbi.util.getAdView
5866
import com.no5ing.bbibbi.util.getCameraProvider
5967
import com.no5ing.bbibbi.util.takePhotoWithImage
6068
import kotlinx.coroutines.launch
@@ -122,6 +130,7 @@ fun CameraView(
122130
preview.setSurfaceProvider(previewView.surfaceProvider)
123131
}
124132

133+
val adView = getAdView()
125134
val zoomValue: Float by animateFloatAsState(
126135
targetValue = if (isZoomed) 0.5f else 0.0f,
127136
animationSpec = tween(
@@ -156,91 +165,98 @@ fun CameraView(
156165
Column(
157166
modifier = Modifier
158167
.padding(vertical = 10.dp)
159-
.fillMaxWidth()
168+
.fillMaxWidth(),
169+
verticalArrangement = Arrangement.SpaceBetween,
160170
) {
161-
ClosableTopBar(
162-
onDispose = onDispose,
163-
title = stringResource(id = R.string.camera_title),
164-
)
165-
Spacer(modifier = Modifier.height(48.dp))
166-
Box {
167-
AndroidView(
168-
{ previewView },
169-
modifier = Modifier
170-
.aspectRatio(1.0f)
171-
.fillMaxWidth()
172-
.clip(RoundedCornerShape(48.dp))
173-
.background(MaterialTheme.bbibbiScheme.backgroundHover),
171+
Column {
172+
ClosableTopBar(
173+
onDispose = onDispose,
174+
title = stringResource(id = R.string.camera_title),
174175
)
175-
Box(
176-
modifier = Modifier
177-
.aspectRatio(1.0f)
178-
.fillMaxWidth()
179-
.padding(bottom = 20.dp),
180-
contentAlignment = Alignment.BottomCenter
176+
Spacer(modifier = Modifier.height(48.dp))
177+
Box {
178+
AndroidView(
179+
{ previewView },
180+
modifier = Modifier
181+
.aspectRatio(1.0f)
182+
.fillMaxWidth()
183+
.clip(RoundedCornerShape(48.dp))
184+
.background(MaterialTheme.bbibbiScheme.backgroundHover),
185+
)
186+
Box(
187+
modifier = Modifier
188+
.aspectRatio(1.0f)
189+
.fillMaxWidth()
190+
.padding(bottom = 20.dp),
191+
contentAlignment = Alignment.BottomCenter
192+
) {
193+
Image(
194+
painter = painterResource(id = R.drawable.zoom_button),
195+
contentDescription = null,
196+
modifier = Modifier
197+
.size(43.dp)
198+
.clickable {
199+
isZoomed = !isZoomed
200+
}
201+
)
202+
203+
}
204+
}
205+
206+
Spacer(modifier = Modifier.height(36.dp))
207+
Row(
208+
modifier = Modifier.fillMaxWidth(),
209+
horizontalArrangement = Arrangement.SpaceAround,
210+
verticalAlignment = Alignment.CenterVertically,
181211
) {
182212
Image(
183-
painter = painterResource(id = R.drawable.zoom_button),
184-
contentDescription = null,
213+
painter = painterResource(R.drawable.toggle_flash_button),
214+
contentDescription = null, // 필수 param
185215
modifier = Modifier
186-
.size(43.dp)
216+
.size(48.dp)
187217
.clickable {
188-
isZoomed = !isZoomed
218+
torchState.value = !torchState.value
219+
cameraState.value?.cameraControl?.enableTorch(torchState.value)
220+
}
221+
)
222+
CameraCaptureButton(
223+
onClick = {
224+
if (isCapturing) return@CameraCaptureButton
225+
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
226+
coroutineScope.launch {
227+
isCapturing = true
228+
val uri = captureState.value.takePhotoWithImage(
229+
context,
230+
requiredFlip = cameraDirection.value == CameraSelector.DEFAULT_FRONT_CAMERA
231+
)
232+
isCapturing = false
233+
onImageCaptured(uri)
189234
}
235+
},
236+
isCapturing = isCapturing,
190237
)
238+
Image(
239+
painter = painterResource(R.drawable.rorate_button),
240+
contentDescription = null, // 필수 param
241+
modifier = Modifier
242+
.size(48.dp)
243+
.clickable {
244+
cameraDirection.value = run {
245+
if (cameraDirection.value == CameraSelector.DEFAULT_BACK_CAMERA) {
246+
CameraSelector.DEFAULT_FRONT_CAMERA
247+
} else {
248+
CameraSelector.DEFAULT_BACK_CAMERA
249+
}
250+
}
191251

252+
}
253+
)
192254
}
193255
}
194-
195-
Spacer(modifier = Modifier.height(36.dp))
196-
Row(
197-
modifier = Modifier.fillMaxWidth(),
198-
horizontalArrangement = Arrangement.SpaceAround,
199-
verticalAlignment = Alignment.CenterVertically,
200-
) {
201-
Image(
202-
painter = painterResource(R.drawable.toggle_flash_button),
203-
contentDescription = null, // 필수 param
204-
modifier = Modifier
205-
.size(48.dp)
206-
.clickable {
207-
torchState.value = !torchState.value
208-
cameraState.value?.cameraControl?.enableTorch(torchState.value)
209-
}
210-
)
211-
CameraCaptureButton(
212-
onClick = {
213-
if (isCapturing) return@CameraCaptureButton
214-
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
215-
coroutineScope.launch {
216-
isCapturing = true
217-
val uri = captureState.value.takePhotoWithImage(
218-
context,
219-
requiredFlip = cameraDirection.value == CameraSelector.DEFAULT_FRONT_CAMERA
220-
)
221-
isCapturing = false
222-
onImageCaptured(uri)
223-
}
224-
},
225-
isCapturing = isCapturing,
226-
)
227-
Image(
228-
painter = painterResource(R.drawable.rorate_button),
229-
contentDescription = null, // 필수 param
230-
modifier = Modifier
231-
.size(48.dp)
232-
.clickable {
233-
cameraDirection.value = run {
234-
if (cameraDirection.value == CameraSelector.DEFAULT_BACK_CAMERA) {
235-
CameraSelector.DEFAULT_FRONT_CAMERA
236-
} else {
237-
CameraSelector.DEFAULT_BACK_CAMERA
238-
}
239-
}
240-
241-
}
242-
)
256+
Box(modifier = Modifier.fillMaxWidth().windowInsetsPadding(WindowInsets.systemBars)) {
257+
BannerAd(adView = adView, modifier = Modifier.fillMaxWidth())
243258
}
259+
244260
}
245261

246262
}

app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/MainCalendarPage.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import androidx.compose.foundation.layout.Box
88
import androidx.compose.foundation.layout.Column
99
import androidx.compose.foundation.layout.Row
1010
import androidx.compose.foundation.layout.Spacer
11+
import androidx.compose.foundation.layout.WindowInsets
1112
import androidx.compose.foundation.layout.aspectRatio
1213
import androidx.compose.foundation.layout.fillMaxSize
1314
import androidx.compose.foundation.layout.fillMaxWidth
1415
import androidx.compose.foundation.layout.height
1516
import androidx.compose.foundation.layout.offset
1617
import androidx.compose.foundation.layout.padding
1718
import androidx.compose.foundation.layout.size
19+
import androidx.compose.foundation.layout.systemBars
20+
import androidx.compose.foundation.layout.windowInsetsPadding
1821
import androidx.compose.foundation.layout.wrapContentHeight
1922
import androidx.compose.foundation.shape.RoundedCornerShape
2023
import androidx.compose.material.Icon
@@ -43,13 +46,15 @@ import com.no5ing.bbibbi.data.model.family.FamilySummary
4346
import com.no5ing.bbibbi.data.model.post.CalendarBanner
4447
import com.no5ing.bbibbi.data.repository.Arguments
4548
import com.no5ing.bbibbi.presentation.component.BBiBBiSurface
49+
import com.no5ing.bbibbi.presentation.component.BannerAd
4650
import com.no5ing.bbibbi.presentation.component.DisposableTopBar
4751
import com.no5ing.bbibbi.presentation.feature.view_model.post.CalendarMonthViewModel
4852
import com.no5ing.bbibbi.presentation.feature.view_model.post.GetFamilySummaryViewModel
4953
import com.no5ing.bbibbi.presentation.feature.view_model.post.MonthlyStatisticsViewModel
5054
import com.no5ing.bbibbi.presentation.theme.bbibbiScheme
5155
import com.no5ing.bbibbi.presentation.theme.bbibbiTypo
5256
import com.no5ing.bbibbi.util.formatYearMonth
57+
import com.no5ing.bbibbi.util.getAdView
5358
import com.no5ing.bbibbi.util.getScreenSize
5459
import com.skydoves.balloon.ArrowPositionRules
5560
import com.skydoves.balloon.BalloonAnimation
@@ -189,8 +194,11 @@ fun MainCalendarPage(
189194
modifier = Modifier
190195
.padding(horizontal = 20.dp)
191196
.fillMaxWidth()
192-
.background(MaterialTheme.bbibbiScheme.backgroundSecondary, RoundedCornerShape(24.dp))
193-
.aspectRatio(335.0f/220)
197+
.background(
198+
MaterialTheme.bbibbiScheme.backgroundSecondary,
199+
RoundedCornerShape(24.dp)
200+
)
201+
.aspectRatio(335.0f / 220)
194202
)
195203
}
196204
Spacer(modifier = Modifier.height(24.dp))

app/src/main/java/com/no5ing/bbibbi/presentation/feature/view/main/calendar/detail/CalendarDetailPage.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import androidx.compose.foundation.layout.Box
1111
import androidx.compose.foundation.layout.Column
1212
import androidx.compose.foundation.layout.Row
1313
import androidx.compose.foundation.layout.Spacer
14+
import androidx.compose.foundation.layout.WindowInsets
1415
import androidx.compose.foundation.layout.aspectRatio
1516
import androidx.compose.foundation.layout.fillMaxSize
1617
import androidx.compose.foundation.layout.fillMaxWidth
1718
import androidx.compose.foundation.layout.height
1819
import androidx.compose.foundation.layout.padding
20+
import androidx.compose.foundation.layout.systemBars
1921
import androidx.compose.foundation.layout.width
22+
import androidx.compose.foundation.layout.windowInsetsPadding
2023
import androidx.compose.foundation.pager.HorizontalPager
2124
import androidx.compose.foundation.pager.rememberPagerState
2225
import androidx.compose.material3.MaterialTheme
@@ -48,6 +51,7 @@ import com.no5ing.bbibbi.R
4851
import com.no5ing.bbibbi.data.model.member.Member
4952
import com.no5ing.bbibbi.data.repository.Arguments
5053
import com.no5ing.bbibbi.presentation.component.BBiBBiSurface
54+
import com.no5ing.bbibbi.presentation.component.BannerAd
5155
import com.no5ing.bbibbi.presentation.component.CircleProfileImage
5256
import com.no5ing.bbibbi.presentation.component.DisposableTopBar
5357
import com.no5ing.bbibbi.presentation.component.showSnackBarWithDismiss
@@ -67,6 +71,7 @@ import com.no5ing.bbibbi.util.LocalSessionState
6771
import com.no5ing.bbibbi.util.LocalSnackbarHostState
6872
import com.no5ing.bbibbi.util.asyncImagePainter
6973
import com.no5ing.bbibbi.util.formatYearMonth
74+
import com.no5ing.bbibbi.util.getAdView
7075
import com.no5ing.bbibbi.util.localResources
7176
import com.no5ing.bbibbi.util.weekDates
7277
import io.github.boguszpawlowski.composecalendar.SelectableWeekCalendar
@@ -171,6 +176,7 @@ fun CalendarDetailPage(
171176
}
172177

173178
val currentPostState by familyPostsViewModel.uiState.collectAsState()
179+
val adView = getAdView()
174180

175181

176182
val pagerState = key(currentPostState) {
@@ -348,7 +354,18 @@ fun CalendarDetailPage(
348354
}
349355
}
350356
}
351-
357+
Column(
358+
modifier = Modifier.fillMaxSize(),
359+
verticalArrangement = Arrangement.Bottom
360+
) {
361+
Box(
362+
contentAlignment = Alignment.BottomCenter,
363+
modifier = Modifier
364+
.fillMaxWidth()
365+
.windowInsetsPadding(WindowInsets.systemBars)) {
366+
BannerAd(adView = adView, modifier = Modifier.fillMaxWidth())
367+
}
368+
}
352369
}
353370

354371
}

0 commit comments

Comments
 (0)