Implement multi-language support with language selection screen - #8
Implement multi-language support with language selection screen#8gyanu2507 wants to merge 6 commits into
Conversation
- Add support for 10 languages: English, Chinese, Hindi, Spanish, Arabic, French, Bengali, Portuguese, Russian, Urdu - Create LocaleHelper utility class for managing locale changes - Add UpdateAppApplication class to initialize locale on app start - Implement LanguageActivity with RecyclerView for language selection - Create LanguageAdapter and LanguageModel for language list - Add strings.xml files for all supported languages - Update MainActivity and LanguageActivity to support locale changes - Language preference persists after app restart - Immediate language switching when language is selected Fixes allknowledge34#7
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📝 WalkthroughWalkthroughIntroduces app-wide locale management infrastructure by creating a LocaleHelper utility class that persists language preferences to SharedPreferences, adding an Application subclass to apply locale at startup, and modifying the launch flow to present a language selection screen on first run. Changes
Sequence DiagramsequenceDiagram
participant User
participant App as App Launch
participant UAA as UpdateAppApplication
participant LH as LocaleHelper
participant SP as SharedPreferences
participant SSA as SplashScreenActivity
participant LA as LanguageActivity
participant OBA as OnboardingActivity
User->>App: Start App
App->>UAA: attachBaseContext()
UAA->>LH: attachBaseContext(context)
LH->>SP: getSavedLanguage()
SP-->>LH: saved_language or "en"
LH->>LH: apply Locale to Configuration
LH-->>UAA: localized context
UAA-->>App: context configured
App->>SSA: Launch SplashScreenActivity
SSA->>SP: read LANGUAGE_SELECTED
alt Language Not Selected (First Launch)
SSA->>LA: navigate to LanguageActivity
LA->>User: show language selection
User->>LA: select language
LA->>LH: setLocale(context, languageCode)
LH->>SP: save selected_language
LA->>OBA: navigate to OnboardingActivity
else Language Already Selected
SSA->>OBA: navigate to OnboardingActivity
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@allknowledge34, please review the PR |
There was a problem hiding this comment.
Actionable comments posted: 10
🧹 Nitpick comments (11)
app/src/main/res/values-zh/strings.xml (1)
3-3: Optional: Consider translating placeholder text.The "Hello blank fragment" placeholder remains in English. While the base file has a TODO to remove or change this, if it's user-facing, it should be translated to "你好,空白片段" or similar.
app/src/main/res/layout/item_language.xml (2)
13-13: Remove the hard-coded default text.The hard-coded text "English" should be removed or replaced with an empty string. The text is set dynamically by the adapter, so this placeholder is unnecessary and could cause confusion during development.
🔎 Proposed fix
- android:text="English" + android:text=""
15-15: Consider using theme-aware color.Using
@color/blackdirectly may not adapt well to dark mode themes. Consider using a theme attribute like?android:attr/textColorPrimaryor defining a color in your theme that adapts to light/dark modes.🔎 Proposed fix
- android:textColor="@color/black" /> + android:textColor="?android:attr/textColorPrimary" />app/src/main/res/values-fr/strings.xml (1)
3-3: Untranslated string: hello_blank_fragment.This string remains in English across all locales. If this is intentional (e.g., a debug/placeholder string), consider adding a comment. Otherwise, provide translations for consistency.
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (1)
68-90: Consider extracting language configuration to constants.The language codes and their mapping to string resource IDs are hard-coded in the method. Consider extracting these to a constants class or configuration file to improve maintainability, especially if you plan to add more languages in the future.
Example refactor
Create a constants class:
public class LanguageConstants { public static final String[] LANGUAGE_CODES = { "en", "zh", "hi", "es", "ar", "fr", "bn", "pt", "ru", "ur" }; public static final int[] LANGUAGE_NAME_RES_IDS = { R.string.language_english, R.string.language_chinese, R.string.language_hindi, R.string.language_spanish, R.string.language_arabic, R.string.language_french, R.string.language_bengali, R.string.language_portuguese, R.string.language_russian, R.string.language_urdu }; }app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
15-47: Code duplication: locale configuration logic repeated.The locale configuration setup is duplicated between
setLocale()(lines 19-24) andattachBaseContext()(lines 38-41). Consider extracting this into a private helper method to reduce duplication and improve maintainability.Example refactor
private static Configuration createLocaleConfiguration(Context context, Locale locale) { Configuration configuration = context.getResources().getConfiguration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { configuration.setLocale(locale); } else { configuration.locale = locale; } return configuration; }Then use it in both methods to eliminate duplication.
app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (3)
26-29: Consider adding null checks for defensive coding.The constructor accepts
languageListandlistenerwithout validation. While the listener has a null check at Line 45, the list does not. If null is passed forlanguageList, it will cause an NPE whengetItemCount()is called.🔎 Suggested defensive null checks
public LanguageAdapter(List<LanguageModel> languageList, OnLanguageClickListener listener) { + if (languageList == null) { + throw new IllegalArgumentException("languageList cannot be null"); + } this.languageList = languageList; this.listener = listener; }
44-48: Consider moving click listener to ViewHolder constructor.Setting the click listener in
onBindViewHoldermeans a new lambda is created every time an item is bound (including during scrolling). Moving the listener setup to theViewHolderconstructor is a better practice.🔎 Suggested refactor
Modify the ViewHolder constructor:
public ViewHolder(@NonNull View itemView) { super(itemView); languageName = itemView.findViewById(R.id.txt_language_name); selectedIcon = itemView.findViewById(R.id.img_selected); + + itemView.setOnClickListener(v -> { + int position = getAdapterPosition(); + if (position != RecyclerView.NO_POSITION && listener != null) { + listener.onLanguageClick(languageList.get(position)); + } + }); }Then remove the click listener from
onBindViewHolder:@Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { LanguageModel language = languageList.get(position); holder.languageName.setText(language.getLanguageName()); holder.selectedIcon.setVisibility(language.isSelected() ? View.VISIBLE : View.GONE); - - holder.itemView.setOnClickListener(v -> { - if (listener != null) { - listener.onLanguageClick(language); - } - }); }
56-61: Optimize selection updates with targeted notifications.Using
notifyDataSetChanged()refreshes the entire RecyclerView, which is inefficient. Since only two items change state during selection (the previously selected item and the newly selected item), usenotifyItemChanged()for better performance.🔎 Optimized implementation
public void updateSelection(String selectedLanguageCode) { + int previouslySelectedPosition = -1; + int newSelectedPosition = -1; + - for (LanguageModel language : languageList) { - language.setSelected(language.getLanguageCode().equals(selectedLanguageCode)); + for (int i = 0; i < languageList.size(); i++) { + LanguageModel language = languageList.get(i); + boolean wasSelected = language.isSelected(); + boolean shouldBeSelected = language.getLanguageCode().equals(selectedLanguageCode); + + if (wasSelected && !shouldBeSelected) { + previouslySelectedPosition = i; + language.setSelected(false); + } else if (!wasSelected && shouldBeSelected) { + newSelectedPosition = i; + language.setSelected(true); + } } - notifyDataSetChanged(); + + if (previouslySelectedPosition != -1) { + notifyItemChanged(previouslySelectedPosition); + } + if (newSelectedPosition != -1) { + notifyItemChanged(newSelectedPosition); + } }app/src/main/java/com/example/updateapp/models/LanguageModel.java (2)
8-12: Consider adding parameter validation.The constructor accepts
languageCodeandlanguageNamewithout validation. While the current implementation works, adding basic null checks would make the class more robust and catch issues earlier.🔎 Suggested validation
public LanguageModel(String languageCode, String languageName, boolean isSelected) { + if (languageCode == null || languageCode.trim().isEmpty()) { + throw new IllegalArgumentException("languageCode cannot be null or empty"); + } + if (languageName == null || languageName.trim().isEmpty()) { + throw new IllegalArgumentException("languageName cannot be null or empty"); + } this.languageCode = languageCode; this.languageName = languageName; this.isSelected = isSelected; }
3-36: Consider implementing equals() and hashCode().For a data model class, implementing
equals()andhashCode()based onlanguageCodewould enable proper object comparison and use in collections. This becomes useful if you need to compare language objects or use them as Map keys.🔎 Suggested implementation
+import java.util.Objects; + public class LanguageModel { private String languageCode; private String languageName; private boolean isSelected; // ... existing constructor, getters and setters ... + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LanguageModel that = (LanguageModel) o; + return Objects.equals(languageCode, that.languageCode); + } + + @Override + public int hashCode() { + return Objects.hash(languageCode); + } }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (19)
app/src/main/AndroidManifest.xml(1 hunks)app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java(1 hunks)app/src/main/java/com/example/updateapp/MainActivity.java(2 hunks)app/src/main/java/com/example/updateapp/UpdateAppApplication.java(1 hunks)app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java(1 hunks)app/src/main/java/com/example/updateapp/models/LanguageModel.java(1 hunks)app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java(2 hunks)app/src/main/java/com/example/updateapp/views/fragments/ProfileFragment.java(0 hunks)app/src/main/res/layout/item_language.xml(1 hunks)app/src/main/res/values-ar/strings.xml(1 hunks)app/src/main/res/values-bn/strings.xml(1 hunks)app/src/main/res/values-es/strings.xml(1 hunks)app/src/main/res/values-fr/strings.xml(1 hunks)app/src/main/res/values-hi/strings.xml(1 hunks)app/src/main/res/values-pt/strings.xml(1 hunks)app/src/main/res/values-ru/strings.xml(1 hunks)app/src/main/res/values-ur/strings.xml(1 hunks)app/src/main/res/values-zh/strings.xml(1 hunks)app/src/main/res/values/strings.xml(1 hunks)
💤 Files with no reviewable changes (1)
- app/src/main/java/com/example/updateapp/views/fragments/ProfileFragment.java
🧰 Additional context used
🧬 Code graph analysis (4)
app/src/main/java/com/example/updateapp/UpdateAppApplication.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (1)
app/src/main/java/com/example/updateapp/models/LanguageModel.java (1)
LanguageModel(3-37)
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (3)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (1)
LanguageAdapter(17-73)app/src/main/java/com/example/updateapp/models/LanguageModel.java (1)
LanguageModel(3-37)
app/src/main/java/com/example/updateapp/MainActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
🔇 Additional comments (11)
app/src/main/res/values/strings.xml (1)
6-16: LGTM! Native script approach is correct for language selection.The language names are properly displayed in their native scripts (e.g., 中文, हिन्दी, العربية), which is the recommended UX pattern for language selection screens. This ensures users can identify their language regardless of the current app locale.
app/src/main/AndroidManifest.xml (1)
10-10: LGTM! Custom Application class properly wired for locale initialization.The custom Application class is correctly configured to enable app-wide locale handling via
UpdateAppApplication.attachBaseContext(). This is the standard approach for implementing persistent language selection in Android.app/src/main/java/com/example/updateapp/MainActivity.java (1)
59-62: LGTM! Locale handling properly implemented.The
attachBaseContextoverride correctly delegates toLocaleHelper.attachBaseContext()to ensure the saved language preference is applied. This follows Android best practices for per-activity locale configuration.app/src/main/java/com/example/updateapp/UpdateAppApplication.java (1)
8-12: LGTM! Correct locale initialization pattern.The Application class correctly wraps the base context using LocaleHelper before passing it to the superclass. This ensures the saved locale is applied application-wide at startup.
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (2)
92-108: Language selection logic implemented correctly.The language selection flow properly:
- Checks if the language actually changed before applying
- Uses LocaleHelper to persist and apply the locale
- Updates the adapter selection state
- Calls
recreate()to immediately reflect the language change in the UIThe use of
recreate()is appropriate here despite resetting activity state, as language changes should provide immediate visual feedback.
110-113: Correct attachBaseContext implementation.The activity correctly overrides
attachBaseContextto apply the saved locale, ensuring consistency with the Application-level locale handling.app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (2)
33-47: attachBaseContext correctly handles API version differences.The method properly creates a new configuration context for API 24+ while falling back to the deprecated
updateConfigurationfor older versions. This is the correct pattern for handling locales inattachBaseContext.
49-52: LGTM! Clean SharedPreferences accessor.The method provides a simple, clean way to retrieve the saved language with a sensible default.
app/src/main/res/values-ar/strings.xml (1)
1-16: RTL layout support for Arabic and Urdu is properly implemented.Verification confirms all RTL requirements are met:
- android:supportsRtl="true" is set in the element in AndroidManifest.xml
- Layout files use start/end attributes; no deprecated left/right attributes remain (e.g., item_language.xml correctly uses layout_alignParentEnd)
- Urdu translations (values-ur/strings.xml) are present and complete
No further action required.
app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (2)
31-36: LGTM!Standard and correct implementation of
onCreateViewHolder.
63-72: LGTM!Standard and correct ViewHolder implementation.
|
@gyanu2507 , please review the PR Thanks for your effort and for submitting this PR. I have reviewed the code and tested the implementation, but unfortunately this PR does not meet the original requirements yet. Issues found:
Requirement clarification:
Because this is a paid issue, I need the above points to be fixed before I can verify, merge, and proceed with payment. Please update the implementation accordingly and let me know once it is ready for re-review. |
- Add first-launch language selection in SplashScreenActivity - Integrate LocaleHelper in all activities for consistent language support - Update LanguageActivity to handle first-launch navigation - Add language selection tracking using SaveState - Support for 10 languages: English, Chinese, Hindi, Spanish, Arabic, French, Bengali, Portuguese, Russian, Urdu
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
app/src/main/java/com/example/updateapp/views/activites/SignUpActivity.java (1)
50-52: Hardcoded strings prevent localization from working app-wide.Per reviewer feedback, the locale change only affects screens with localized strings. These hardcoded UI texts (progress dialog messages, error messages, toast messages) will not change when the user switches languages. All visible text must be moved to
strings.xmlwith consistent keys across all locale files.Examples in this file:
- Lines 51-52:
"Creating Your Account","Your Account Is Creating"- Lines 77-80: Validation error messages
- Lines 102-104:
"This email is already registered..."🔎 Example fix for progress dialog strings
Add to
res/values/strings.xml:<string name="creating_account_title">Creating Your Account</string> <string name="creating_account_message">Your Account Is Creating</string>Then update the code:
progressDialog = new ProgressDialog(this); -progressDialog.setTitle("Creating Your Account"); -progressDialog.setMessage("Your Account Is Creating"); +progressDialog.setTitle(getString(R.string.creating_account_title)); +progressDialog.setMessage(getString(R.string.creating_account_message));Also applies to: 77-80, 102-104
app/src/main/java/com/example/updateapp/views/activites/LoginActivity.java (1)
68-70: Hardcoded strings will not respond to language changes.This activity contains numerous hardcoded strings that won't be localized when the user changes language. Per the PR requirements, all visible text must be externalized to
strings.xml:
- Lines 69-70:
"Logging In","Please wait..."- Lines 80, 82, 114, 116: Validation error messages
- Lines 212-213:
"Firebase Authentication Failed"Extract these to string resources with the same keys defined in all locale files.
Also applies to: 80-82, 114-116, 211-213
app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java (1)
59-61: Hardcoded strings prevent app-wide localization.This activity has multiple hardcoded strings that won't be translated when the user changes language:
- Lines 60-61:
"Verifying OTP","Please wait..."- Line 74:
"Please enter valid OTP"- Lines 157, 163: OTP error messages
- Lines 188-194: Account linking error messages
These must be extracted to
strings.xmland translated in all locale files.Also applies to: 74-74, 156-158, 188-194
app/src/main/java/com/example/updateapp/views/activites/ForgetActivity.java (2)
38-38: Hardcoded string needs localization.The string
"Please Wait"should be moved tostrings.xmland referenced viagetString(R.string.please_wait). Per reviewer feedback, all visible text must support localization for the language switch to work app-wide.🔎 Proposed fix
- progressDialog.setTitle("Please Wait"); + progressDialog.setTitle(getString(R.string.please_wait));Add to all
strings.xmlfiles:<string name="please_wait">Please Wait</string>
46-48: Additional hardcoded strings require localization.Lines 48, 61, and 69 contain hardcoded user-facing strings (
"Enter Valid Email","Please Check Your Email", and the Firebase exception message display). These should all use string resources for full multi-language support.🔎 Proposed fix for line 48
- binding.edtForgetEmail.setError("Enter Valid Email"); + binding.edtForgetEmail.setError(getString(R.string.enter_valid_email));🔎 Proposed fix for line 61
- Toast.makeText(ForgetActivity.this, "Please Check Your Email", Toast.LENGTH_SHORT).show(); + Toast.makeText(ForgetActivity.this, getString(R.string.check_your_email), Toast.LENGTH_SHORT).show();
♻️ Duplicate comments (6)
app/src/main/res/values-fr/strings.xml (1)
4-4: OAuth client ID still hardcoded in version control.The hardcoded
default_web_client_idfrom a previous review comment has not been addressed. This value should be moved togradle.properties(excluded from VCS) or injected via BuildConfig, not committed across all locale files.app/src/main/res/values-es/strings.xml (1)
6-15: Language names should use native scripts.This issue was already flagged in a previous review. Language names should be displayed in their native scripts (e.g., "中文" for Chinese, "हिन्दी" for Hindi) so users can identify their language regardless of current locale.
app/src/main/res/layout/item_language.xml (1)
17-24: Missing contentDescription for accessibility.The ImageView lacks a
contentDescriptionattribute, which is required for accessibility. Screen readers need this to describe the checkmark icon to users.This was already flagged in a previous review.
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (1)
46-46: Typo in resource ID:rev_langauge.This should be
rev_language. The typo exists in the layout XML file and should be fixed for consistency.This was already flagged in a previous review.
app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (1)
56-61: Critical: Unresolved NPE risk in updateSelection.The past review correctly identified that Line 58 will throw a
NullPointerExceptionifselectedLanguageCodeisnullandlanguage.getLanguageCode()is non-null. This issue remains unaddressed and must be fixed before merge.🔎 Recommended null-safe fix
public void updateSelection(String selectedLanguageCode) { for (LanguageModel language : languageList) { - language.setSelected(language.getLanguageCode().equals(selectedLanguageCode)); + language.setSelected(selectedLanguageCode != null && + selectedLanguageCode.equals(language.getLanguageCode())); } notifyDataSetChanged(); }Alternatively, use
Objects.equals()for a more concise solution:+import java.util.Objects; + // ... public void updateSelection(String selectedLanguageCode) { for (LanguageModel language : languageList) { - language.setSelected(language.getLanguageCode().equals(selectedLanguageCode)); + language.setSelected(Objects.equals(language.getLanguageCode(), selectedLanguageCode)); } notifyDataSetChanged(); }app/src/main/res/values-ur/strings.xml (1)
6-15: Critical: Language names must use native scripts, not Urdu translations.This issue was flagged in the previous review but remains unaddressed. When all language names are written in Urdu script, users who don't read Urdu cannot identify or select their preferred language. Each language must appear in its own native script.
🔎 Required fix: Use native scripts for language names
- <string name="language_english">انگریزی</string> - <string name="language_chinese">چینی</string> - <string name="language_hindi">ہندی</string> - <string name="language_spanish">ہسپانوی</string> - <string name="language_arabic">عربی</string> - <string name="language_french">فرانسیسی</string> - <string name="language_bengali">بنگالی</string> - <string name="language_portuguese">پرتگالی</string> - <string name="language_russian">روسی</string> - <string name="language_urdu">اردو</string> + <string name="language_english">English</string> + <string name="language_chinese">中文</string> + <string name="language_hindi">हिन्दी</string> + <string name="language_spanish">Español</string> + <string name="language_arabic">العربية</string> + <string name="language_french">Français</string> + <string name="language_bengali">বাংলা</string> + <string name="language_portuguese">Português</string> + <string name="language_russian">Русский</string> + <string name="language_urdu">اردو</string>Note: This same correction must be applied to all other locale-specific
strings.xmlfiles (values-ar, values-bn, values-es, values-fr, values-hi, values-pt, values-ru, values-zh).
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (22)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.javaapp/src/main/java/com/example/updateapp/UpdateAppApplication.javaapp/src/main/java/com/example/updateapp/adapters/LanguageAdapter.javaapp/src/main/java/com/example/updateapp/models/LanguageModel.javaapp/src/main/java/com/example/updateapp/views/activites/ForgetActivity.javaapp/src/main/java/com/example/updateapp/views/activites/LanguageActivity.javaapp/src/main/java/com/example/updateapp/views/activites/LoginActivity.javaapp/src/main/java/com/example/updateapp/views/activites/NewUpdateActivity.javaapp/src/main/java/com/example/updateapp/views/activites/OTPActivity.javaapp/src/main/java/com/example/updateapp/views/activites/OnboardingActivity.javaapp/src/main/java/com/example/updateapp/views/activites/SignUpActivity.javaapp/src/main/java/com/example/updateapp/views/activites/SplashScreenActivity.javaapp/src/main/res/layout/item_language.xmlapp/src/main/res/values-ar/strings.xmlapp/src/main/res/values-bn/strings.xmlapp/src/main/res/values-es/strings.xmlapp/src/main/res/values-fr/strings.xmlapp/src/main/res/values-hi/strings.xmlapp/src/main/res/values-pt/strings.xmlapp/src/main/res/values-ru/strings.xmlapp/src/main/res/values-ur/strings.xmlapp/src/main/res/values-zh/strings.xml
🚧 Files skipped from review as they are similar to previous changes (8)
- app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java
- app/src/main/res/values-zh/strings.xml
- app/src/main/res/values-ru/strings.xml
- app/src/main/res/values-bn/strings.xml
- app/src/main/java/com/example/updateapp/UpdateAppApplication.java
- app/src/main/java/com/example/updateapp/models/LanguageModel.java
- app/src/main/res/values-hi/strings.xml
- app/src/main/res/values-pt/strings.xml
🧰 Additional context used
🧬 Code graph analysis (8)
app/src/main/java/com/example/updateapp/views/activites/ForgetActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/views/activites/LoginActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/views/activites/OnboardingActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (4)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)app/src/main/java/com/example/updateapp/Helpers/SaveState.java (1)
SaveState(6-27)app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (1)
LanguageAdapter(17-73)app/src/main/java/com/example/updateapp/models/LanguageModel.java (1)
LanguageModel(3-37)
app/src/main/java/com/example/updateapp/views/activites/SignUpActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
app/src/main/java/com/example/updateapp/adapters/LanguageAdapter.java (1)
app/src/main/java/com/example/updateapp/models/LanguageModel.java (1)
LanguageModel(3-37)
app/src/main/java/com/example/updateapp/views/activites/NewUpdateActivity.java (1)
app/src/main/java/com/example/updateapp/Helpers/LocaleHelper.java (1)
LocaleHelper(11-53)
🔇 Additional comments (11)
app/src/main/java/com/example/updateapp/views/activites/SignUpActivity.java (1)
167-170: Locale integration is correct.The
attachBaseContextoverride follows the same pattern used across other activities and properly delegates toLocaleHelper.attachBaseContext()for consistent locale handling.app/src/main/java/com/example/updateapp/views/activites/LoginActivity.java (1)
230-233: Locale integration is correctly implemented.The
attachBaseContextoverride properly wraps the base context with locale-aware configuration viaLocaleHelper.app/src/main/java/com/example/updateapp/views/activites/NewUpdateActivity.java (1)
39-42: LGTM!The
attachBaseContextoverride is correctly implemented, consistent with the locale handling pattern across other activities.app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java (1)
230-233: Locale integration is correctly implemented.The
attachBaseContextoverride properly applies the saved locale configuration.app/src/main/java/com/example/updateapp/views/activites/OnboardingActivity.java (1)
119-122: Locale context wrapping looks correct.The
attachBaseContextoverride properly delegates toLocaleHelper.attachBaseContext(), ensuring this activity respects the user's saved language preference. This is consistent with the pattern applied across other activities in the PR.app/src/main/java/com/example/updateapp/views/activites/ForgetActivity.java (1)
87-90: Locale context wrapping is correctly implemented.The
attachBaseContextoverride follows the established pattern.app/src/main/res/layout/item_language.xml (1)
1-26: Layout structure is acceptable.The layout provides a functional language item view with a name and selection indicator. The hardcoded
android:text="English"on Line 13 is a design-time placeholder and is correctly overwritten by the adapter at runtime.app/src/main/java/com/example/updateapp/views/activites/SplashScreenActivity.java (2)
32-50: First-launch language selection flow is well-implemented.The logic correctly checks if a language has been selected before and routes accordingly:
- First launch →
LanguageActivitywithisFirstLaunchflag- Subsequent launches →
OnboardingActivityThe
SaveStateusage for tracking language selection state is consistent with patterns elsewhere in the codebase.
59-62: Locale context wrapping is correctly applied.The
attachBaseContextoverride ensures the splash screen respects the saved language preference from the start.app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (2)
80-102: Language list construction is correct.The method properly:
- Uses string resources for language names (enabling localized display)
- Marks the current language as selected
- Covers all 10 required languages
126-129: Locale context wrapping is correctly implemented.
…improve back button handling - Fix typo: rev_langauge -> rev_language in layout and Java file - Remove deprecated updateConfiguration() call from LocaleHelper.setLocale() - Remove unused Resources import - Replace deprecated onBackPressed() with OnBackPressedCallback - Prevent back navigation on first launch (user must select language) - All language translations verified complete
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (1)
29-39:⚠️ Potential issue | 🔴 CriticalDuplicate field declarations will cause compilation error.
Fields
recyclerViewandlanguageListare declared twice (lines 29, 31 and lines 36, 38). Additionally, there are two adapter fields with different names (languageAdapteron line 30 andadapteron line 37), andcurrentLanguageCodeis declared but never used in the final implementation.🐛 Proposed fix: Remove duplicate declarations
public class LanguageActivity extends AppCompatActivity implements LanguageAdapter.OnLanguageSelectedListener { private RecyclerView recyclerView; private LanguageAdapter languageAdapter; private List<LanguageModel> languageList; private ImageView imgDone, imgBack; 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) {app/src/main/java/com/example/updateapp/views/activites/OnboardingActivity.java (1)
16-20:⚠️ Potential issue | 🔴 CriticalDuplicate
LocaleHelperimports from different packages will cause compilation error.Same issue as other files—two
LocaleHelperclasses imported fromHelpersandutilspackages. Remove the unused import.🐛 Proposed fix
-import com.example.updateapp.Helpers.LocaleHelper; import com.example.updateapp.Helpers.SaveState; import com.example.updateapp.R; import com.example.updateapp.adapters.OnboardingAdapter; import com.example.updateapp.utils.LocaleHelper;app/src/main/java/com/example/updateapp/views/activites/SplashScreenActivity.java (1)
60-68:⚠️ Potential issue | 🔴 CriticalDuplicate
attachBaseContextmethod declarations will cause compilation error.Two
attachBaseContextmethods are defined (lines 60-63 and lines 65-68). This won't compile. Additionally, they use differentLocaleHelpermethods:
- First uses
LocaleHelper.attachBaseContext(newBase)(fromHelperspackage)- Second uses
LocaleHelper.onAttach(newBase)(fromutilspackage)Keep only one method. For consistency with other activities, use
LocaleHelper.onAttach()from theutilspackage.🐛 Proposed fix: Keep only one attachBaseContext method
- `@Override` - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleHelper.attachBaseContext(newBase)); - } - `@Override` protected void attachBaseContext(Context newBase) { super.attachBaseContext(LocaleHelper.onAttach(newBase)); } }
🤖 Fix all issues with AI agents
In
`@app/src/main/java/com/example/updateapp/views/activites/NewUpdateActivity.java`:
- Around line 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.
In `@app/src/main/java/com/example/updateapp/views/activites/SignUpActivity.java`:
- Around line 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.
In
`@app/src/main/java/com/example/updateapp/views/activites/SplashScreenActivity.java`:
- Around line 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.
🧹 Nitpick comments (1)
app/src/main/java/com/example/updateapp/views/activites/LanguageActivity.java (1)
10-10: Unused import.
OnBackPressedCallbackis imported but not used anywhere in this file.♻️ Remove unused import
-import androidx.activity.OnBackPressedCallback;
Keep a single LocaleHelper, persist English as en with no country, and apply it through AppCompatDelegate plus a full-task restart so every screen follows the choice. Move remaining hardcoded copy into strings.xml for all locales and give the language list a selected state.
|
@allknowledge34 this is ready for another look. Language now applies app-wide ( |
Persist English without a country tag so switching back from Hindi works, and move remaining hardcoded UI copy into translated string resources.
|
Addressed the review:
Please rebuild and try: open the app, pick Hindi, leave LanguageActivity, then switch back to English. |
Description
This PR implements multi-language support for the UpdateApp with a fully functional language selection screen, as requested in issue #7.
Changes Made
New Features
New Files Created
LocaleHelper.java- Utility class for managing locale changes and persistenceUpdateAppApplication.java- Custom Application class to initialize locale on app startLanguageModel.java- Model class for language dataLanguageAdapter.java- RecyclerView adapter for language listitem_language.xml- Layout for language list itemsstrings.xmlfiles for all 10 languages in their respectivevalues-<lang>/directoriesFiles Modified
LanguageActivity.java- Implemented full language selection functionalityMainActivity.java- Added locale support viaattachBaseContextProfileFragment.java- Removed "Coming Soon" toast messageAndroidManifest.xml- Added custom Application classstrings.xml(base) - Added language name stringsTechnical Implementation
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.