Skip to content

Commit

Permalink
Merge pull request #68 from meongCare/feature/nutrition
Browse files Browse the repository at this point in the history
feat: 이상증상 리스트 편집 기능, 데이터 없을 시 이벤트 추가
  • Loading branch information
nueijeel authored Dec 20, 2023
2 parents de1afcc + bcb0b00 commit be9d386
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface SymptomAPI {
@DELETE("/symptom")
fun deleteSymptom(
@Header("AccessToken") accessToken: String,
@Query("symptomIds") symtomIds: Array<Int>,
@Query("symptomIds") symtomIds: IntArray,
): Call<ResponseSymptom>

@PATCH("/symptom")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SymptomRepository {
)
}

fun deleteSymptom(symptomIds: Array<Int>) {
fun deleteSymptom(symptomIds: IntArray) {
val retrofit =
Retrofit.Builder().baseUrl(MainActivity.BASE_URL)
.addConverterFactory(nullOnEmptyConverterFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.DatePicker
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.project.meongcare.MainActivity
import com.project.meongcare.R
import com.project.meongcare.databinding.FragmentSymptomAddBinding
import com.project.meongcare.symptom.model.data.repository.SymptomRepository
import com.project.meongcare.symptom.model.entities.ToAddSymptom
import com.project.meongcare.symptom.view.SymptomUtils.Companion.getSymptomName
import com.project.meongcare.symptom.view.SymptomUtils.Companion.hideKeyboard
import com.project.meongcare.symptom.view.SymptomUtils.Companion.showCalendarBottomSheet
import com.project.meongcare.symptom.viewmodel.SymptomViewModel
import java.time.LocalDate

class SymptomAddFragment : Fragment() {
lateinit var fragmentSymptomAddBinding: FragmentSymptomAddBinding
lateinit var mainActivity: MainActivity
lateinit var symptomViewModel: SymptomViewModel
private lateinit var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -89,14 +86,9 @@ class SymptomAddFragment : Fragment() {
navController.navigate(R.id.action_symptomAdd_to_symptom)
}
}
includeBottomsheetSymptomAddDate.run {
initializeBottomSheet(layoutBottomsheetSymptomAddDate)
bottomSheetEvent(buttonBottomsheetSymptomAddDateComplete)
removeDatePickerHeader()
}

buttonSymptomAddDate.setOnClickListener {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
showCalendarBottomSheet(parentFragmentManager, symptomViewModel)
}

isNullDate()
Expand Down Expand Up @@ -179,16 +171,6 @@ class SymptomAddFragment : Fragment() {
return fragmentSymptomAddBinding.root
}

private fun removeDatePickerHeader() {
fragmentSymptomAddBinding.includeBottomsheetSymptomAddDate.run {
val datePickerHeaderId =
datepickerBottomsheetSymptomAddDate.getChildAt(0)
.resources.getIdentifier("date_picker_header", "id", "android")
datepickerBottomsheetSymptomAddDate.findViewById<View>(datePickerHeaderId).visibility =
View.GONE
}
}

private fun FragmentSymptomAddBinding.isNullAddItem() {
if (!symptomViewModel.symptomItemTitle.value.isNullOrEmpty()) {
layoutSymptomAddList.visibility = View.VISIBLE
Expand Down Expand Up @@ -220,67 +202,6 @@ class SymptomAddFragment : Fragment() {
}
}

private fun initializeBottomSheet(symptomBottomSheet: LinearLayout) {
// BottomSheetBehavior에 layout 설정
bottomSheetBehavior = BottomSheetBehavior.from(symptomBottomSheet)

bottomSheetBehavior.addBottomSheetCallback(
object :
BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(
bottomSheet: View,
newState: Int,
) {
// BottomSheetBehavior state에 따른 이벤트
when (newState) {
BottomSheetBehavior.STATE_HIDDEN -> {
Log.d("MainActivity", "state: hidden")
}

BottomSheetBehavior.STATE_EXPANDED -> {
Log.d("MainActivity", "state: expanded")
}

BottomSheetBehavior.STATE_COLLAPSED -> {
Log.d("MainActivity", "state: collapsed")
}

BottomSheetBehavior.STATE_DRAGGING -> {
Log.d("MainActivity", "state: dragging")
}

BottomSheetBehavior.STATE_SETTLING -> {
Log.d("MainActivity", "state: settling")
}

BottomSheetBehavior.STATE_HALF_EXPANDED -> {
Log.d("MainActivity", "state: half expanded")
}
}
}

override fun onSlide(
bottomSheet: View,
slideOffset: Float,
) {
}
},
)
}

private fun bottomSheetEvent(symptomBottomSheetCloseButton: LinearLayout): LocalDate {
var customDate = LocalDate.now()
symptomBottomSheetCloseButton.setOnClickListener {
val datePicker =
mainActivity.findViewById<DatePicker>(R.id.datepicker_bottomsheet_symptom_add_date)
customDate = LocalDate.of(datePicker.year, datePicker.month + 1, datePicker.dayOfMonth)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
symptomViewModel.symptomDateText.value = customDate.toString()
Log.d("뷰모델", symptomViewModel.symptomDateText.value.toString())
}
return customDate
}

private fun isNullInput(
textView: TextView,
layout: LinearLayout,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.project.meongcare.symptom.view

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.project.meongcare.databinding.BottomsheetSymptomAddDateBinding
import java.time.LocalDate

class SymptomBottomSheetDialogFragment : BottomSheetDialogFragment() {
lateinit var fragmentSymptomBottomSheetBinding: BottomsheetSymptomAddDateBinding

interface OnDateSelectedListener {
fun onDateSelected(date: LocalDate)
}

var onDateSelectedListener: OnDateSelectedListener? = null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
fragmentSymptomBottomSheetBinding = BottomsheetSymptomAddDateBinding.inflate(inflater, container, false)

fragmentSymptomBottomSheetBinding.buttonBottomsheetSymptomAddDateComplete.setOnClickListener {
val datePicker = fragmentSymptomBottomSheetBinding.datepickerBottomsheetSymptomAddDate
val selectedDate =
LocalDate.of(datePicker.year, datePicker.month + 1, datePicker.dayOfMonth)
onDateSelectedListener?.onDateSelected(selectedDate)
dismiss()
}

return fragmentSymptomBottomSheetBinding.root
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
val peekHeightInPixels = 0

val behavior = dialog.behavior
if (behavior != null) {
behavior.peekHeight = peekHeightInPixels
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}

return dialog
}

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
removeDatePickerHeader()
}

fun removeDatePickerHeader() {
fragmentSymptomBottomSheetBinding.run {
val datePickerHeaderId =
fragmentSymptomBottomSheetBinding.datepickerBottomsheetSymptomAddDate.getChildAt(0)
.resources.getIdentifier("date_picker_header", "id", "android")
fragmentSymptomBottomSheetBinding.root.findViewById<View>(datePickerHeaderId).visibility =
View.GONE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.widget.DatePicker
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.project.meongcare.MainActivity
import com.project.meongcare.R
import com.project.meongcare.databinding.FragmentSymptomEditBinding
Expand All @@ -24,13 +22,13 @@ import com.project.meongcare.symptom.view.SymptomUtils.Companion.convertDateToMo
import com.project.meongcare.symptom.view.SymptomUtils.Companion.convertDateToSimpleTime
import com.project.meongcare.symptom.view.SymptomUtils.Companion.convertDateToTime
import com.project.meongcare.symptom.view.SymptomUtils.Companion.convertSimpleDateToMonthDate
import com.project.meongcare.symptom.view.SymptomUtils.Companion.showCalendarBottomSheet
import com.project.meongcare.symptom.viewmodel.SymptomViewModel

class SymptomEditFragment : Fragment() {
lateinit var fragmentSymptomEditBinding: FragmentSymptomEditBinding
lateinit var mainActivity: MainActivity
lateinit var symptomViewModel: SymptomViewModel
private lateinit var bottomSheetBehavior: BottomSheetBehavior<LinearLayout>
lateinit var navController: NavController

override fun onCreateView(
Expand All @@ -45,6 +43,7 @@ class SymptomEditFragment : Fragment() {
navController = findNavController()

symptomViewModel.run {
isEditSymptom = true
symptomDateText.observe(viewLifecycleOwner) {
if (it != null) {
fragmentSymptomEditBinding.textViewSymptomEditDate.text =
Expand All @@ -68,16 +67,11 @@ class SymptomEditFragment : Fragment() {

fragmentSymptomEditBinding.run {
val symptomData = symptomViewModel.infoSymptomData.value!!
includeBottomsheetSymptomEdit.run {
initializeBottomSheet(layoutBottomsheetSymptomAddDate)
bottomSheetEvent(buttonBottomsheetSymptomAddDateComplete)
removeDatePickerHeader()
}

textViewSymptomEditDate.run {
text = convertDateToMonthDate(symptomViewModel.symptomDateText.value!!)
setOnClickListener {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
showCalendarBottomSheet(parentFragmentManager, symptomViewModel)
}
}

Expand Down Expand Up @@ -135,6 +129,7 @@ class SymptomEditFragment : Fragment() {
}

buttonSymptomEditCancel.setOnClickListener {
symptomViewModel.clearLiveData()
navController.navigate(R.id.action_symptomEdit_to_symptomInfo)
}

Expand Down Expand Up @@ -191,16 +186,6 @@ class SymptomEditFragment : Fragment() {
return fragmentSymptomEditBinding.root
}

fun removeDatePickerHeader() {
fragmentSymptomEditBinding.includeBottomsheetSymptomEdit.run {
val datePickerHeaderId =
datepickerBottomsheetSymptomAddDate.getChildAt(0)
.resources.getIdentifier("date_picker_header", "id", "android")
datepickerBottomsheetSymptomAddDate.findViewById<View>(datePickerHeaderId).visibility =
View.GONE
}
}

private fun isNullInput(
textView: TextView,
layout: LinearLayout,
Expand All @@ -215,71 +200,6 @@ class SymptomEditFragment : Fragment() {
}
}

private fun initializeBottomSheet(symptomBottomSheet: LinearLayout) {
// BottomSheetBehavior에 layout 설정
bottomSheetBehavior = BottomSheetBehavior.from(symptomBottomSheet)

bottomSheetBehavior.addBottomSheetCallback(
object :
BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(
bottomSheet: View,
newState: Int,
) {
// BottomSheetBehavior state에 따른 이벤트
when (newState) {
BottomSheetBehavior.STATE_HIDDEN -> {
Log.d("MainActivity", "state: hidden")
}

BottomSheetBehavior.STATE_EXPANDED -> {
Log.d("MainActivity", "state: expanded")
}

BottomSheetBehavior.STATE_COLLAPSED -> {
Log.d("MainActivity", "state: collapsed")
}

BottomSheetBehavior.STATE_DRAGGING -> {
Log.d("MainActivity", "state: dragging")
}

BottomSheetBehavior.STATE_SETTLING -> {
Log.d("MainActivity", "state: settling")
}

BottomSheetBehavior.STATE_HALF_EXPANDED -> {
Log.d("MainActivity", "state: half expanded")
}
}
}

override fun onSlide(
bottomSheet: View,
slideOffset: Float,
) {
}
},
)
}

private fun bottomSheetEvent(symptomBottomSheetCloseButton: LinearLayout) {
symptomBottomSheetCloseButton.setOnClickListener {
val datePicker =
mainActivity.findViewById<DatePicker>(R.id.datepicker_bottomsheet_symptom_add_date)

val year = datePicker.year
val month = datePicker.month + 1
val dayOfMonth = datePicker.dayOfMonth

val customDateTime = String.format("%04d-%02d-%02dT00:00:00", year, month, dayOfMonth)

bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
symptomViewModel.symptomDateText.value = customDateTime.toString()
Log.d("뷰모델", symptomViewModel.symptomDateText.value.toString())
}
}

private fun hideCompleteBtn() {
fragmentSymptomEditBinding.layoutSymptomEditButton.visibility = View.GONE
}
Expand Down
Loading

0 comments on commit be9d386

Please sign in to comment.