Updated String resources and provided context

This commit is contained in:
Pau 2025-05-23 00:48:01 +02:00
parent 83a02ba6ed
commit 13cd391af0
10 changed files with 39 additions and 32 deletions

View File

@ -227,7 +227,7 @@ public class AddNewPlaceActivity extends AppCompatActivity implements View.OnCli
private void onClickBtnSubmit() { private void onClickBtnSubmit() {
View[] views = {etPlaceName, etLatitude, etLongitude, etAddress, etPlaceDescription}; View[] views = {etPlaceName, etLatitude, etLongitude, etAddress, etPlaceDescription};
if (Helper.isEmptyFieldValidation(views)) { if (Helper.isEmptyFieldValidation(context, views)) {
setInputDataToEntity(); setInputDataToEntity();
if (place_uuid != null && !place_uuid.isEmpty()) { if (place_uuid != null && !place_uuid.isEmpty()) {

View File

@ -2,7 +2,6 @@ package com.example.acloc.activity;
import static com.example.acloc.utility.Constants.BASE_URL; import static com.example.acloc.utility.Constants.BASE_URL;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
@ -273,7 +272,7 @@ public class AddReportActivity extends AppCompatActivity implements View.OnClick
private void onClickBtnSubmit() { private void onClickBtnSubmit() {
View[] views = {etPlaceName, etDescription}; View[] views = {etPlaceName, etDescription};
if (Helper.isEmptyFieldValidation(views) && isValidateRating()) { if (Helper.isEmptyFieldValidation(context, views) && isValidateRating()) {
setInputDataToEntity(); setInputDataToEntity();
if (report_uuid != null && !report_uuid.isEmpty()) { if (report_uuid != null && !report_uuid.isEmpty()) {

View File

@ -53,7 +53,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
Helper.goTo(this, MainActivity.class); Helper.goTo(this, MainActivity.class);
finish(); finish();
} else { } else {
// Optionally force logout if token expired // force logout if token expired
SharedPref.setIsLoggedIn(this, false); SharedPref.setIsLoggedIn(this, false);
SharedPref.setAccessToken(this, ""); // clear token SharedPref.setAccessToken(this, ""); // clear token
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
@ -112,7 +112,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
private void onClickBtnLogin() { private void onClickBtnLogin() {
View[] views = {etUsername, etPassword}; View[] views = {etUsername, etPassword};
if (Helper.isEmptyFieldValidation(views)) { if (Helper.isEmptyFieldValidation(context, views)) {
setInputDataToEntity(); setInputDataToEntity();
loginUserWithRetrofit(); loginUserWithRetrofit();
} }

View File

@ -78,7 +78,7 @@ public class PlaceDetailActivity extends AppCompatActivity implements View.OnCli
super.onResume(); super.onResume();
if (adapter != null) { if (adapter != null) {
setDataVisibility(false); setDataVisibility(false);
adapter.clearReports(); // Safe way to clear and notify adapter.clearReports(); // clear and notify
} }
if (context != null) loadData(); if (context != null) loadData();

View File

@ -91,7 +91,7 @@ public class AlertChangePasswordDialog implements View.OnClickListener {
private void onClickBtnUpdate() { private void onClickBtnUpdate() {
View[] views = {etOldPassword, etNewPassword}; View[] views = {etOldPassword, etNewPassword};
if (Helper.isEmptyFieldValidation(views) && Helper.isPasswordValid(etNewPassword)) { if (Helper.isEmptyFieldValidation(context, views) && Helper.isPasswordValid(context, etNewPassword)) {
String username = SharedPref.getUserName(context); String username = SharedPref.getUserName(context);
String oldPassword = Helper.getStringFromInput(etOldPassword); String oldPassword = Helper.getStringFromInput(etOldPassword);
String newPassword = Helper.getStringFromInput(etNewPassword); String newPassword = Helper.getStringFromInput(etNewPassword);

View File

@ -115,7 +115,7 @@ public class AlertViewAddNewPlaceDialog implements View.OnClickListener {
private void onClickBtnSubmit() { private void onClickBtnSubmit() {
View[] views = {etPlaceName, etLatitude, etLongitude, etAddress, etPlaceDescription}; View[] views = {etPlaceName, etLatitude, etLongitude, etAddress, etPlaceDescription};
if (Helper.isEmptyFieldValidation(views)) { if (Helper.isEmptyFieldValidation(context, views)) {
setInputDataToEntity(); setInputDataToEntity();
if (place_uuid != null && !place_uuid.isEmpty()) { if (place_uuid != null && !place_uuid.isEmpty()) {

View File

@ -115,7 +115,7 @@ public class AlertViewOrUpdateProfileDialog implements View.OnClickListener {
private void onClickBtnUpdate() { private void onClickBtnUpdate() {
View[] views = {etUsername, etEmail}; View[] views = {etUsername, etEmail};
if (Helper.isEmptyFieldValidation(views) && Helper.isEmailValid(etEmail)) { if (Helper.isEmptyFieldValidation(context, views) && Helper.isEmailValid(context, etEmail)) {
setInputDataToEntity(); setInputDataToEntity();
String uuid = SharedPref.getUserUid(context); String uuid = SharedPref.getUserUid(context);
updateUserWithRetrofit(uuid, entity.getUsername(), entity.getEmail()); updateUserWithRetrofit(uuid, entity.getUsername(), entity.getEmail());

View File

@ -14,6 +14,7 @@ import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.MaterialAutoCompleteTextView; import com.google.android.material.textfield.MaterialAutoCompleteTextView;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import com.ieslamar.acloc.R;
import java.io.Serializable; import java.io.Serializable;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -49,17 +50,6 @@ public class Helper {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent); context.startActivity(intent);
// No need to finish explicitly here, flags handle it
if (context instanceof Activity) {
((Activity) context).finish();
}
}
public static void goToAndFinish(Context context, Class<?> activity, String key, Serializable object) {
Intent intent = new Intent(context, activity);
intent.putExtra(key, object);
context.startActivity(intent);
if (context instanceof Activity) { if (context instanceof Activity) {
((Activity) context).finish(); ((Activity) context).finish();
} }
@ -75,6 +65,16 @@ public class Helper {
// } // }
} }
public static void goToAndFinish(Context context, Class<?> activity, String key, Serializable object) {
Intent intent = new Intent(context, activity);
intent.putExtra(key, object);
context.startActivity(intent);
if (context instanceof Activity) {
((Activity) context).finish();
}
}
public static int getIntValueFromString(String value) { public static int getIntValueFromString(String value) {
try { try {
return Integer.parseInt(value); return Integer.parseInt(value);
@ -137,7 +137,7 @@ public class Helper {
return isValidate; return isValidate;
} }
public static boolean isEmptyFieldValidation(View[] inputFields) { public static boolean isEmptyFieldValidation(Context context, View[] inputFields) {
boolean isValidate = true; boolean isValidate = true;
try { try {
for (View view : inputFields) { for (View view : inputFields) {
@ -156,13 +156,13 @@ public class Helper {
if (inputText.isEmpty()) { if (inputText.isEmpty()) {
if (textInputLayout != null) { if (textInputLayout != null) {
textInputLayout.setError("Please " + textInputLayout.getHint()); textInputLayout.setError(context.getString(R.string.please) +" "+ textInputLayout.getHint());
textInputLayout.setErrorEnabled(true); textInputLayout.setErrorEnabled(true);
} else { } else {
if (view instanceof TextInputEditText) { if (view instanceof TextInputEditText) {
((TextInputEditText) view).setError("Empty"); ((TextInputEditText) view).setError(context.getString(R.string.empty));
} else if (view instanceof MaterialAutoCompleteTextView) { } else if (view instanceof MaterialAutoCompleteTextView) {
((MaterialAutoCompleteTextView) view).setError("Empty"); ((MaterialAutoCompleteTextView) view).setError(context.getString(R.string.empty));
} }
} }
isValidate = false; isValidate = false;
@ -185,7 +185,7 @@ public class Helper {
return isValidate; return isValidate;
} }
public static boolean isEmailValid(View emailView) { public static boolean isEmailValid(Context context, View emailView) {
boolean isValidate = true; boolean isValidate = true;
try { try {
TextInputLayout textInputLayout = null; TextInputLayout textInputLayout = null;
@ -204,13 +204,13 @@ public class Helper {
// Regex for email validation // Regex for email validation
if (!emailText.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")) { if (!emailText.matches("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$")) {
if (textInputLayout != null) { if (textInputLayout != null) {
textInputLayout.setError("Invalid Email Address"); textInputLayout.setError(context.getString(R.string.invalid_email_address));
textInputLayout.setErrorEnabled(true); textInputLayout.setErrorEnabled(true);
} else { } else {
if (emailView instanceof TextInputEditText) { if (emailView instanceof TextInputEditText) {
((TextInputEditText) emailView).setError("Invalid Email Address"); ((TextInputEditText) emailView).setError(context.getString(R.string.invalid_email_address));
} else if (emailView instanceof MaterialAutoCompleteTextView) { } else if (emailView instanceof MaterialAutoCompleteTextView) {
((MaterialAutoCompleteTextView) emailView).setError("Invalid Email Address"); ((MaterialAutoCompleteTextView) emailView).setError(context.getString(R.string.invalid_email_address));
} }
} }
isValidate = false; isValidate = false;
@ -232,7 +232,7 @@ public class Helper {
return isValidate; return isValidate;
} }
public static boolean isPasswordValid(View passwordView) { public static boolean isPasswordValid(Context context, View passwordView) {
boolean isValidate = true; boolean isValidate = true;
try { try {
TextInputLayout textInputLayout = null; TextInputLayout textInputLayout = null;
@ -253,13 +253,13 @@ public class Helper {
if (!passwordText.matches(passwordPattern)) { if (!passwordText.matches(passwordPattern)) {
if (textInputLayout != null) { if (textInputLayout != null) {
textInputLayout.setError("Password must be at least 6 characters, include 1 uppercase, 1 lowercase, 1 digit, and 1 special character."); textInputLayout.setError(context.getString(R.string.password_validation_requirement));
textInputLayout.setErrorEnabled(true); textInputLayout.setErrorEnabled(true);
} else { } else {
if (passwordView instanceof TextInputEditText) { if (passwordView instanceof TextInputEditText) {
((TextInputEditText) passwordView).setError("Password must be at least 6 characters, include 1 uppercase, 1 lowercase, 1 digit, and 1 special character."); ((TextInputEditText) passwordView).setError(context.getString(R.string.password_validation_requirement));
} else if (passwordView instanceof MaterialAutoCompleteTextView) { } else if (passwordView instanceof MaterialAutoCompleteTextView) {
((MaterialAutoCompleteTextView) passwordView).setError("Password must be at least 6 characters, include 1 uppercase, 1 lowercase, 1 digit, and 1 special character."); ((MaterialAutoCompleteTextView) passwordView).setError(context.getString(R.string.password_validation_requirement));
} }
} }
isValidate = false; isValidate = false;

View File

@ -170,6 +170,10 @@
<string name="response_parsing_error">Error de análisis</string> <string name="response_parsing_error">Error de análisis</string>
<string name="no_places_found_near_this_location">Ningún lugar encontrado cerca de esta dirección</string> <string name="no_places_found_near_this_location">Ningún lugar encontrado cerca de esta dirección</string>
<string name="location_not_found">Lugar no encontrado</string> <string name="location_not_found">Lugar no encontrado</string>
<string name="invalid_email_address">Dirección de correo no válida</string>
<string name="please">Por favor</string>
<string name="empty">Vacío</string>
<string name="password_validation_requirement">La contraseña debe tener al menos 6 caracteres, incluir 1 mayúscula, 1 minúscula, 1 dígito y 1 carácter especial.</string>
</resources> </resources>

View File

@ -173,6 +173,10 @@
<string name="response_parsing_error">Response parsing error</string> <string name="response_parsing_error">Response parsing error</string>
<string name="no_places_found_near_this_location">No places found near this location</string> <string name="no_places_found_near_this_location">No places found near this location</string>
<string name="location_not_found">Location not found</string> <string name="location_not_found">Location not found</string>
<string name="invalid_email_address">Invalid email address</string>
<string name="please">Please</string>
<string name="empty">Empty</string>
<string name="password_validation_requirement">Password must be at least 6 characters, include 1 uppercase, 1 lowercase, 1 digit, and 1 special character.</string>
</resources> </resources>