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

emotion-89 : bottom items 추가 #94

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package com.teamtuna.emotionaldiary.main

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.teamtuna.emotionaldiary.add.EmotionAddFragment
import com.teamtuna.emotionaldiary.presentation.R
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement.SpaceBetween
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.google.accompanist.insets.ProvideWindowInsets
import com.teamtuna.emotionaldiary.compose.theme.EmotionalDiaryTheme
import dagger.hilt.android.AndroidEntryPoint

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

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setContent {
MainScene()
}

val fragment = EmotionAddFragment()
supportFragmentManager.beginTransaction().replace(R.id.fragment, fragment).commit()
}

@Composable
fun MainScene() {
EmotionalDiaryTheme {
ProvideWindowInsets {

BottomMenu()
csi111 marked this conversation as resolved.
Show resolved Hide resolved
// fixme bottomAppBar
// Scaffold(
// bottomAppBar = {
//
// }
// )
}
}
}

@Composable
fun BottomMenu() {
val selectedMenu = viewModel.selectedMenu
Row(
Modifier
.background(Color(0xFFEDEAE0))
.fillMaxSize(),
horizontalArrangement = SpaceBetween,
verticalAlignment = Alignment.Bottom
) {
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.CALENDAR) }) {
val color =
if (selectedMenu.value == BottomMenu.CALENDAR) Color.Blue else Color.DarkGray
Text(text = "달력", color = color)
}
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.TIMELINE) }) {
val color =
if (selectedMenu.value == BottomMenu.TIMELINE) Color.Blue else Color.DarkGray
Text(text = "타임라인", color = color)
}
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.ANALYSIS) }) {
val color =
if (selectedMenu.value == BottomMenu.ANALYSIS) Color.Blue else Color.DarkGray
Text(text = "분석", color = color)
}
TextButton(onClick = { viewModel.onSelectBottomMenu(BottomMenu.SETTING) }) {
val color =
if (selectedMenu.value == BottomMenu.SETTING) Color.Blue else Color.DarkGray
Text(text = "설정", color = color)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teamtuna.emotionaldiary.main

import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import com.teamtuna.emotionaldiary.usecase.MainUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -8,4 +9,15 @@ import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(private val mainUseCase: MainUseCase) : ViewModel() {
fun test() = mainUseCase()

private val _selectedMenu = mutableStateOf<BottomMenu>(BottomMenu.CALENDAR)
val selectedMenu get() = _selectedMenu

fun onSelectBottomMenu(menu: BottomMenu) {
_selectedMenu.value = menu
}
}

enum class BottomMenu {
CALENDAR, TIMELINE, ANALYSIS, SETTING
}