Skip to content

Commit

Permalink
Merge pull request #10 from itsLeonB/moritZ
Browse files Browse the repository at this point in the history
Morit z
  • Loading branch information
BonaventuraD authored Dec 20, 2023
2 parents 189275d + 1792114 commit 728cd3c
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 117 deletions.
24 changes: 20 additions & 4 deletions app/src/main/java/com/example/posyandu/HomeFragmentBidan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class HomeFragmentBidan: Fragment() {
super.onViewCreated(view, savedInstanceState)

val cardJadwalTerdekat: MaterialCardView = view.findViewById(R.id.jadwalterdekatbidan)

val btnSettings: Button = view.findViewById(R.id.btn_settings)
val cardJadwalPosyandu: MaterialCardView = view.findViewById(R.id.card_jadwal_posyandu)
val btnInput: ExtendedFloatingActionButton = view.findViewById(R.id.btn_input)
val cardDashboard: MaterialCardView = view.findViewById(R.id.dashboardHomeBidan)
// val cardChatTerbaru: MaterialCardView = view.findViewById(R.id.chatterbarubidan)

cardJadwalTerdekat.setOnClickListener { v: View ->
requireActivity().supportFragmentManager
Expand All @@ -50,6 +48,24 @@ class HomeFragmentBidan: Fragment() {
.commit()
}

cardDashboard.setOnClickListener { v: View ->
requireActivity().supportFragmentManager
.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.fragment_container, DaftarRemajaFragment())
.addToBackStack(null)
.commit()
}

// cardChatTerbaru.setOnClickListener { v: View ->
// requireActivity().supportFragmentManager
// .beginTransaction()
// .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
// .replace(R.id.fragment_container, ChatFragment())
// .addToBackStack(null)
// .commit()
// }


}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/posyandu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MainActivity : AppCompatActivity() {
// as soon as the application opens the first fragment should
// be shown to the user in this case it is algorithm fragment
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, HomeFragment()).commit()
.replace(R.id.fragment_container, HomeFragmentBidan()).commit()
}

private val navListener = NavigationBarView.OnItemSelectedListener {
Expand All @@ -30,7 +30,7 @@ class MainActivity : AppCompatActivity() {
lateinit var selectedFragment: Fragment
when (it.itemId) {
R.id.home -> {
selectedFragment = HomeFragment()
selectedFragment = HomeFragmentBidan()
}

R.id.konsultasi -> {
Expand Down
167 changes: 129 additions & 38 deletions app/src/main/java/com/example/posyandu/ProfileFragment.kt
Original file line number Diff line number Diff line change
@@ -1,59 +1,150 @@
package com.example.posyandu

import android.os.Build
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AutoCompleteTextView
import android.widget.Button
import androidx.activity.OnBackPressedCallback
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputEditText

// 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 [ProfileFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class ProfileFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null

private lateinit var editNama: TextInputEditText
private lateinit var editEmail: TextInputEditText
private lateinit var editNIK: TextInputEditText
private lateinit var editTTL: TextInputEditText
private lateinit var editAlamat: TextInputEditText
private lateinit var editProvinsi: AutoCompleteTextView
private lateinit var editKota: AutoCompleteTextView
private lateinit var editKecamatan: AutoCompleteTextView
private lateinit var editKelurahan: AutoCompleteTextView
private lateinit var editKodePos: TextInputEditText
private lateinit var editRT: TextInputEditText
private lateinit var editRW: TextInputEditText
private lateinit var editNotelp: TextInputEditText
private lateinit var BtnSaveChanges: MaterialButton
private lateinit var BtnEditProfile: MaterialButton
private var isEditMode = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
activity?.onBackPressedDispatcher?.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
// in here you can do logic when backPress is clicked
parentFragmentManager.popBackStack()
}
})
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile, 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 ProfileFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
ProfileFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
@RequiresApi(Build.VERSION_CODES.O)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

editNama = view.findViewById(R.id.editNama)
editEmail = view.findViewById(R.id.editEmail)
editNIK = view.findViewById(R.id.editNIK)
editTTL = view.findViewById(R.id.editTTL)
editAlamat = view.findViewById(R.id.editAlamat)
editProvinsi = view.findViewById(R.id.editProvinsi)
editKota = view.findViewById(R.id.editKota)
editKecamatan = view.findViewById(R.id.editKecamatan)
editKelurahan = view.findViewById(R.id.editKelurahan)
editKodePos = view.findViewById(R.id.editKodePos)
editRT = view.findViewById(R.id.editRT)
editRW = view.findViewById(R.id.editRW)
editNotelp = view.findViewById(R.id.editNotelp)
BtnEditProfile = view.findViewById(R.id.buttonedit)
BtnSaveChanges = view.findViewById(R.id.buttonSaveChanges)

BtnEditProfile.setOnClickListener {
toggleEditMode()
}

BtnSaveChanges.setOnClickListener {
toggleEditMode()

val btmBar = activity?.findViewById<BottomNavigationView>(
R.id.bottom_navigation
)

Snackbar.make(
btmBar!!,
"Profil berhasil diperbarui.",
Snackbar.LENGTH_SHORT
).setAnchorView(btmBar)
.show()
}

}

private fun toggleEditMode() {
isEditMode = !isEditMode

if (isEditMode) {
// Switch to "Cancel Edit" mode
BtnEditProfile.text = "Cancel Edit"
BtnEditProfile.setBackgroundColor(
ContextCompat.getColor(
requireContext(),
R.color.md_theme_light_error
)
)
BtnSaveChanges.visibility = View.VISIBLE

// Enable EditText views
editAlamat.isEnabled = true
editProvinsi.isEnabled = true
editKota.isEnabled = true
editKecamatan.isEnabled = true
editKelurahan.isEnabled = true
editKodePos.isEnabled = true
editRT.isEnabled = true
editRW.isEnabled = true
editNotelp.isEnabled = true

// Enable other EditText views as needed
} else {
// Switch back to "Edit Profile" mode
BtnEditProfile.text = "Edit Profile"
BtnEditProfile.setBackgroundColor(
ContextCompat.getColor(
requireContext(),
R.color.md_theme_light_primary
)
)
BtnSaveChanges.visibility = View.GONE

// Disable EditText views
editAlamat.isEnabled = false
editProvinsi.isEnabled = false
editKota.isEnabled = false
editKecamatan.isEnabled = false
editKelurahan.isEnabled = false
editKodePos.isEnabled = false
editRT.isEnabled = false
editRW.isEnabled = false
editNotelp.isEnabled = false
// Disable other EditText views as needed
}
}

}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/fragment_chat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ChatFragment">


</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 3 additions & 5 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardCornerRadius="12dp"
app:layout_constraintTop_toBottomOf="@+id/namaUser"
android:layout_marginBottom="20dp">
android:layout_marginVertical="20dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -260,10 +259,9 @@
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardCornerRadius="12dp"
app:layout_constraintTop_toBottomOf="@id/dashboardHomeBidan"
android:layout_marginBottom="20dp">
android:layout_marginVertical="20dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/barisjuduljadwal"
Expand Down Expand Up @@ -434,7 +432,7 @@
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginVertical="20dp"
app:cardCornerRadius="12dp"
app:layout_constraintTop_toBottomOf="@id/jadwalterdekatbidan"
>
Expand Down
Loading

0 comments on commit 728cd3c

Please sign in to comment.