From 4c20ac4f7c45fe7e9ac6d43675ac82c823ecdbb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:02:54 +0900 Subject: [PATCH 1/8] =?UTF-8?q?feat=20:=20=ED=95=99=EC=82=AC=20=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20=EC=84=A0=ED=83=9D=20datePicker=20Dialog=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 84 +++++++++++++++++++ .../ui/view/schedule/ScheduleFragment.kt | 41 ++++++--- .../ui/view/schedule/ScheduleViewModel.kt | 6 +- app/src/main/res/layout/dialog_datepicker.xml | 54 ++++++++++++ app/src/main/res/values/strings.xml | 4 + 5 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt create mode 100644 app/src/main/res/layout/dialog_datepicker.xml diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt new file mode 100644 index 00000000..8b34fa1c --- /dev/null +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -0,0 +1,84 @@ +package com.dongyang.android.youdongknowme.ui.view.schedule + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.NumberPicker +import androidx.fragment.app.DialogFragment +import com.dongyang.android.youdongknowme.databinding.DialogDatepickerBinding +import org.koin.androidx.viewmodel.ext.android.viewModel +import org.threeten.bp.LocalDate + +class DatePickerDialog( + val year: Int, + val month: Int, + private val dateSelectedListener: ScheduleFragment, + private val cancelListener: (() -> Unit)? = null, +) : DialogFragment() { + + private var _binding: DialogDatepickerBinding? = null + private val binding get() = _binding!! + + private val viewModel: ScheduleViewModel by viewModel() + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { + + _binding = DialogDatepickerBinding.inflate(inflater, container, false) + val view = binding.root + + // 현재 연도 + val currentYear = LocalDate.now().year + + // 순환 막기 + binding.numberpickerDialogDatepickerYear.wrapSelectorWheel = false + binding.numberpickerDialogDatepickerMonth.wrapSelectorWheel = false + + // editText 설정 막기 + binding.numberpickerDialogDatepickerYear.descendantFocusability = NumberPicker.FOCUS_BLOCK_DESCENDANTS + binding.numberpickerDialogDatepickerMonth.descendantFocusability = NumberPicker.FOCUS_BLOCK_DESCENDANTS + + // 연도 및 월의 최소/최대값 설정 + with(binding.numberpickerDialogDatepickerYear) { + minValue = currentYear - 1 + maxValue = currentYear + 1 + } + + with(binding.numberpickerDialogDatepickerMonth) { + minValue = 1 + maxValue = if (year == currentYear + 1) 2 else 12 + + // 연도 선택에 따른 월의 최대값 동적 설정 + binding.numberpickerDialogDatepickerYear.setOnValueChangedListener { _, _, newYear -> + maxValue = if (newYear == currentYear + 1) 2 else 12 + } + } + + // 초기 설정 + binding.numberpickerDialogDatepickerYear.value = year + binding.numberpickerDialogDatepickerMonth.value = month + + // 취소 버튼 클릭시 + binding.tvDialogDatepickerCancel.setOnClickListener { + cancelListener?.invoke() + dismiss() + } + + binding.tvDialogPermissionComplete.setOnClickListener { + viewModel.setDatePicker(binding.numberpickerDialogDatepickerYear.value, binding.numberpickerDialogDatepickerMonth.value) + dateSelectedListener.onDateSelected(binding.numberpickerDialogDatepickerYear.value, binding.numberpickerDialogDatepickerMonth.value) + dismiss() + } + + return view + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt index 340a84a7..61b6bc2a 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt @@ -1,14 +1,7 @@ package com.dongyang.android.youdongknowme.ui.view.schedule import android.content.res.ColorStateList -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.PorterDuff -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.Drawable import androidx.core.content.ContextCompat -import androidx.core.content.res.ResourcesCompat -import androidx.core.graphics.drawable.DrawableCompat import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.dongyang.android.youdongknowme.R @@ -20,15 +13,34 @@ import com.prolificinteractive.materialcalendarview.CalendarDay import org.koin.androidx.viewmodel.ext.android.viewModel import org.threeten.bp.LocalDate +interface OnDateSelectedListener { + fun onDateSelected(year: Int, month: Int) +} + /* 학사 일정 화면 */ -class ScheduleFragment : BaseFragment() { +class ScheduleFragment : BaseFragment(), OnDateSelectedListener { override val layoutResourceId: Int = R.layout.fragment_schedule override val viewModel: ScheduleViewModel by viewModel() private lateinit var adapter: ScheduleAdapter + private var _year = LocalDate.now().year.toString() + private var year = _year + + private var _month = LocalDate.now().month.toString() + private var month = _month + + override fun onDateSelected(year: Int, month: Int) { + + // 선택된 연도와 월을 사용하여 CalendarView 업데이트 + val date = CalendarDay.from(year, month, 1) + binding.mvScheduleCalendar.currentDate = date + binding.mvScheduleCalendar.setCurrentDate(date, true) + } + override fun initStartView() { + binding.vm = viewModel viewModel.setPickedDate(binding.mvScheduleCalendar.currentDate) @@ -55,6 +67,10 @@ class ScheduleFragment : BaseFragment + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eeb8a4bf..07ee7b12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -148,4 +148,8 @@ 내용 취소 설정 화면 이동 + + + 취소 + 저장 \ No newline at end of file From c07455b6d546682227b736c8a980cde010ad1e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:38:04 +0900 Subject: [PATCH 2/8] =?UTF-8?q?build=20:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20datepicker=20custom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 28 ++++++++++++++++++- app/src/main/res/layout/dialog_datepicker.xml | 14 ++++++---- app/src/main/res/values/themes.xml | 5 ++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index 8b34fa1c..38f522f3 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -1,9 +1,11 @@ package com.dongyang.android.youdongknowme.ui.view.schedule +import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.WindowManager import android.widget.NumberPicker import androidx.fragment.app.DialogFragment import com.dongyang.android.youdongknowme.databinding.DialogDatepickerBinding @@ -27,7 +29,7 @@ class DatePickerDialog( container: ViewGroup?, savedInstanceState: Bundle?, ): View { - + _binding = DialogDatepickerBinding.inflate(inflater, container, false) val view = binding.root @@ -77,7 +79,31 @@ class DatePickerDialog( return view } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + + val dialog = super.onCreateDialog(savedInstanceState) + + dialog.window?.let { window -> + window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) + } + + return dialog + } + + override fun onStart() { + + super.onStart() + + dialog?.window?.let { window -> + val layoutParams = window.attributes + layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT + window.attributes = layoutParams + } + } + override fun onDestroyView() { + super.onDestroyView() _binding = null } diff --git a/app/src/main/res/layout/dialog_datepicker.xml b/app/src/main/res/layout/dialog_datepicker.xml index 078d1004..8c3a0187 100644 --- a/app/src/main/res/layout/dialog_datepicker.xml +++ b/app/src/main/res/layout/dialog_datepicker.xml @@ -10,20 +10,22 @@ + app:layout_constraintTop_toTopOf="parent" + android:theme="@style/Theme.YouDongKnowMe.NumberPicker"/> + app:layout_constraintTop_toTopOf="parent" + android:theme="@style/Theme.YouDongKnowMe.NumberPicker" /> 16dp @color/gray500 + + + \ No newline at end of file From 0b1dd99edcb7d1609de22a7c769a88faa594784e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Mon, 12 Aug 2024 17:39:45 +0900 Subject: [PATCH 3/8] =?UTF-8?q?build:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20datepicker=20=EC=BD=94=EB=93=9C=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 21 +++++++++++---- .../ui/view/schedule/ScheduleFragment.kt | 27 ++++++++++++++++--- app/src/main/res/layout/dialog_datepicker.xml | 12 ++++----- app/src/main/res/values/themes.xml | 2 +- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index 38f522f3..cf545462 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -41,8 +41,10 @@ class DatePickerDialog( binding.numberpickerDialogDatepickerMonth.wrapSelectorWheel = false // editText 설정 막기 - binding.numberpickerDialogDatepickerYear.descendantFocusability = NumberPicker.FOCUS_BLOCK_DESCENDANTS - binding.numberpickerDialogDatepickerMonth.descendantFocusability = NumberPicker.FOCUS_BLOCK_DESCENDANTS + binding.numberpickerDialogDatepickerYear.descendantFocusability = + NumberPicker.FOCUS_BLOCK_DESCENDANTS + binding.numberpickerDialogDatepickerMonth.descendantFocusability = + NumberPicker.FOCUS_BLOCK_DESCENDANTS // 연도 및 월의 최소/최대값 설정 with(binding.numberpickerDialogDatepickerYear) { @@ -71,8 +73,14 @@ class DatePickerDialog( } binding.tvDialogPermissionComplete.setOnClickListener { - viewModel.setDatePicker(binding.numberpickerDialogDatepickerYear.value, binding.numberpickerDialogDatepickerMonth.value) - dateSelectedListener.onDateSelected(binding.numberpickerDialogDatepickerYear.value, binding.numberpickerDialogDatepickerMonth.value) + viewModel.setDatePicker( + binding.numberpickerDialogDatepickerYear.value, + binding.numberpickerDialogDatepickerMonth.value + ) + dateSelectedListener.onDateSelected( + binding.numberpickerDialogDatepickerYear.value, + binding.numberpickerDialogDatepickerMonth.value + ) dismiss() } @@ -84,7 +92,10 @@ class DatePickerDialog( val dialog = super.onCreateDialog(savedInstanceState) dialog.window?.let { window -> - window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + window.setLayout( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT + ) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) } diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt index 61b6bc2a..9a2942e7 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt @@ -18,7 +18,8 @@ interface OnDateSelectedListener { } /* 학사 일정 화면 */ -class ScheduleFragment : BaseFragment(), OnDateSelectedListener { +class ScheduleFragment : BaseFragment(), + OnDateSelectedListener { override val layoutResourceId: Int = R.layout.fragment_schedule override val viewModel: ScheduleViewModel by viewModel() @@ -45,8 +46,22 @@ class ScheduleFragment : BaseFragment + android:background="@drawable/bg_stroke_gray300_radius_2dp" + android:backgroundTint="@color/white"> + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" /> - \ No newline at end of file From 3df50b70447c27d638abcac13b70a5a4457ab05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Wed, 14 Aug 2024 02:46:03 +0900 Subject: [PATCH 4/8] =?UTF-8?q?build=20:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20datepicker=20=EB=82=B4=EB=B6=80=20=EB=94=94?= =?UTF-8?q?=EC=9E=90=EC=9D=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 7 ---- app/src/main/res/layout/dialog_datepicker.xml | 42 ++++++++----------- app/src/main/res/values/strings.xml | 3 +- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index cf545462..512dccc3 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -16,7 +16,6 @@ class DatePickerDialog( val year: Int, val month: Int, private val dateSelectedListener: ScheduleFragment, - private val cancelListener: (() -> Unit)? = null, ) : DialogFragment() { private var _binding: DialogDatepickerBinding? = null @@ -66,12 +65,6 @@ class DatePickerDialog( binding.numberpickerDialogDatepickerYear.value = year binding.numberpickerDialogDatepickerMonth.value = month - // 취소 버튼 클릭시 - binding.tvDialogDatepickerCancel.setOnClickListener { - cancelListener?.invoke() - dismiss() - } - binding.tvDialogPermissionComplete.setOnClickListener { viewModel.setDatePicker( binding.numberpickerDialogDatepickerYear.value, diff --git a/app/src/main/res/layout/dialog_datepicker.xml b/app/src/main/res/layout/dialog_datepicker.xml index fef3a8c4..095d21f3 100644 --- a/app/src/main/res/layout/dialog_datepicker.xml +++ b/app/src/main/res/layout/dialog_datepicker.xml @@ -10,8 +10,11 @@ - - - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/numberpicker_dialog_datepicker_year" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 07ee7b12..4079c5e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -150,6 +150,5 @@ 설정 화면 이동 - 취소 - 저장 + 완료 \ No newline at end of file From 53cb6634ab70e7586d69bb1e7bfe489fab059519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Wed, 14 Aug 2024 02:52:42 +0900 Subject: [PATCH 5/8] =?UTF-8?q?build=20:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=20datepicker=20=EC=98=B5=EC=85=98=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EB=B0=A9=EC=8B=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../youdongknowme/ui/view/schedule/DatePickerDialog.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index 512dccc3..11c747d2 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -45,12 +45,14 @@ class DatePickerDialog( binding.numberpickerDialogDatepickerMonth.descendantFocusability = NumberPicker.FOCUS_BLOCK_DESCENDANTS - // 연도 및 월의 최소/최대값 설정 + // 연도 최소/최대값 설정 및 출력 방식 설정 with(binding.numberpickerDialogDatepickerYear) { minValue = currentYear - 1 maxValue = currentYear + 1 + displayedValues=((minValue..maxValue).map{"$it 년"}.toTypedArray()) } + // 월 최소/최대값 설정 및 출력 방식 설정 with(binding.numberpickerDialogDatepickerMonth) { minValue = 1 maxValue = if (year == currentYear + 1) 2 else 12 @@ -59,6 +61,8 @@ class DatePickerDialog( binding.numberpickerDialogDatepickerYear.setOnValueChangedListener { _, _, newYear -> maxValue = if (newYear == currentYear + 1) 2 else 12 } + + displayedValues=((minValue..maxValue).map{"$it 월"}.toTypedArray()) } // 초기 설정 From 392928090f4c3d0e95ec96aa5c29a149b1b77309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Wed, 14 Aug 2024 13:17:19 +0900 Subject: [PATCH 6/8] =?UTF-8?q?build=20:=20=ED=95=99=EC=82=AC=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=EC=9D=98=20datepicker=EC=9D=84=20bottomsheet=20?= =?UTF-8?q?=ED=98=95=ED=83=9C=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 29 ++++--------------- .../res/drawable/bg_white_radius_20dp.xml | 5 ++++ app/src/main/res/layout/dialog_datepicker.xml | 5 +--- app/src/main/res/values/styles.xml | 8 +++++ 4 files changed, 19 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/bg_white_radius_20dp.xml diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index 11c747d2..ed22f8cb 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -8,7 +8,10 @@ import android.view.ViewGroup import android.view.WindowManager import android.widget.NumberPicker import androidx.fragment.app.DialogFragment +import com.dongyang.android.youdongknowme.R import com.dongyang.android.youdongknowme.databinding.DialogDatepickerBinding +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.bottomsheet.BottomSheetDialogFragment import org.koin.androidx.viewmodel.ext.android.viewModel import org.threeten.bp.LocalDate @@ -16,7 +19,7 @@ class DatePickerDialog( val year: Int, val month: Int, private val dateSelectedListener: ScheduleFragment, -) : DialogFragment() { +) : BottomSheetDialogFragment() { private var _binding: DialogDatepickerBinding? = null private val binding get() = _binding!! @@ -85,29 +88,7 @@ class DatePickerDialog( } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - - val dialog = super.onCreateDialog(savedInstanceState) - - dialog.window?.let { window -> - window.setLayout( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) - } - - return dialog - } - - override fun onStart() { - - super.onStart() - - dialog?.window?.let { window -> - val layoutParams = window.attributes - layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT - window.attributes = layoutParams - } + return BottomSheetDialog(requireContext(), R.style.CustomBottomSheetDialogTheme) } override fun onDestroyView() { diff --git a/app/src/main/res/drawable/bg_white_radius_20dp.xml b/app/src/main/res/drawable/bg_white_radius_20dp.xml new file mode 100644 index 00000000..330ad6eb --- /dev/null +++ b/app/src/main/res/drawable/bg_white_radius_20dp.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_datepicker.xml b/app/src/main/res/layout/dialog_datepicker.xml index 095d21f3..add0c289 100644 --- a/app/src/main/res/layout/dialog_datepicker.xml +++ b/app/src/main/res/layout/dialog_datepicker.xml @@ -4,9 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="20dp" - android:background="@drawable/bg_stroke_gray300_radius_2dp" - android:backgroundTint="@color/white"> + android:layout_margin="20dp"> - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 28b2676d..7da23d7f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -29,4 +29,12 @@ @font/pretendard_medium @dimen/font_size_12 + + + + \ No newline at end of file From 7e4ab803e7274386fc23293a7c95ebe4c84abea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=9D=AC=EC=9A=B0?= <84004687+huiwoo-jo@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:18:59 +0900 Subject: [PATCH 7/8] =?UTF-8?q?build=20:=20=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=ED=94=BC=EC=BB=A4=20=ED=95=B8=EB=93=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/ic_dialog_handle.xml | 9 +++++++++ app/src/main/res/layout/dialog_datepicker.xml | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 app/src/main/res/drawable/ic_dialog_handle.xml diff --git a/app/src/main/res/drawable/ic_dialog_handle.xml b/app/src/main/res/drawable/ic_dialog_handle.xml new file mode 100644 index 00000000..3e5c12fc --- /dev/null +++ b/app/src/main/res/drawable/ic_dialog_handle.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/dialog_datepicker.xml b/app/src/main/res/layout/dialog_datepicker.xml index add0c289..462c9e72 100644 --- a/app/src/main/res/layout/dialog_datepicker.xml +++ b/app/src/main/res/layout/dialog_datepicker.xml @@ -6,6 +6,15 @@ android:layout_height="wrap_content" android:layout_margin="20dp"> + + Date: Fri, 20 Sep 2024 22:02:28 +0900 Subject: [PATCH 8/8] =?UTF-8?q?build=20:=20mvvm=20=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/view/schedule/DatePickerDialog.kt | 46 ++++++++------ .../ui/view/schedule/ScheduleClickListener.kt | 7 +++ .../ui/view/schedule/ScheduleFragment.kt | 61 +++++++++++-------- .../ui/view/schedule/ScheduleViewModel.kt | 10 +-- 4 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleClickListener.kt diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt index ed22f8cb..89d625c9 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/DatePickerDialog.kt @@ -5,27 +5,24 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.WindowManager import android.widget.NumberPicker -import androidx.fragment.app.DialogFragment +import androidx.fragment.app.activityViewModels import com.dongyang.android.youdongknowme.R import com.dongyang.android.youdongknowme.databinding.DialogDatepickerBinding import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import org.koin.androidx.viewmodel.ext.android.viewModel +import com.prolificinteractive.materialcalendarview.CalendarDay import org.threeten.bp.LocalDate class DatePickerDialog( - val year: Int, - val month: Int, - private val dateSelectedListener: ScheduleFragment, + private val year: Int, + private val month: Int, + private val listener: ScheduleClickListener ) : BottomSheetDialogFragment() { private var _binding: DialogDatepickerBinding? = null private val binding get() = _binding!! - private val viewModel: ScheduleViewModel by viewModel() - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -52,7 +49,9 @@ class DatePickerDialog( with(binding.numberpickerDialogDatepickerYear) { minValue = currentYear - 1 maxValue = currentYear + 1 - displayedValues=((minValue..maxValue).map{"$it 년"}.toTypedArray()) + displayedValues = + ((minValue..maxValue).map { "$it${getString(R.string.calendar_year)}" } + .toTypedArray()) } // 월 최소/최대값 설정 및 출력 방식 설정 @@ -65,29 +64,36 @@ class DatePickerDialog( maxValue = if (newYear == currentYear + 1) 2 else 12 } - displayedValues=((minValue..maxValue).map{"$it 월"}.toTypedArray()) + displayedValues = + ((minValue..maxValue).map { "$it${getString(R.string.calendar_month)}" } + .toTypedArray()) } // 초기 설정 binding.numberpickerDialogDatepickerYear.value = year binding.numberpickerDialogDatepickerMonth.value = month + return view + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + + super.onViewCreated(view, savedInstanceState) + binding.tvDialogPermissionComplete.setOnClickListener { - viewModel.setDatePicker( - binding.numberpickerDialogDatepickerYear.value, - binding.numberpickerDialogDatepickerMonth.value - ) - dateSelectedListener.onDateSelected( - binding.numberpickerDialogDatepickerYear.value, - binding.numberpickerDialogDatepickerMonth.value - ) + val year = binding.numberpickerDialogDatepickerYear.value + val month = binding.numberpickerDialogDatepickerMonth.value + val date = CalendarDay.from(year, month, 1) + + listener.buttonClick(date = date) + dismiss() } - - return view } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + return BottomSheetDialog(requireContext(), R.style.CustomBottomSheetDialogTheme) } diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleClickListener.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleClickListener.kt new file mode 100644 index 00000000..869a6291 --- /dev/null +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleClickListener.kt @@ -0,0 +1,7 @@ +package com.dongyang.android.youdongknowme.ui.view.schedule + +import com.prolificinteractive.materialcalendarview.CalendarDay + +interface ScheduleClickListener { + fun buttonClick(date: CalendarDay) +} diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt index 9a2942e7..34038d32 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleFragment.kt @@ -13,13 +13,9 @@ import com.prolificinteractive.materialcalendarview.CalendarDay import org.koin.androidx.viewmodel.ext.android.viewModel import org.threeten.bp.LocalDate -interface OnDateSelectedListener { - fun onDateSelected(year: Int, month: Int) -} - /* 학사 일정 화면 */ class ScheduleFragment : BaseFragment(), - OnDateSelectedListener { + ScheduleClickListener { override val layoutResourceId: Int = R.layout.fragment_schedule override val viewModel: ScheduleViewModel by viewModel() @@ -32,12 +28,27 @@ class ScheduleFragment : BaseFragment + val inputText: LocalDate = day.date + val calendarHeaderElements = inputText.toString().split("-").toTypedArray() + + year = calendarHeaderElements[0] + month = calendarHeaderElements[1] - // 선택된 연도와 월을 사용하여 CalendarView 업데이트 - val date = CalendarDay.from(year, month, 1) - binding.mvScheduleCalendar.currentDate = date - binding.mvScheduleCalendar.setCurrentDate(date, true) + val calendarHeaderBuilder = StringBuilder() + calendarHeaderBuilder.append(year) + .append(getString(R.string.calendar_year)) + .append(" ") + .append(month) + .append(getString(R.string.calendar_month)) + calendarHeaderBuilder.toString() + } } override fun initStartView() { @@ -90,6 +101,10 @@ class ScheduleFragment : BaseFragment + updateCalendarViewHeader(date) + } + viewModel.scheduleList.observe(viewLifecycleOwner) { adapter.submitList(it) } @@ -99,6 +114,13 @@ class ScheduleFragment : BaseFragment @@ -109,7 +131,7 @@ class ScheduleFragment : BaseFragment - val inputText: LocalDate = day.date - val calendarHeaderElements = inputText.toString().split("-").toTypedArray() - - year = calendarHeaderElements[0] - month = calendarHeaderElements[1] - - val calendarHeaderBuilder = StringBuilder() - calendarHeaderBuilder.append(year) - .append(getString(R.string.calendar_year)) - .append(" ") - .append(month) - .append(getString(R.string.calendar_month)) - calendarHeaderBuilder.toString() - } + setCalenderHeader() } } diff --git a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleViewModel.kt b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleViewModel.kt index cd48fc28..8b4c045b 100644 --- a/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleViewModel.kt +++ b/app/src/main/java/com/dongyang/android/youdongknowme/ui/view/schedule/ScheduleViewModel.kt @@ -36,14 +36,14 @@ class ScheduleViewModel(private val scheduleRepository: ScheduleRepository) : Ba private val _pickMonth = MutableLiveData() val pickMonth: LiveData = _pickMonth + private val _selectedDate = MutableLiveData() + val selectedDate: LiveData = _selectedDate + fun setPickedDate(date: CalendarDay) { + _selectedDate.value = date _pickYear.value = date.year _pickMonth.value = date.month - } - - fun setDatePicker(year: Int, month: Int) { - _pickYear.value = year - _pickMonth.value = month + getSchedules() } fun getSchedules() {