Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".UpdateAppApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
53 changes: 53 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,53 @@
package com.example.updateapp.Helpers;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
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);

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();
}
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
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/updateapp/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.updateapp;

import android.content.Context;
import android.os.Bundle;
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.views.fragments.ChatbotFragment;
import com.example.updateapp.views.fragments.ProfileFragment;
Expand Down Expand Up @@ -54,4 +56,9 @@ private void loadFragment(Fragment fragment) {
transaction.commit();
}

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

}
13 changes: 13 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,13 @@
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
@@ -0,0 +1,73 @@
package com.example.updateapp.adapters;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.updateapp.R;
import com.example.updateapp.models.LanguageModel;

import java.util.List;

public class LanguageAdapter extends RecyclerView.Adapter<LanguageAdapter.ViewHolder> {

private List<LanguageModel> languageList;
private OnLanguageClickListener listener;

public interface OnLanguageClickListener {
void onLanguageClick(LanguageModel language);
}

public LanguageAdapter(List<LanguageModel> languageList, OnLanguageClickListener listener) {
this.languageList = languageList;
this.listener = listener;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_language, parent, false);
return new ViewHolder(view);
}

@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);
}
});
}

@Override
public int getItemCount() {
return languageList.size();
}

public void updateSelection(String selectedLanguageCode) {
for (LanguageModel language : languageList) {
language.setSelected(language.getLanguageCode().equals(selectedLanguageCode));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
notifyDataSetChanged();
}

public class ViewHolder extends RecyclerView.ViewHolder {
TextView languageName;
ImageView selectedIcon;

public ViewHolder(@NonNull View itemView) {
super(itemView);
languageName = itemView.findViewById(R.id.txt_language_name);
selectedIcon = itemView.findViewById(R.id.img_selected);
}
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/example/updateapp/models/LanguageModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.updateapp.models;

public class LanguageModel {
private String languageCode;
private String languageName;
private boolean isSelected;

public LanguageModel(String languageCode, String languageName, boolean isSelected) {
this.languageCode = languageCode;
this.languageName = languageName;
this.isSelected = isSelected;
}

public String getLanguageCode() {
return languageCode;
}

public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}

public String getLanguageName() {
return languageName;
}

public void setLanguageName(String languageName) {
this.languageName = languageName;
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean selected) {
isSelected = selected;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
package com.example.updateapp.views.activites;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.updateapp.Helpers.LocaleHelper;
import com.example.updateapp.R;
import com.example.updateapp.adapters.LanguageAdapter;
import com.example.updateapp.models.LanguageModel;

import java.util.ArrayList;
import java.util.List;

public class LanguageActivity extends AppCompatActivity {

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

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,5 +40,75 @@ protected void onCreate(Bundle savedInstanceState) {
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

// Initialize views
recyclerView = findViewById(R.id.rev_langauge);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
TextView titleText = findViewById(R.id.txt_title);
ImageView doneButton = findViewById(R.id.img_done);

// Get current language
currentLanguageCode = LocaleHelper.getSavedLanguage(this);

// Setup RecyclerView
languageList = createLanguageList();
adapter = new LanguageAdapter(languageList, this::onLanguageSelected);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);

// Update selection UI
adapter.updateSelection(currentLanguageCode);

// Done button click handler
doneButton.setOnClickListener(v -> finish());

// Set title
titleText.setText(getString(R.string.language));
}

private List<LanguageModel> createLanguageList() {
List<LanguageModel> list = new ArrayList<>();
String[] languageCodes = {"en", "zh", "hi", "es", "ar", "fr", "bn", "pt", "ru", "ur"};
String[] languageNames = {
getString(R.string.language_english),
getString(R.string.language_chinese),
getString(R.string.language_hindi),
getString(R.string.language_spanish),
getString(R.string.language_arabic),
getString(R.string.language_french),
getString(R.string.language_bengali),
getString(R.string.language_portuguese),
getString(R.string.language_russian),
getString(R.string.language_urdu)
};

for (int i = 0; i < languageCodes.length; i++) {
boolean isSelected = languageCodes[i].equals(currentLanguageCode);
list.add(new LanguageModel(languageCodes[i], languageNames[i], isSelected));
}

return list;
}

private void onLanguageSelected(LanguageModel language) {
String selectedLanguageCode = language.getLanguageCode();

if (!selectedLanguageCode.equals(currentLanguageCode)) {
// Save and apply new language
LocaleHelper.setLocale(this, selectedLanguageCode);

// Update current language
currentLanguageCode = selectedLanguageCode;

// Update adapter selection
adapter.updateSelection(selectedLanguageCode);

// Restart activity to apply language changes immediately
recreate();
}
}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleHelper.attachBaseContext(newBase));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public void onClick(View v) {
binding.relLang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Toast.makeText(requireContext(), "Coming Soon", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), LanguageActivity.class);
startActivity(intent);
}
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/res/layout/item_language.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="?android:attr/selectableItemBackground">

<TextView
android:id="@+id/txt_language_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="English"
android:textSize="16sp"
android:textColor="@color/black" />

<ImageView
android:id="@+id/img_selected"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_done_24"
android:visibility="gone" />
Comment on lines +25 to +33
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

Add contentDescription for accessibility.

The ImageView is missing a contentDescription attribute, which is important for accessibility. Screen readers need this to describe the checkmark icon to visually impaired users.

🔎 Proposed fix
     <ImageView
         android:id="@+id/img_selected"
         android:layout_width="24dp"
         android:layout_height="24dp"
         android:layout_alignParentEnd="true"
         android:layout_centerVertical="true"
         android:src="@drawable/ic_done_24"
+        android:contentDescription="@string/selected"
         android:visibility="gone" />

Note: You'll need to add a string resource selected to your strings.xml files (e.g., "Selected" in English, with appropriate translations).

📝 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
<ImageView
android:id="@+id/img_selected"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_done_24"
android:visibility="gone" />
<ImageView
android:id="@+id/img_selected"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_done_24"
android:contentDescription="@string/selected"
android:visibility="gone" />
🤖 Prompt for AI Agents
In app/src/main/res/layout/item_language.xml around lines 17 to 24 the ImageView
lacks a contentDescription which breaks accessibility; add
android:contentDescription="@string/selected" to the ImageView and create a
string resource named "selected" in res/values/strings.xml (and corresponding
translations in other locale files) with an appropriate label such as
"Selected".


</RelativeLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>
<string name="app_name">UpdateApp</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
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 | 🟡 Minor

Translate or document untranslated strings.

The app_name and hello_blank_fragment strings remain in English. While app names sometimes stay in English by design, ensure this is intentional. The hello_blank_fragment string appears to be a placeholder and should either be translated or removed if unused.

🤖 Prompt for AI Agents
In app/src/main/res/values-ar/strings.xml around lines 2-3, the strings app_name
("UpdateApp") and hello_blank_fragment ("Hello blank fragment") are
untranslated/placeholders; either provide Arabic translations for both (or
confirm app_name intentionally stays English) or remove/replace the
hello_blank_fragment entry if it’s unused. Update the XML values to the correct
Arabic text for each string key or delete the unused key, and if you keep
app_name in English add a comment in the English strings or a note in project
docs confirming it’s intentional.

<string name="default_web_client_id">610596201338-8jkqtv5msdu5q7mi0qs0gho2tu8a8esv.apps.googleusercontent.com</string>
<string name="language">اللغة</string>
<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>
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

Critical: Incomplete localization - only language selection strings present.

This file contains only language selection UI strings. Per the reviewer's feedback, this is a blocking issue for PR approval and payment. The requirement is explicit: all visible text must be moved to strings.xml with the same string keys across all languages.

Missing localizations include but are not limited to:

  • Login/signup screen labels, buttons, and validation messages
  • Profile screen text and actions
  • Navigation labels and menu items
  • Error messages, toasts, and dialogs
  • All other user-facing text throughout the app

Without complete localization, switching to Arabic will only affect the LanguageActivity screen—exactly the issue the reviewer reported: "locale change only affects LanguageActivity; other screens (login, signup, profile, buttons, messages) do not update."

Required action: Add complete string resources for every user-facing text element in the app, ensuring the same string keys exist across all locale files (values/, values-ar/, values-zh/, etc.) with appropriate translations for each language.

Would you like me to help generate a comprehensive list of string keys that should be present across all locale files, or search the codebase to identify hardcoded strings that need to be externalized?

🤖 Prompt for AI Agents
In app/src/main/res/values-ar/strings.xml around lines 5-15, this Arabic file
currently only contains language-selection strings; you must add the full set of
user-facing string keys (matching the base values/strings.xml keys exactly) so
every screen updates on locale change. Fix by extracting any hardcoded UI text
from layouts/activities/fragments into strings.xml (login/signup labels,
buttons, validation messages, profile screen text, navigation/menu labels,
dialogs/toasts/errors, toolbars, placeholders, etc.), ensure each key present in
values/strings.xml is also present in values-ar/strings.xml with Arabic
translations, scan the codebase for hardcoded strings and replace them with
getString(R.string.<key>), and update other locale folders (values-zh,
values-fr, etc.) to keep keys consistent across all locales.

</resources>
16 changes: 16 additions & 0 deletions app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>
<string name="app_name">UpdateApp</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="default_web_client_id">610596201338-8jkqtv5msdu5q7mi0qs0gho2tu8a8esv.apps.googleusercontent.com</string>
<string name="language">ভাষা</string>
<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>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
</resources>
Loading