Skip to content

Commit

Permalink
Merge pull request #4 from itsLeonB/posyandu
Browse files Browse the repository at this point in the history
Update Jadwal Posyandu layout
  • Loading branch information
mauritzmauritz authored Dec 14, 2023
2 parents 61d3c40 + 1e1d3a5 commit b3305ab
Show file tree
Hide file tree
Showing 29 changed files with 2,073 additions and 1,064 deletions.
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

15 changes: 14 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Posyandu"
android:theme="@style/Base.Theme.Posyandu"
tools:targetApi="31">
<activity
android:name=".SandiBaruActivity"
Expand Down
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 app/src/main/java/com/example/posyandu/JadwalPosyanduFragment.kt
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ private const val ARG_PARAM2 = "param2"

/**
* A simple [Fragment] subclass.
* Use the [ChatFragment.newInstance] factory method to
* Use the [KonsultasiFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class ChatFragment : Fragment() {
class KonsultasiFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
Expand All @@ -31,10 +31,10 @@ class ChatFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_chat, container, false)
return inflater.inflate(R.layout.fragment_konsultasi, container, false)
}

companion object {
Expand All @@ -44,12 +44,12 @@ class ChatFragment : Fragment() {
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ChatFragment.
* @return A new instance of fragment KonsultasiFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
ChatFragment().apply {
KonsultasiFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
Expand Down
18 changes: 4 additions & 14 deletions app/src/main/java/com/example/posyandu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ package com.example.posyandu
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.posyandu.ChatFragment
import com.example.posyandu.HomeFragment
import com.example.posyandu.MateriFragment
import com.example.posyandu.PosyanduFragment
import com.example.posyandu.ProfileFragment
import com.example.posyandu.R
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.navigation.NavigationBarView

Expand All @@ -35,18 +29,14 @@ class MainActivity : AppCompatActivity() {
// selected fragment by using there id
lateinit var selectedFragment: Fragment
when (it.itemId) {
R.id.materi -> {
selectedFragment = MateriFragment()
}

R.id.chat -> {
selectedFragment = ChatFragment()
}

R.id.home -> {
selectedFragment = HomeFragment()
}

R.id.konsultasi -> {
selectedFragment = KonsultasiFragment()
}

R.id.posyandu -> {
selectedFragment = PosyanduFragment()
}
Expand Down
Loading

0 comments on commit b3305ab

Please sign in to comment.