-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from itsLeonB/posyandu
Update Jadwal Posyandu layout
- Loading branch information
Showing
29 changed files
with
2,073 additions
and
1,064 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/example/posyandu/JadwalKonsultasiBidanFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.example.posyandu | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
|
||
// TODO: Rename parameter arguments, choose names that match | ||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | ||
private const val ARG_PARAM1 = "param1" | ||
private const val ARG_PARAM2 = "param2" | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
* Use the [JadwalKonsultasiBidanFragment.newInstance] factory method to | ||
* create an instance of this fragment. | ||
*/ | ||
class JadwalKonsultasiBidanFragment : Fragment() { | ||
// TODO: Rename and change types of parameters | ||
private var param1: String? = null | ||
private var param2: String? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
arguments?.let { | ||
param1 = it.getString(ARG_PARAM1) | ||
param2 = it.getString(ARG_PARAM2) | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_jadwal_konsultasi_bidan, container, false) | ||
} | ||
|
||
companion object { | ||
/** | ||
* Use this factory method to create a new instance of | ||
* this fragment using the provided parameters. | ||
* | ||
* @param param1 Parameter 1. | ||
* @param param2 Parameter 2. | ||
* @return A new instance of fragment JadwalKonsultasiBidanFragment. | ||
*/ | ||
// TODO: Rename and change types and number of parameters | ||
@JvmStatic | ||
fun newInstance(param1: String, param2: String) = | ||
JadwalKonsultasiBidanFragment().apply { | ||
arguments = Bundle().apply { | ||
putString(ARG_PARAM1, param1) | ||
putString(ARG_PARAM2, param2) | ||
} | ||
} | ||
} | ||
} |
205 changes: 205 additions & 0 deletions
205
app/src/main/java/com/example/posyandu/JadwalPosyanduFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
package com.example.posyandu | ||
|
||
import android.os.Build | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import androidx.annotation.RequiresApi | ||
import androidx.fragment.app.Fragment | ||
import com.google.android.material.card.MaterialCardView | ||
import com.google.android.material.datepicker.CalendarConstraints | ||
import com.google.android.material.datepicker.MaterialDatePicker | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton | ||
import com.google.android.material.textfield.TextInputEditText | ||
import com.google.android.material.timepicker.MaterialTimePicker | ||
import com.google.android.material.timepicker.TimeFormat | ||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.util.TimeZone | ||
|
||
class JadwalPosyanduFragment : Fragment() { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View? { | ||
return inflater.inflate(R.layout.fragment_jadwal_posyandu, container, false) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val btnTambah: ExtendedFloatingActionButton = view.findViewById(R.id.btn_tambah) | ||
val cardJadwal: MaterialCardView = view.findViewById(R.id.card_jadwal_1) | ||
|
||
btnTambah.setOnClickListener { | ||
showAlertDialog() | ||
} | ||
|
||
cardJadwal.setOnClickListener { | ||
showViewDialog() | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun showViewDialog() { | ||
val customView = | ||
LayoutInflater.from(requireContext()).inflate(R.layout.fragment_ubah_jadwal, null) | ||
|
||
MaterialAlertDialogBuilder(requireContext()) | ||
.setView(customView) | ||
.show() | ||
|
||
val btnTambah: Button = customView.findViewById(R.id.btn_tambah) | ||
|
||
val editJadwal: TextInputEditText = customView.findViewById(R.id.jam_2_edit) | ||
|
||
editJadwal.setOnClickListener { | ||
showEditDialog() | ||
} | ||
|
||
btnTambah.setOnClickListener { | ||
showAlertDialog() | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun showEditDialog() { | ||
val customView = | ||
LayoutInflater.from(requireContext()).inflate(R.layout.fragment_edit_jadwal, null) | ||
val tanggalEdit: TextInputEditText = customView.findViewById(R.id.tanggal_edit) | ||
val jamMulaiEdit: TextInputEditText = customView.findViewById(R.id.jam_mulai_edit) | ||
val jamSelesaiEdit: TextInputEditText = customView.findViewById(R.id.jam_selesai_edit) | ||
|
||
val today = MaterialDatePicker.todayInUtcMilliseconds() | ||
|
||
val constraintsBuilder = | ||
CalendarConstraints.Builder() | ||
.setStart(today) | ||
|
||
val datePicker = | ||
MaterialDatePicker.Builder.datePicker() | ||
.setCalendarConstraints(constraintsBuilder.build()) | ||
.setSelection(today) | ||
.setTitleText("Pilih tanggal") | ||
.build() | ||
|
||
datePicker.addOnPositiveButtonClickListener { | ||
val dateTime = LocalDateTime.ofInstant( | ||
datePicker.selection?.let { it1 -> Instant.ofEpochMilli(it1) }, | ||
TimeZone.getDefault().toZoneId() | ||
) | ||
val formatter = DateTimeFormatter.ofPattern("dd MMM YY") | ||
val formattedDate = dateTime.format(formatter) | ||
tanggalEdit.setText(formattedDate) | ||
} | ||
|
||
var selectedEditText: TextInputEditText? = null | ||
|
||
val timePicker = | ||
MaterialTimePicker.Builder() | ||
.setTimeFormat(TimeFormat.CLOCK_12H) | ||
.setHour(12) | ||
.setMinute(10) | ||
.setTitleText("Pilih jam mulai") | ||
.build() | ||
|
||
timePicker.addOnPositiveButtonClickListener { | ||
// Handle the selected time | ||
val selectedTime = String.format("%02d:%02d", timePicker.hour, timePicker.minute) | ||
|
||
// Set the selected time to the appropriate EditText | ||
selectedEditText?.setText(selectedTime) | ||
} | ||
|
||
tanggalEdit.setOnClickListener { | ||
datePicker.show(parentFragmentManager, datePicker.toString()) | ||
} | ||
|
||
jamMulaiEdit.setOnClickListener { | ||
selectedEditText = jamMulaiEdit | ||
timePicker.show(parentFragmentManager, timePicker.toString()) | ||
} | ||
|
||
jamSelesaiEdit.setOnClickListener { | ||
selectedEditText = jamSelesaiEdit | ||
timePicker.show(parentFragmentManager, timePicker.toString()) | ||
} | ||
|
||
MaterialAlertDialogBuilder(requireContext()) | ||
.setView(customView) | ||
.show() | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.O) | ||
private fun showAlertDialog() { | ||
val customView = | ||
LayoutInflater.from(requireContext()).inflate(R.layout.fragment_tambah_jadwal, null) | ||
val tanggalEdit: TextInputEditText = customView.findViewById(R.id.tanggal_edit) | ||
val jamMulaiEdit: TextInputEditText = customView.findViewById(R.id.jam_mulai_edit) | ||
val jamSelesaiEdit: TextInputEditText = customView.findViewById(R.id.jam_selesai_edit) | ||
|
||
val today = MaterialDatePicker.todayInUtcMilliseconds() | ||
|
||
val constraintsBuilder = | ||
CalendarConstraints.Builder() | ||
.setStart(today) | ||
|
||
val datePicker = | ||
MaterialDatePicker.Builder.datePicker() | ||
.setCalendarConstraints(constraintsBuilder.build()) | ||
.setSelection(today) | ||
.setTitleText("Pilih tanggal") | ||
.build() | ||
|
||
datePicker.addOnPositiveButtonClickListener { | ||
val dateTime = LocalDateTime.ofInstant( | ||
datePicker.selection?.let { it1 -> Instant.ofEpochMilli(it1) }, | ||
TimeZone.getDefault().toZoneId() | ||
) | ||
val formatter = DateTimeFormatter.ofPattern("dd MMM YY") | ||
val formattedDate = dateTime.format(formatter) | ||
tanggalEdit.setText(formattedDate) | ||
} | ||
|
||
var selectedEditText: TextInputEditText? = null | ||
|
||
val timePicker = | ||
MaterialTimePicker.Builder() | ||
.setTimeFormat(TimeFormat.CLOCK_12H) | ||
.setHour(12) | ||
.setMinute(10) | ||
.setTitleText("Pilih jam mulai") | ||
.build() | ||
|
||
timePicker.addOnPositiveButtonClickListener { | ||
// Handle the selected time | ||
val selectedTime = String.format("%02d:%02d", timePicker.hour, timePicker.minute) | ||
|
||
// Set the selected time to the appropriate EditText | ||
selectedEditText?.setText(selectedTime) | ||
} | ||
|
||
tanggalEdit.setOnClickListener { | ||
datePicker.show(parentFragmentManager, datePicker.toString()) | ||
} | ||
|
||
jamMulaiEdit.setOnClickListener { | ||
selectedEditText = jamMulaiEdit | ||
timePicker.show(parentFragmentManager, timePicker.toString()) | ||
} | ||
|
||
jamSelesaiEdit.setOnClickListener { | ||
selectedEditText = jamSelesaiEdit | ||
timePicker.show(parentFragmentManager, timePicker.toString()) | ||
} | ||
|
||
MaterialAlertDialogBuilder(requireContext()) | ||
.setView(customView) | ||
.show() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.