Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.updateapp.Helpers;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;

import java.util.Locale;

public class LocaleHelper {
private static final String PREFS_NAME = "app_prefs";
private static final String KEY_LANGUAGE = "selected_language";

public static void setLocale(Context context, String languageCode) {
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);

// Save language preference
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putString(KEY_LANGUAGE, languageCode).apply();

// Note: Configuration update is handled by attachBaseContext when activity is recreated
// This avoids using deprecated updateConfiguration method
}
Comment on lines +14 to +24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Using deprecated API: updateConfiguration should be avoided for API 25+.

Line 26 uses updateConfiguration(), which has been deprecated since API 25. For API 24+, the recommended approach is to use createConfigurationContext() instead. While the current implementation works because LanguageActivity calls recreate() immediately after, it's better to follow Android best practices.

The deprecation is mentioned in Android docs: updateConfiguration can lead to unpredictable behavior and configuration inconsistencies.

🔎 Proposed fix

Consider refactoring setLocale to avoid the deprecated API for newer Android versions:

 public static void setLocale(Context context, String languageCode) {
     Locale locale = new Locale(languageCode);
     Locale.setDefault(locale);
 
-    Configuration configuration = context.getResources().getConfiguration();
-    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-        configuration.setLocale(locale);
-    } else {
-        configuration.locale = locale;
-    }
-
-    context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());
-
     // Save language preference
     SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
     prefs.edit().putString(KEY_LANGUAGE, languageCode).apply();
 }

Then ensure activities call recreate() or restart themselves after calling setLocale() to pick up the new locale through attachBaseContext(). Your current implementation in LanguageActivity.onLanguageSelected() already does this correctly with the recreate() call.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java around
lines 15-31, avoid using the deprecated Resources.updateConfiguration for API
25+; instead after creating and setting the Locale on a Configuration, for API
>= Build.VERSION_CODES.N (API 24+) call Context newContext =
context.createConfigurationContext(configuration) and use that context's
resources (or return/wrap it) so the updated configuration is applied without
updateConfiguration, and for older APIs keep the existing configuration.locale +
updateConfiguration fallback; keep persisting KEY_LANGUAGE to SharedPreferences
and ensure callers continue to recreate activities to pick up the new locale.


public static Context attachBaseContext(Context context) {
String languageCode = getSavedLanguage(context);
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);

Configuration configuration = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(locale);
return context.createConfigurationContext(configuration);
} else {
configuration.locale = locale;
context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());
return context;
}
}

public static String getSavedLanguage(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
return prefs.getString(KEY_LANGUAGE, "en"); // Default to English
}
}

1 change: 1 addition & 0 deletions app/src/main/java/com/example/updateapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.databinding.ActivityMainBinding;
import com.example.updateapp.utils.LocaleHelper;
import com.example.updateapp.views.fragments.ChatbotFragment;
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/updateapp/UpdateAppApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.updateapp;

import android.app.Application;
import android.content.Context;

import com.example.updateapp.Helpers.LocaleHelper;

public class UpdateAppApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(LocaleHelper.attachBaseContext(base));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ public LanguageViewHolder(@NonNull View itemView) {
imgSelected = itemView.findViewById(R.id.img_selected);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public boolean isSelected() {
public void setSelected(boolean selected) {
isSelected = selected;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
Expand All @@ -32,6 +33,11 @@ public class LanguageActivity extends AppCompatActivity implements LanguageAdapt
private TextView txtTitle;
private int selectedPosition = 0;

private RecyclerView recyclerView;
private LanguageAdapter adapter;
private List<LanguageModel> languageList;
private String currentLanguageCode;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.MainActivity;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivityLoginBinding;
Expand Down Expand Up @@ -222,7 +223,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
this,
getString(R.string.google_signin_error, e.getStatusCode(), e.getMessage()),
Toast.LENGTH_LONG
).show();
) .show();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivityNewUpdateBinding;
import com.example.updateapp.utils.LocaleHelper;
Comment on lines +14 to 17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Duplicate LocaleHelper imports from different packages will cause compilation error.

Two classes named LocaleHelper are imported from different packages:

