From 69c2be9f524a4a603789a1c4075320cede3c55e5 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Tue, 22 Aug 2023 06:59:42 +0530 Subject: [PATCH 01/10] new request data classes and end point --- .../java/one/njk/celestidesk/domain/NewBreakRequest.kt | 10 ++++++++++ .../java/one/njk/celestidesk/network/ApiService.kt | 7 ++++++- .../one/njk/celestidesk/network/DataTransferObjects.kt | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/one/njk/celestidesk/domain/NewBreakRequest.kt diff --git a/app/src/main/java/one/njk/celestidesk/domain/NewBreakRequest.kt b/app/src/main/java/one/njk/celestidesk/domain/NewBreakRequest.kt new file mode 100644 index 0000000..758a6f2 --- /dev/null +++ b/app/src/main/java/one/njk/celestidesk/domain/NewBreakRequest.kt @@ -0,0 +1,10 @@ +package one.njk.celestidesk.domain + +import kotlinx.datetime.LocalDateTime +import one.njk.celestidesk.network.Stage + +data class NewBreakRequest( + val message: String, + val status: Stage, + val date: LocalDateTime +) diff --git a/app/src/main/java/one/njk/celestidesk/network/ApiService.kt b/app/src/main/java/one/njk/celestidesk/network/ApiService.kt index 1d7ce70..3aff24d 100644 --- a/app/src/main/java/one/njk/celestidesk/network/ApiService.kt +++ b/app/src/main/java/one/njk/celestidesk/network/ApiService.kt @@ -47,5 +47,10 @@ interface ApiService { @Header("Authorization") token: String, ): NetworkTransactionsContainer - + @GET("api/request/create") + suspend fun createNewRequest( + @Header("Authorization") token: String, + @Body request: NetworkNewRequest + ): Message + // TODO: Wrap message with sealed class } diff --git a/app/src/main/java/one/njk/celestidesk/network/DataTransferObjects.kt b/app/src/main/java/one/njk/celestidesk/network/DataTransferObjects.kt index 2725348..1d34a8d 100644 --- a/app/src/main/java/one/njk/celestidesk/network/DataTransferObjects.kt +++ b/app/src/main/java/one/njk/celestidesk/network/DataTransferObjects.kt @@ -120,4 +120,8 @@ fun NetworkTransactionsContainer.asDatabaseModel(): List { // --------------------- Transaction Model [ENDS] -------------------------- // -// TODO: Add database, domain models, mappers and a fragment with a view to show transaction (only Manager & Teamlead) +data class NetworkNewRequest( + val message: String, + val status: Stage, + val date: String, +) From fdf744ffab9e99f811a5a6978ee6348254f75e51 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Tue, 22 Aug 2023 08:44:47 +0530 Subject: [PATCH 02/10] bottom sheet for creating new requests --- .../one/njk/celestidesk/ui/NewRequestSheet.kt | 25 +++++ .../one/njk/celestidesk/ui/RequestFragment.kt | 10 +- app/src/main/res/drawable/chat.xml | 4 + app/src/main/res/drawable/convo.xml | 4 + app/src/main/res/drawable/date_range.xml | 4 + app/src/main/res/layout/new_request_sheet.xml | 98 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 + 7 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt create mode 100644 app/src/main/res/drawable/chat.xml create mode 100644 app/src/main/res/drawable/convo.xml create mode 100644 app/src/main/res/drawable/date_range.xml create mode 100644 app/src/main/res/layout/new_request_sheet.xml diff --git a/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt new file mode 100644 index 0000000..6ba91a2 --- /dev/null +++ b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt @@ -0,0 +1,25 @@ +package one.njk.celestidesk.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import one.njk.celestidesk.databinding.NewRequestSheetBinding + +class NewRequestSheet: BottomSheetDialogFragment() { + + private var _binding: NewRequestSheetBinding? = null + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = NewRequestSheetBinding.inflate(inflater, container, false) + return _binding!!.root + } + companion object { + const val TAG = "NewRequestBottomSheet" + } +} \ No newline at end of file diff --git a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt index 952e95a..72565ce 100644 --- a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt +++ b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt @@ -99,7 +99,10 @@ class RequestFragment : Fragment() { if(currentRole != Role.EMPLOYEE) findNavController() .navigate(RequestFragmentDirections.actionRequestFragmentToSearchFragment()) - // TODO: Create a new requests screen + else { + val requestSheet = NewRequestSheet() + requestSheet.show(childFragmentManager, NewRequestSheet.TAG) + } } } @@ -171,7 +174,4 @@ class RequestFragment : Fragment() { } .show() } -} -// TODO: Profile Pic for users -// TODO: >5 Request, it goes to Manager directly -// TODO: 20min expiry after reaching manager \ No newline at end of file +} \ No newline at end of file diff --git a/app/src/main/res/drawable/chat.xml b/app/src/main/res/drawable/chat.xml new file mode 100644 index 0000000..f846db8 --- /dev/null +++ b/app/src/main/res/drawable/chat.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/convo.xml b/app/src/main/res/drawable/convo.xml new file mode 100644 index 0000000..ec98d21 --- /dev/null +++ b/app/src/main/res/drawable/convo.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/drawable/date_range.xml b/app/src/main/res/drawable/date_range.xml new file mode 100644 index 0000000..1adb423 --- /dev/null +++ b/app/src/main/res/drawable/date_range.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/new_request_sheet.xml b/app/src/main/res/layout/new_request_sheet.xml new file mode 100644 index 0000000..9e36235 --- /dev/null +++ b/app/src/main/res/layout/new_request_sheet.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 4bacc1d..bfa284b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,4 +58,7 @@ Logout Search New Request + Subject + Reason + Duration \ No newline at end of file From f693c5cce65d2977a3a13544345f7c50a6f0a312 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Thu, 24 Aug 2023 01:02:33 +0530 Subject: [PATCH 03/10] added date picker --- .../one/njk/celestidesk/ui/NewRequestSheet.kt | 42 +++++++++++++++++-- .../one/njk/celestidesk/ui/RequestFragment.kt | 22 +++++++++- app/src/main/res/layout/new_request_sheet.xml | 7 ++-- 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt index 6ba91a2..36f43d9 100644 --- a/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt +++ b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt @@ -1,15 +1,22 @@ package one.njk.celestidesk.ui +import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.inputmethod.InputMethodManager +import androidx.core.util.Pair import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.google.android.material.datepicker.MaterialDatePicker +import kotlinx.datetime.Instant +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toLocalDateTime import one.njk.celestidesk.databinding.NewRequestSheetBinding -class NewRequestSheet: BottomSheetDialogFragment() { +class NewRequestSheet(val datePicker: () -> Unit): BottomSheetDialogFragment() { - private var _binding: NewRequestSheetBinding? = null + private lateinit var _binding: NewRequestSheetBinding override fun onCreateView( inflater: LayoutInflater, @@ -17,7 +24,36 @@ class NewRequestSheet: BottomSheetDialogFragment() { savedInstanceState: Bundle? ): View { _binding = NewRequestSheetBinding.inflate(inflater, container, false) - return _binding!!.root + return _binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val inputMethodManager = + requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + + _binding.durationEdit.setOnFocusChangeListener { editText, hasFocus -> + if(hasFocus){ + datePicker() + } + inputMethodManager.hideSoftInputFromWindow(editText.windowToken, 0) + } + } + + fun updateDateRange(range: Pair?) { + val from = Instant + .fromEpochMilliseconds( + range?.first ?: MaterialDatePicker.todayInUtcMilliseconds() + ).toLocalDateTime(TimeZone.UTC).date.toString() + + val to = Instant + .fromEpochMilliseconds( + range?.second ?: (MaterialDatePicker.todayInUtcMilliseconds() + 86_400_000L) + ).toLocalDateTime(TimeZone.UTC).date.toString() + // (24 hours * 60 minutes * 60 seconds * 1000 milliseconds) + + _binding.duration.editText?.setText("$from - $to") } companion object { const val TAG = "NewRequestBottomSheet" diff --git a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt index 72565ce..f7a6d4d 100644 --- a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt +++ b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt @@ -12,6 +12,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup +import com.google.android.material.datepicker.MaterialDatePicker import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope @@ -30,6 +31,7 @@ import one.njk.celestidesk.viewmodels.ManagerViewModel import one.njk.celestidesk.viewmodels.RoleAgreement import one.njk.celestidesk.viewmodels.TeamLeadViewModel import javax.inject.Inject +import androidx.core.util.Pair /** * A simple [Fragment] subclass as the default destination in the navigation. @@ -77,6 +79,14 @@ class RequestFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val dateRangePicker = MaterialDatePicker.Builder.dateRangePicker() + .setTitleText("Select dates") + .build() + + val requestSheet = NewRequestSheet { + dateRangePicker.show(childFragmentManager, "DATE_PICK") + } + lifecycleScope.launch { _binding!!.role.text = viewModel.name _binding!!.fab.setIconResource(fabIcon) @@ -100,8 +110,18 @@ class RequestFragment : Fragment() { findNavController() .navigate(RequestFragmentDirections.actionRequestFragmentToSearchFragment()) else { - val requestSheet = NewRequestSheet() requestSheet.show(childFragmentManager, NewRequestSheet.TAG) + dateRangePicker.addOnDismissListener { + requestSheet.updateDateRange(dateRangePicker.selection) + } + + /* TODO: add date selection constraints (restrict past dates) + * https://m3.material.io/components/date-pickers/overview + * https://github.com/material-components/material-components-android/blob/master/docs/components/DatePicker.md + * + * TODO: override onCancel & onDismiss of model sheet (dialogue interface) to send save req + * https://github.com/material-components/material-components-android/blob/master/docs/components/BottomSheet.md + * */ } } diff --git a/app/src/main/res/layout/new_request_sheet.xml b/app/src/main/res/layout/new_request_sheet.xml index 9e36235..2dcdec6 100644 --- a/app/src/main/res/layout/new_request_sheet.xml +++ b/app/src/main/res/layout/new_request_sheet.xml @@ -42,7 +42,7 @@ android:layout_height="wrap_content" android:imeOptions="actionNext" - android:inputType="textMultiLine|text" + android:inputType="text" tools:text="Visit home for festival" /> @@ -65,7 +65,7 @@ android:layout_height="wrap_content" android:imeOptions="actionNext" - android:inputType="textMultiLine|text" + android:inputType="text" tools:text="Once in a while, like a human, I need to get out of my home" /> @@ -84,10 +84,11 @@ app:startIconDrawable="@drawable/date_range"> + android:inputType="none"/> From 3d5bcd5c635ec61f9b49ea8e1257735f35846187 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Thu, 24 Aug 2023 23:07:34 +0530 Subject: [PATCH 04/10] date picker starts from this month --- .../java/one/njk/celestidesk/ui/RequestFragment.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt index f7a6d4d..4bd17bf 100644 --- a/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt +++ b/app/src/main/java/one/njk/celestidesk/ui/RequestFragment.kt @@ -12,6 +12,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.google.android.material.chip.Chip import com.google.android.material.chip.ChipGroup +import com.google.android.material.datepicker.CalendarConstraints import com.google.android.material.datepicker.MaterialDatePicker import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint @@ -31,7 +32,6 @@ import one.njk.celestidesk.viewmodels.ManagerViewModel import one.njk.celestidesk.viewmodels.RoleAgreement import one.njk.celestidesk.viewmodels.TeamLeadViewModel import javax.inject.Inject -import androidx.core.util.Pair /** * A simple [Fragment] subclass as the default destination in the navigation. @@ -79,8 +79,12 @@ class RequestFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val calendarConstraints = CalendarConstraints.Builder() + .setStart(MaterialDatePicker.todayInUtcMilliseconds()) + val dateRangePicker = MaterialDatePicker.Builder.dateRangePicker() .setTitleText("Select dates") + .setCalendarConstraints(calendarConstraints.build()) .build() val requestSheet = NewRequestSheet { @@ -115,12 +119,11 @@ class RequestFragment : Fragment() { requestSheet.updateDateRange(dateRangePicker.selection) } - /* TODO: add date selection constraints (restrict past dates) - * https://m3.material.io/components/date-pickers/overview - * https://github.com/material-components/material-components-android/blob/master/docs/components/DatePicker.md - * + /* * TODO: override onCancel & onDismiss of model sheet (dialogue interface) to send save req * https://github.com/material-components/material-components-android/blob/master/docs/components/BottomSheet.md + * + * TODO: Add Emergency / Regular Request button * */ } } From fba468aa9414b2d351af3526256346285371c7d0 Mon Sep 17 00:00:00 2001 From: nijuyonkadesu <24ksriramv@gmail.com> Date: Thu, 24 Aug 2023 23:51:12 +0530 Subject: [PATCH 05/10] add toggle for normal and emergency request --- .../one/njk/celestidesk/ui/NewRequestSheet.kt | 1 + app/src/main/res/drawable/send.xml | 4 ++ app/src/main/res/layout/new_request_sheet.xml | 65 ++++++++++++++++++- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/send.xml diff --git a/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt index 36f43d9..e45ed80 100644 --- a/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt +++ b/app/src/main/java/one/njk/celestidesk/ui/NewRequestSheet.kt @@ -33,6 +33,7 @@ class NewRequestSheet(val datePicker: () -> Unit): BottomSheetDialogFragment() { val inputMethodManager = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + _binding.normal.performClick() _binding.durationEdit.setOnFocusChangeListener { editText, hasFocus -> if(hasFocus){ datePicker() diff --git a/app/src/main/res/drawable/send.xml b/app/src/main/res/drawable/send.xml new file mode 100644 index 0000000..157e92f --- /dev/null +++ b/app/src/main/res/drawable/send.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/new_request_sheet.xml b/app/src/main/res/layout/new_request_sheet.xml index 2dcdec6..d82814d 100644 --- a/app/src/main/res/layout/new_request_sheet.xml +++ b/app/src/main/res/layout/new_request_sheet.xml @@ -22,7 +22,56 @@ + android:paddingVertical="16dp"> + + + + + + + +