Skip to content

Commit 03b665d

Browse files
committed
feat: 나아돼 위에 이벤트 툴팁 추가
1 parent 59071a3 commit 03b665d

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

app/src/main/java/com/eatssu/android/presentation/MainActivity.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.eatssu.android.R
1818
import com.eatssu.android.databinding.ActivityMainBinding
1919
import com.eatssu.android.presentation.base.BaseActivity
2020
import com.eatssu.android.presentation.event.AnyoneButMeEventPopupController
21+
import com.eatssu.android.presentation.event.AnyoneButMeEventTooltipController
2122
import com.eatssu.android.presentation.login.LoginActivity
2223
import com.eatssu.android.presentation.mypage.MyPageViewModel
2324
import com.eatssu.android.presentation.mypage.userinfo.UserInfoActivity
@@ -48,6 +49,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(
4849
@Inject
4950
lateinit var anyoneButMeEventPopupController: AnyoneButMeEventPopupController
5051

52+
@Inject
53+
lateinit var anyoneButMeEventTooltipController: AnyoneButMeEventTooltipController
54+
5155
private val mainViewModel: MainViewModel by viewModels()
5256
private val myPageViewModel: MyPageViewModel by viewModels()
5357

@@ -58,6 +62,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(
5862
setupNoToolbar()
5963
setNavigation()
6064
bindEventPopup(showOnLaunch = savedInstanceState == null)
65+
bindEventTooltip()
6166

6267
checkAlarmPermission()
6368
collectState()
@@ -107,6 +112,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>(
107112
)
108113
}
109114

115+
private fun bindEventTooltip() {
116+
anyoneButMeEventTooltipController.bind(
117+
tooltipComposeView = binding.composeEventTooltip,
118+
bottomNavigationView = binding.bottomNaviBar
119+
)
120+
}
121+
110122
// set UI --
111123
private fun setupNoToolbar() {
112124
// 툴바 사용하지 않도록 설정
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.eatssu.android.presentation.event
2+
3+
import androidx.compose.foundation.Canvas
4+
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.layout.size
8+
import androidx.compose.foundation.shape.RoundedCornerShape
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Alignment
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.graphics.Path
14+
import androidx.compose.ui.text.TextStyle
15+
import androidx.compose.ui.text.font.FontWeight
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
18+
import androidx.compose.ui.unit.sp
19+
import com.eatssu.design_system.theme.EatssuTheme
20+
import com.eatssu.design_system.theme.Primary
21+
import com.eatssu.design_system.theme.White
22+
import com.eatssu.design_system.theme.pretendardMedium
23+
24+
@Composable
25+
fun AnyoneButMeEventTooltip(
26+
modifier: Modifier = Modifier,
27+
) {
28+
Column(
29+
modifier = modifier,
30+
horizontalAlignment = Alignment.CenterHorizontally
31+
) {
32+
Text(
33+
text = "EVENT!",
34+
modifier = Modifier
35+
.background(
36+
color = Primary,
37+
shape = RoundedCornerShape(999.dp)
38+
)
39+
.padding(horizontal = 12.dp, vertical = 4.dp),
40+
color = White,
41+
style = TextStyle(
42+
fontFamily = pretendardMedium,
43+
fontWeight = FontWeight.Medium,
44+
fontSize = 12.sp,
45+
lineHeight = 18.sp
46+
)
47+
)
48+
49+
Canvas(
50+
modifier = Modifier.size(width = 12.dp, height = 6.dp)
51+
) {
52+
drawPath(
53+
path = Path().apply {
54+
moveTo(0f, 0f)
55+
lineTo(size.width / 2f, size.height)
56+
lineTo(size.width, 0f)
57+
close()
58+
},
59+
color = Primary
60+
)
61+
}
62+
}
63+
}
64+
65+
@Preview(showBackground = true)
66+
@Composable
67+
private fun AnyoneButMeEventTooltipPreview() {
68+
EatssuTheme {
69+
AnyoneButMeEventTooltip()
70+
}
71+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.eatssu.android.presentation.event
2+
3+
import android.view.View
4+
import androidx.compose.ui.platform.ComposeView
5+
import androidx.compose.ui.platform.ViewCompositionStrategy
6+
import androidx.core.view.doOnLayout
7+
import com.eatssu.design_system.theme.EatssuTheme
8+
import com.google.android.material.bottomnavigation.BottomNavigationView
9+
import dagger.hilt.android.scopes.ActivityScoped
10+
import javax.inject.Inject
11+
12+
@ActivityScoped
13+
class AnyoneButMeEventTooltipController @Inject constructor() {
14+
private companion object {
15+
const val BOTTOM_NAVIGATION_ITEM_COUNT = 4
16+
const val ANYONE_BUT_ME_MENU_INDEX = 2
17+
}
18+
19+
private lateinit var tooltipComposeView: ComposeView
20+
private lateinit var bottomNavigationView: BottomNavigationView
21+
22+
private val bottomNavigationLayoutChangeListener = View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
23+
updateTooltipPosition()
24+
}
25+
private val tooltipLayoutChangeListener = View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
26+
updateTooltipPosition()
27+
}
28+
29+
fun bind(
30+
tooltipComposeView: ComposeView,
31+
bottomNavigationView: BottomNavigationView,
32+
) {
33+
clearPreviousBindings()
34+
35+
this.tooltipComposeView = tooltipComposeView
36+
this.bottomNavigationView = bottomNavigationView
37+
38+
setupContent()
39+
observeLayout()
40+
}
41+
42+
private fun clearPreviousBindings() {
43+
if (::bottomNavigationView.isInitialized) {
44+
bottomNavigationView.removeOnLayoutChangeListener(bottomNavigationLayoutChangeListener)
45+
}
46+
47+
if (::tooltipComposeView.isInitialized) {
48+
tooltipComposeView.removeOnLayoutChangeListener(tooltipLayoutChangeListener)
49+
}
50+
}
51+
52+
private fun setupContent() {
53+
tooltipComposeView.apply {
54+
isClickable = false
55+
isFocusable = false
56+
importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
57+
setViewCompositionStrategy(
58+
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
59+
)
60+
setContent {
61+
EatssuTheme {
62+
AnyoneButMeEventTooltip()
63+
}
64+
}
65+
}
66+
}
67+
68+
private fun observeLayout() {
69+
bottomNavigationView.addOnLayoutChangeListener(bottomNavigationLayoutChangeListener)
70+
tooltipComposeView.addOnLayoutChangeListener(tooltipLayoutChangeListener)
71+
72+
bottomNavigationView.doOnLayout { updateTooltipPosition() }
73+
tooltipComposeView.doOnLayout { updateTooltipPosition() }
74+
tooltipComposeView.post { updateTooltipPosition() }
75+
}
76+
77+
private fun updateTooltipPosition() {
78+
if (!::tooltipComposeView.isInitialized || !::bottomNavigationView.isInitialized) return
79+
if (tooltipComposeView.width == 0 || tooltipComposeView.height == 0) return
80+
81+
val itemWidth = bottomNavigationView.width / BOTTOM_NAVIGATION_ITEM_COUNT.toFloat()
82+
val itemCenterX = itemWidth * ANYONE_BUT_ME_MENU_INDEX + (itemWidth / 2f)
83+
84+
tooltipComposeView.x =
85+
bottomNavigationView.x +
86+
itemCenterX -
87+
(tooltipComposeView.width / 2f)
88+
tooltipComposeView.y =
89+
bottomNavigationView.y - tooltipComposeView.height.toFloat()
90+
tooltipComposeView.visibility = View.VISIBLE
91+
}
92+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
app:itemPaddingTop="10dp"
3939
app:menu="@menu/menu_bottom_navigation" />
4040

41+
<androidx.compose.ui.platform.ComposeView
42+
android:id="@+id/compose_event_tooltip"
43+
android:layout_width="wrap_content"
44+
android:layout_height="wrap_content"
45+
android:clickable="false"
46+
android:focusable="false"
47+
android:visibility="invisible"
48+
app:layout_constraintStart_toStartOf="parent"
49+
app:layout_constraintTop_toTopOf="parent" />
50+
4151
<androidx.compose.ui.platform.ComposeView
4252
android:id="@+id/compose_event_popup"
4353
android:layout_width="0dp"

0 commit comments

Comments
 (0)