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

feat: 이상증상 리스트 편집 기능, 데이터 없을 시 이벤트 추가 #68

Merged
merged 23 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
684b68f
design: bottomsheet 파일 이름 변경
iiolo Dec 19, 2023
f39d583
refactor: bottomsheet 프로세스 변경
iiolo Dec 19, 2023
8e4a7b3
feat: 취소 시 뷰모델 데이터 초기화 하는 기능 추가
iiolo Dec 19, 2023
28b324c
feat: 이상증상 리스트 시간 순으로 정렬하는 기능 추가
iiolo Dec 19, 2023
236a1f2
feat: symptom <-> symptomListEdit 이동 기능 추가
iiolo Dec 19, 2023
9c0c038
design: symptom <-> symptomListEdit 이동 액션 추가
iiolo Dec 19, 2023
79751c7
design: 툴바 타이틀 스타일 추가
iiolo Dec 19, 2023
455544a
design: margin 값 추가
iiolo Dec 19, 2023
395e2dd
design: 전체 삭제 이미지 뷰 아이디 변경
iiolo Dec 19, 2023
5235d88
refactor: 쓰지 않는 import문 삭제
iiolo Dec 19, 2023
13e3c5d
refactor: 쓰지 않는 import문 삭제
iiolo Dec 19, 2023
e2df3b2
feat: 전체 삭제 및 선택에 따른 이미지 뷰 및 체크된 이상증상 리스트 데이터 변화 기능 구현
iiolo Dec 19, 2023
3774a50
refactor: 쓰지 않는 함수 삭제
iiolo Dec 19, 2023
51db28a
fix: Array -> IntArray 자료형으로 변경
iiolo Dec 19, 2023
9110360
feat: 선택한 이상증상 삭제 기능 구현
iiolo Dec 19, 2023
08d1e32
feat: 취소 버튼 클릭 시 이상증상 홈으로 돌아가게 구현
iiolo Dec 19, 2023
57ab150
design: 전체 삭제 레이아웃 및 확인 취소 버튼 레이아웃 아이디 지정
iiolo Dec 19, 2023
90c9698
refactor: 함수 이름 변경
iiolo Dec 19, 2023
85849fc
feat: 등록된 이상증상 데이터 없을 경우 전체 삭제 버튼 및 취소, 완료 버튼 안보이게 처리
iiolo Dec 19, 2023
968ed9f
feat: 이상증상 리스트 편집화면에서 이상증상 없을 경우 이벤트 추가
iiolo Dec 19, 2023
9c79367
feat: 이상증상 데이터 없을 경우 이벤트 추가
iiolo Dec 19, 2023
224679d
design: 데이터 없음 안내 문구 수정
iiolo Dec 19, 2023
bcb0b00
refactor: 코틀린 컨벤션에 맞춰 코드 정리
iiolo Dec 19, 2023
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
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