  • com.example.updateapp.Helpers.LocaleHelper (line 14)
  • com.example.updateapp.utils.LocaleHelper (line 17)

This will fail to compile. Choose one implementation and remove the other import. Based on the attachBaseContext usage with onAttach(), you should keep only the utils.LocaleHelper.

🐛 Proposed fix
-import com.example.updateapp.Helpers.LocaleHelper;
 import com.example.updateapp.R;
 import com.example.updateapp.databinding.ActivityNewUpdateBinding;
 import com.example.updateapp.utils.LocaleHelper;
🤖 Prompt for AI Agents
In
`@app/src/main/java/com/example/updateapp/views/activites/NewUpdateActivity.java`
around lines 14 - 17, There are two conflicting imports of LocaleHelper causing
a compile error; remove the import for
com.example.updateapp.Helpers.LocaleHelper and keep
com.example.updateapp.utils.LocaleHelper, then ensure any references in
NewUpdateActivity (e.g., in attachBaseContext(...) or onAttach(...) usages) use
the utils.LocaleHelper implementation so all calls resolve to that single class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.MainActivity;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivityOtpactivityBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import androidx.cardview.widget.CardView;
import androidx.viewpager.widget.ViewPager;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.Helpers.SaveState;
import com.example.updateapp.R;
import com.example.updateapp.adapters.OnboardingAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivitySignUpBinding;
import com.example.updateapp.utils.LocaleHelper;
Comment on lines +14 to 17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Duplicate LocaleHelper imports from different packages will cause compilation error.

Same issue—remove the unused Helpers.LocaleHelper import.

🐛 Proposed fix
-import com.example.updateapp.Helpers.LocaleHelper;
 import com.example.updateapp.R;
 import com.example.updateapp.databinding.ActivitySignUpBinding;
 import com.example.updateapp.utils.LocaleHelper;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivitySignUpBinding;
import com.example.updateapp.utils.LocaleHelper;
import com.example.updateapp.R;
import com.example.updateapp.databinding.ActivitySignUpBinding;
import com.example.updateapp.utils.LocaleHelper;
🤖 Prompt for AI Agents
In `@app/src/main/java/com/example/updateapp/views/activites/SignUpActivity.java`
around lines 14 - 17, Remove the duplicate/incorrect import of LocaleHelper in
SignUpActivity: keep the correct import com.example.updateapp.utils.LocaleHelper
and delete the unused com.example.updateapp.Helpers.LocaleHelper import so the
class (SignUpActivity) compiles without conflicting imports.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.Helpers.SaveState;
import com.example.updateapp.R;
import com.example.updateapp.utils.LocaleHelper;
Comment on lines +14 to 17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Duplicate LocaleHelper imports from different packages will cause compilation error.

Same issue as other files—two LocaleHelper classes imported.

🐛 Proposed fix
-import com.example.updateapp.Helpers.LocaleHelper;
 import com.example.updateapp.Helpers.SaveState;
 import com.example.updateapp.R;
 import com.example.updateapp.utils.LocaleHelper;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.Helpers.SaveState;
import com.example.updateapp.R;
import com.example.updateapp.utils.LocaleHelper;
import com.example.updateapp.Helpers.SaveState;
import com.example.updateapp.R;
import com.example.updateapp.utils.LocaleHelper;
🤖 Prompt for AI Agents
In
`@app/src/main/java/com/example/updateapp/views/activites/SplashScreenActivity.java`
around lines 14 - 17, The file has two conflicting imports for LocaleHelper
(com.example.updateapp.Helpers.LocaleHelper and
com.example.updateapp.utils.LocaleHelper) which causes a compile error; in
SplashScreenActivity remove the incorrect/unused LocaleHelper import and keep
the one that matches the actual class used by this activity (ensure references
in SplashScreenActivity resolve to the retained LocaleHelper), or refactor usage
to the retained package if the wrong one was imported.


Expand All @@ -28,21 +30,36 @@ protected void onCreate(Bundle savedInstanceState) {
);
setContentView(R.layout.activity_splash_screen);

// Check if language has been selected before
SaveState languageState = new SaveState(this, "LANGUAGE_SELECTED");
boolean languageSelected = languageState.getState() == 1;

new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent();
intent.setClass(SplashScreenActivity.this, OnboardingActivity.class);
Intent intent;
if (!languageSelected) {
// Show language selection screen on first launch
intent = new Intent(SplashScreenActivity.this, LanguageActivity.class);
intent.putExtra("isFirstLaunch", true);
} else {
// Go to onboarding
intent = new Intent(SplashScreenActivity.this, OnboardingActivity.class);
}
startActivity(intent);
finish();
}
});
}
},500);
}, 500);
}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleHelper.attachBaseContext(newBase));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
android:layout_below="@+id/rel_top">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rev_langauge"
android:id="@+id/rev_language"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
android:layout_marginEnd="-20dp"
android:background="#F0F0F0" />

</RelativeLayout>
</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">العودة إلى</string>
<string name="forget_password_button">نسيت كلمة المرور</string>
<string name="check_email">يرجى التحقق من بريدك الإلكتروني</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">ফিরে যান</string>
<string name="forget_password_button">পাসওয়ার্ড ভুলে গেছেন</string>
<string name="check_email">অনুগ্রহ করে আপনার ইমেইল চেক করুন</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">Volver a</string>
<string name="forget_password_button">OLVIDÉ MI CONTRASEÑA</string>
<string name="check_email">Por Favor Revisa Tu Email</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">Retour à</string>
<string name="forget_password_button">MOT DE PASSE OUBLIÉ</string>
<string name="check_email">Veuillez Vérifier Votre Email</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">वापस जाएं</string>
<string name="forget_password_button">पासवर्ड भूल गए</string>
<string name="check_email">कृपया अपना ईमेल जांचें</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">Voltar para</string>
<string name="forget_password_button">ESQUECI A SENHA</string>
<string name="check_email">Por Favor Verifique Seu Email</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">Вернуться к</string>
<string name="forget_password_button">ЗАБЫЛИ ПАРОЛЬ</string>
<string name="check_email">Пожалуйста, Проверьте Ваш Email</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ur/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="back_to">واپس جائیں</string>
<string name="forget_password_button">پاس ورڈ بھول گئے</string>
<string name="check_email">براہ کرم اپنا ای میل چیک کریں</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@
<string name="otp_verification_failed">验证码验证失败</string>
<string name="otp_error">验证码错误: %1$s</string>
<string name="auth_error_user_not_found">身份验证错误:登录后未找到用户</string>
</resources>
</resources>