Skip to content

Commit 40fa6d6

Browse files
authored
Merge pull request #94 from teamtuna/feature/emotion-89
emotion-89 : bottom items 추가
2 parents 1abd4b2 + 401a537 commit 40fa6d6

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
package com.teamtuna.emotionaldiary.main
22

33
import android.os.Bundle
4+
import androidx.activity.compose.setContent
45
import androidx.activity.viewModels
56
import androidx.appcompat.app.AppCompatActivity
6-
import com.teamtuna.emotionaldiary.add.EmotionAddFragment
7-
import com.teamtuna.emotionaldiary.presentation.R
7+
import androidx.compose.foundation.background
8+
import androidx.compose.foundation.layout.Arrangement.SpaceBetween
9+
import androidx.compose.foundation.layout.Row
10+
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.material.Text
12+
import androidx.compose.material.TextButton
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.graphics.Color
17+
import com.google.accompanist.insets.ProvideWindowInsets
18+
import com.teamtuna.emotionaldiary.compose.theme.EmotionalDiaryTheme
819
import dagger.hilt.android.AndroidEntryPoint
920

1021
@AndroidEntryPoint
@@ -14,9 +25,58 @@ class MainActivity : AppCompatActivity() {
1425

1526
override fun onCreate(savedInstanceState: Bundle?) {
1627
super.onCreate(savedInstanceState)
17-
setContentView(R.layout.activity_main)
28+
setContent {
29+
MainScene()
30+
}
1831

19-
val fragment = EmotionAddFragment()
20-
supportFragmentManager.beginTransaction().replace(R.id.fragment, fragment).commit()
32+
}
33+
34+
@Composable
35+
fun MainScene() {
36+
EmotionalDiaryTheme {
37+
ProvideWindowInsets {
38+
39+
BottomMenu()
40+
// fixme bottomAppBar
41+
// Scaffold(
42+
// bottomAppBar = {
43+
//
44+
// }
45+
// )
46+
}
47+
}
48+
}
49+
50+
@Composable
51+
fun BottomMenu() {
52+
val selectedMenu = viewModel.selectedMenu
53+
Row(
54+
Modifier
55+
.background(Color(0xFFEDEAE0))
56+
.fillMaxSize(),
57+
horizontalArrangement = SpaceBetween,
58+
verticalAlignment = Alignment.Bottom
59+
) {
60+
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.CALENDAR) }) {
61+
val color =
62+
if (selectedMenu.value == BottomMenu.CALENDAR) Color.Blue else Color.DarkGray
63+
Text(text = "달력", color = color)
64+
}
65+
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.TIMELINE) }) {
66+
val color =
67+
if (selectedMenu.value == BottomMenu.TIMELINE) Color.Blue else Color.DarkGray
68+
Text(text = "타임라인", color = color)
69+
}
70+
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.ANALYSIS) }) {
71+
val color =
72+
if (selectedMenu.value == BottomMenu.ANALYSIS) Color.Blue else Color.DarkGray
73+
Text(text = "분석", color = color)
74+
}
75+
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.SETTING) }) {
76+
val color =
77+
if (selectedMenu.value == BottomMenu.SETTING) Color.Blue else Color.DarkGray
78+
Text(text = "설정", color = color)
79+
}
80+
}
2181
}
2282
}

presentation/src/main/java/com/teamtuna/emotionaldiary/main/MainViewModel.kt

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.teamtuna.emotionaldiary.main
22

3+
import androidx.compose.runtime.mutableStateOf
34
import androidx.lifecycle.ViewModel
45
import com.teamtuna.emotionaldiary.usecase.MainUseCase
56
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -8,4 +9,15 @@ import javax.inject.Inject
89
@HiltViewModel
910
class MainViewModel @Inject constructor(private val mainUseCase: MainUseCase) : ViewModel() {
1011
fun test() = mainUseCase()
12+
13+
private val _selectedMenu = mutableStateOf<BottomMenu>(BottomMenu.CALENDAR)
14+
val selectedMenu get() = _selectedMenu
15+
16+
fun onSelectBottomMenu(menu: BottomMenu) {
17+
_selectedMenu.value = menu
18+
}
19+
}
20+
21+
enum class BottomMenu {
22+
CALENDAR, TIMELINE, ANALYSIS, SETTING
1123
}

0 commit comments

Comments
 (0)