-
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 #10 from itsLeonB/moritZ
Morit z
- Loading branch information
Showing
7 changed files
with
427 additions
and
117 deletions.
There are no files selected for viewing
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
167 changes: 129 additions & 38 deletions
167
app/src/main/java/com/example/posyandu/ProfileFragment.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 |
---|---|---|
@@ -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 | ||
} | ||
} | ||
|
||
} |
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,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> |
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.