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

[FIX/#118] 2차 mvp 배포 전 수정사항 반영 #143

Merged
merged 13 commits into from
Feb 12, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class HomeFragment :
private val viewModel by viewModels<GroupListViewModel>()
private var adapter: GroupListAdapter? = null


override fun onResume() {
super.onResume()
(activity as MainActivity).showBottomNavi()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ import com.teumteum.teumteum.presentation.moim.compose.MoimDateTime
import com.teumteum.teumteum.presentation.moim.compose.MoimFinish
import com.teumteum.teumteum.presentation.moim.compose.MoimIntroduce
import com.teumteum.teumteum.presentation.moim.compose.MoimPeople
import com.teumteum.teumteum.presentation.signup.modal.SingleModalBottomSheet
import com.teumteum.teumteum.util.SignupUtils.TIME_LIST
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import java.util.ArrayList

class MoimFragment :
BindingFragment<FragmentMoimBinding>(R.layout.fragment_moim) {
private val viewModel: MoimViewModel by activityViewModels()
private var timeBottomSheet: SingleModalBottomSheet? = null


override fun onResume() {
super.onResume()
Expand All @@ -47,6 +52,7 @@ class MoimFragment :
super.onViewCreated(view, savedInstanceState)

observe()
observeBottomSheet()

val navController = findNavController()
val meetingId = arguments?.getLong("meetingId", -1L) ?: -1L
Expand Down Expand Up @@ -134,6 +140,29 @@ class MoimFragment :
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}

private fun showTimeSheet() {
val topicClassListener: (String) -> Unit = { item ->
item?.let {
viewModel.updateAfternoon(it)
}
timeBottomSheet?.dismiss()
viewModel.updateBottomSheet(BottomSheet.Default)
Log.d("viewModel", viewModel.bottomSheet.value.toString())
}

timeBottomSheet = SingleModalBottomSheet.newInstance(
"모임 시간", TIME_LIST, topicClassListener
).apply {
dismissListener = object: SingleModalBottomSheet.OnDismissListener {
override fun onDismiss() {
viewModel.updateBottomSheet(BottomSheet.Default)
}
}
}
Log.d("viewModel", viewModel.bottomSheet.value.toString())
timeBottomSheet?.show(childFragmentManager, SingleModalBottomSheet.TAG)
}

private fun setupUI() {
lifecycleScope.launchWhenStarted {
viewModel.currentStep.collect {currentStep ->
Expand All @@ -160,12 +189,6 @@ class MoimFragment :
}
}

private fun setUpBottomSheet() {
viewLifecycleOwner.lifecycleScope.launch {

}
}

private fun observe() {
viewModel.screenState.flowWithLifecycle(lifecycle)
.onEach {
Expand All @@ -183,8 +206,6 @@ class MoimFragment :
viewModel.initializeState()
}
ScreenState.Success -> {
delay(1000)
(activity as MainActivity).showBottomNavi()
delay(2000)
viewModel.initializeState()
}
Expand All @@ -208,6 +229,18 @@ class MoimFragment :
.launchIn(lifecycleScope)
}

private fun observeBottomSheet() {
viewModel.bottomSheet.flowWithLifecycle(lifecycle)
.onEach {
when(it) {
BottomSheet.Default -> {}
BottomSheet.Time -> showTimeSheet()
else -> {}
}
}
.launchIn(lifecycleScope)
}

private fun animateProgressBar(targetStep: Int) {
val targetProgress = targetStep * 100 + 100
ObjectAnimator.ofInt(binding.progressBar, "progress", targetProgress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class MoimModifyFragment: BindingFragment<FragmentModifyMoimBinding>(R.layout.fr
BottomSheet.Default -> {}
BottomSheet.Topic -> showTopicSheet()
BottomSheet.People -> showPeopleSheet()
else -> {}
}
}
.launchIn(lifecycleScope)
Expand All @@ -90,9 +91,14 @@ class MoimModifyFragment: BindingFragment<FragmentModifyMoimBinding>(R.layout.fr
}

val topicTitles = TopicType.values().map { it.title }
topicBottomSheet = SingleModalBottomSheet.newInstance(
"모임 주제", topicTitles as ArrayList, topicClassListener
)
topicBottomSheet = SingleModalBottomSheet.newInstance("모임 주제", topicTitles as ArrayList, topicClassListener
).apply {
dismissListener = object: SingleModalBottomSheet.OnDismissListener {
override fun onDismiss() {
viewModel.updateBottomSheet(BottomSheet.Default)
}
}
}
topicBottomSheet?.show(childFragmentManager, SingleModalBottomSheet.TAG)
}

Expand All @@ -111,7 +117,13 @@ class MoimModifyFragment: BindingFragment<FragmentModifyMoimBinding>(R.layout.fr

peopleBottomSheet = SingleModalBottomSheet.newInstance(
"참여 인원 선택", PEOPLE_LIST, peopleClassListener
)
).apply {
dismissListener = object: SingleModalBottomSheet.OnDismissListener {
override fun onDismiss() {
viewModel.updateBottomSheet(BottomSheet.Default)
}
}
}
peopleBottomSheet?.show(childFragmentManager, SingleModalBottomSheet.TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class MoimViewModel @Inject constructor(
private val _isBookmark = MutableStateFlow(false)
val isBookmark: StateFlow<Boolean> = _isBookmark.asStateFlow()

private val _isAfternoon = MutableStateFlow("오후")
val isAfternoon: StateFlow<String> = _isAfternoon.asStateFlow()

val characterList: HashMap<Int, Int> = hashMapOf(
0 to R.drawable.ic_ghost,
1 to R.drawable.ic_star,
Expand Down Expand Up @@ -185,19 +188,31 @@ class MoimViewModel @Inject constructor(
fun updateTopic(topicType: TopicType) {
_topic.value = topicType
}

fun updateAfternoon(string: String) {
_isAfternoon.value = string
}
fun updateTitle(title: String) {
_title.value = title
}
fun updateIntroduce(introduce: String) {
_introduction.value = introduce
}
fun updateDate(input: String) {
_date.value = input
}

fun updateTime(input: String) {
_time.value = input
}

fun updateDate2(input: String) {
if (input.length == 4) {
_date.value = formatDateAndDay(input)
}
}

fun updateTime(input: String): String {
fun updateTime2(input: String): String {
val formattedTime = formatTime(input)
_time.value = formattedTime
return formattedTime
Expand Down Expand Up @@ -280,10 +295,14 @@ class MoimViewModel @Inject constructor(
}
}

private fun combineDateAndTime(): LocalDateTime? {
private fun combineDateAndTime2(): LocalDateTime? {
return try {
val currentYear = Year.now().value
val dateInput = "${currentYear}년 ${_date.value.substring(0, _date.value.lastIndexOf(" "))}"
val dateInput = if(_date.value.length == 4) {
"${currentYear}${_date.value}"
} else {
"${currentYear}년 ${_date.value.substring(0, _date.value.lastIndexOf(" "))}"
}
var timeInput = _time.value.replace("오후", "PM").replace("오전", "AM")

val timeParts = timeInput.split(" ")
Expand All @@ -307,6 +326,35 @@ class MoimViewModel @Inject constructor(
}
}

private fun combineDateAndTime(): LocalDateTime? {
return try {
val dateInput = _date.value
var timeInput = _time.value

val isAfternoon = _isAfternoon.value == "오후"
val (hourString, minute) = timeInput.split(":")
var hour = hourString.toInt()

if (isAfternoon && hour < 12) { hour += 12 }
else if (!isAfternoon && hour == 12) {
hour = 0
}

timeInput = "$hour:$minute"

val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd")
val timeFormatter = DateTimeFormatter.ofPattern("H:mm")

val parsedDate = LocalDate.parse(dateInput, dateFormatter)
val parsedTime = LocalTime.parse(timeInput, timeFormatter)

LocalDateTime.of(parsedDate, parsedTime)
} catch (e: Exception) {
Timber.e(e, "Failed to combine date and time")
null
}
}

private suspend fun convertUrisToFile(uris: List<Uri>): List<File> {
return uris.mapNotNull { uri ->
when {
Expand Down Expand Up @@ -411,7 +459,7 @@ class MoimViewModel @Inject constructor(

fun modifyMoim(meetingId: Long) {
viewModelScope.launch {
val dateTime = combineDateAndTime()
val dateTime = combineDateAndTime2()
val imageFiles = convertUrisToFile(imageUri.value)
if(dateTime != null) {
val meetingArea = address.value?.let {
Expand Down Expand Up @@ -626,7 +674,7 @@ enum class ScreenState {
}

enum class BottomSheet {
Topic, People, Default
Topic, People, Default, Time
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fun MoimConfirm(
LazyColumn(modifier = Modifier.weight(1f)) {
item {
MoimPhotoPager(viewModel)
MoimConfirmInfo(viewModel)
MoimConfirmInfo(viewModel, isJoinView = isJoinView)
TmMarginVerticalSpacer(size = 32)
TeumDividerThick(int = 8)
TmMarginVerticalSpacer(size = 20)
Expand Down Expand Up @@ -324,54 +324,73 @@ fun MoimPhotoPager(viewModel : MoimViewModel) {
}

@Composable
fun MoimConfirmInfo(viewModel: MoimViewModel) {
fun MoimConfirmInfo(
viewModel: MoimViewModel,
isJoinView: Boolean
) {
val title by viewModel.title.collectAsState()
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.background(color = TmtmColorPalette.current.color_background)
.padding(horizontal = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Top
) {
TmMarginVerticalSpacer(size = 32)
Row(modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.background(color = TmtmColorPalette.current.color_background)
.padding(horizontal = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Top
) {
Text(
text = title,
style = TmTypo.current.HeadLine3,
modifier = Modifier
.width(320.dp)
.align(Alignment.Top),
color = TmtmColorPalette.current.color_text_headline_primary
)
TmMarginHorizontalSpacer(size = 8)
Image(
painterResource(id = R.drawable.icon_share),
contentDescription = null,
modifier= Modifier
.size(24.dp)
.offset(y = 5.dp)
)
TmMarginVerticalSpacer(size = 32)
Row(modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
Text(
text = title,
style = TmTypo.current.HeadLine3,
modifier = Modifier
.width(320.dp)
.align(Alignment.Top),
color = TmtmColorPalette.current.color_text_headline_primary
)
TmMarginHorizontalSpacer(size = 8)
Image(
painterResource(id = R.drawable.icon_share),
contentDescription = null,
modifier= Modifier
.size(24.dp)
.offset(y = 5.dp)
)
}
TmMarginVerticalSpacer(size = 16)
MoimInfoCard(viewModel, isJoinView = isJoinView)
}
TmMarginVerticalSpacer(size = 16)
MoimInfoCard(viewModel)
}

}

@Composable
fun MoimInfoCard(viewModel: MoimViewModel) {
fun MoimInfoCard(viewModel: MoimViewModel,isJoinView: Boolean) {
val topic by viewModel.topic.collectAsState()
val people by viewModel.people.collectAsState()
val date by viewModel.date.collectAsState()
val time by viewModel.time.collectAsState()
val isAfternoon by viewModel.isAfternoon.collectAsState()
val detailAddress by viewModel.detailAddress.collectAsState()

val dateString = if (isJoinView) {
if(date.length ==4) {
"${date.substring(0, 2)}월 ${date.substring(2, 4)}일 $time"
} else {
"$date $time"
}
} else {
if (date.length == 8) {
"${date.substring(0, 4)}년 ${date.substring(4, 6)}월 ${date.substring(6, 8)}일 $isAfternoon $time"
} else {
date
}
}

Box(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -389,7 +408,7 @@ fun MoimInfoCard(viewModel: MoimViewModel) {
verticalArrangement = Arrangement.SpaceAround,
horizontalAlignment = Alignment.CenterHorizontally
) {
MoimCardRow(title = stringResource(id = R.string.moim_confirm_title1), text = "$date $time")
MoimCardRow(title = stringResource(id = R.string.moim_confirm_title1), text = dateString)
TmMarginVerticalSpacer(size = 4)
MoimCardRow(title = stringResource(id = R.string.moim_confirm_title2), text = viewModel.getTopicTitle(topic))
TmMarginVerticalSpacer(size = 4)
Expand Down
Loading
Loading