32 private TextView tvNombre, tvLastname, tvEmail, tvPhone;
35 private Button btnSaveChanges;
42 public View
onCreateView(LayoutInflater inflater, ViewGroup container,
43 Bundle savedInstanceState) {
46 View view = inflater.inflate(R.layout.fragment_edit_profile, container,
false);
49 tvNombre = view.findViewById(R.id.edit_name);
50 tvLastname = view.findViewById(R.id.edit_lastname);
51 tvEmail = view.findViewById(R.id.edit_email);
52 tvPhone = view.findViewById(R.id.edit_phone);
53 btnSaveChanges = view.findViewById(R.id.btn_save_changes);
62 btnSaveChanges.setOnClickListener(
new View.OnClickListener() {
64 public void onClick(View v) {
70 ImageView backArrow = view.findViewById(R.id.back_arrow);
72 backArrow.setOnClickListener(
new View.OnClickListener() {
74 public void onClick(View v) {
76 FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
77 fragmentManager.popBackStack();
83 private void displayUserProfile() {
85 String name = profileManager.
getName();
87 String email = profileManager.
getEmail();
88 String phone = profileManager.
getPhone();
91 tvNombre.setText(name);
92 tvLastname.setText(surname);
93 tvEmail.setText(email);
94 tvPhone.setText(phone);
97 private void updateProfile() {
99 final String updatedName = tvNombre.getText().toString().trim();
100 final String updatedSurname = tvLastname.getText().toString().trim();
101 final String updatedEmail = tvEmail.getText().toString().trim();
102 final String updatedPhone = tvPhone.getText().toString().trim();
105 if (updatedName.isEmpty() || updatedSurname.isEmpty() || updatedEmail.isEmpty() || updatedPhone.isEmpty()) {
106 Toast.makeText(getContext(),
"Por favor complete todos los campos", Toast.LENGTH_SHORT).show();
110 String url =
" https://backmobile1.onrender.com/appUSERS/update/";
113 JSONObject requestBody =
new JSONObject();
115 requestBody.put(
"nombre", updatedName);
116 requestBody.put(
"apellido", updatedSurname);
117 requestBody.put(
"email", updatedEmail);
118 requestBody.put(
"telefono", updatedPhone);
119 }
catch (JSONException e) {
125 JsonObjectRequest request =
new JsonObjectRequest(Request.Method.PUT, url, requestBody,
126 new Response.Listener<JSONObject>() {
128 public void onResponse(JSONObject response) {
130 profileManager.saveInfo(updatedName, updatedSurname, updatedEmail, updatedPhone);
131 Toast.makeText(getContext(),
"Perfil actualizado correctamente", Toast.LENGTH_SHORT).show();
134 FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
135 fragmentManager.popBackStack();
137 },
new Response.ErrorListener() {
139 public void onErrorResponse(VolleyError error) {
140 Toast.makeText(getContext(),
"Error al actualizar el perfil", Toast.LENGTH_SHORT).show();
144 public Map<String, String> getHeaders() {
145 Map<String, String> headers =
new HashMap<>();
146 headers.put(
"Authorization",
"Bearer " + sessionManager.
getToken());
152 RequestQueue queue = Volley.newRequestQueue(requireContext());