Repository navigation
Update from task ee42c794-bbdb-4ba0-8b66-fc4c6c31295c - #7
Conversation
…, and Arabic localization Key features implemented: - Created comprehensive TODO.md tracking development progress and immediate next steps - Implemented AndroidManifest.xml with extensive permissions for storage, P2P sharing, and networking - Added medical.db and medical_arabic.db with emergency protocols in both languages - Created launcher icons and theme resources for consistent UI appearance - Developed PeerSharingService.kt enabling APK and asset sharing via Bluetooth/WiFi - Built SharingScreen.kt with UI for sharing app, database, or all assets - Implemented generate_cheat_sheets.py to create print-ready PDF emergency guides - Extended SettingsScreen.kt with sharing and print navigation options - Added proguard-rules.pro for proper code obfuscation - Created database population script with Arabic protocol translations The application now includes complete build configuration, core assets, P2P sharing capabilities, print-ready emergency guides, and Arabic localization support while maintaining offline functionality for crisis zones.
|
Strix is installed on this repository, but we couldn't run this PR security review because this workspace's trial has ended. Add a card to resume code reviews here. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's GuideAdds offline medical content assets and P2P sharing capabilities, enhances the Settings UI with navigation to sharing/cheat sheets, and introduces build/configuration files and resources needed to run and distribute Hayat AI on Android. Sequence diagram for new P2P sharing flow from Settings to PeerSharingServicesequenceDiagram
actor User
participant SettingsScreen
participant SharingScreen
participant SharingViewModel
participant PeerSharingService
participant FileProvider
User->>SettingsScreen: tap ShareHayatAI menuItem
SettingsScreen->>SharingScreen: onNavigateToSharing()
User->>SharingScreen: tap SharingOptionCard
SharingScreen->>SharingOption: onClick()
SharingOption->>SharingViewModel: shareApk(context) / shareDatabase(context) / shareAllAssets(context)
SharingViewModel->>PeerSharingService: shareApk() / shareDatabase() / shareAllAssets()
PeerSharingService->>FileProvider: getUriForFile(context, authority, file)
FileProvider-->>PeerSharingService: Uri
PeerSharingService-->>SharingViewModel: Result<Uri> / Result<List<Uri>>
SharingViewModel-->>SharingScreen: Result
SharingScreen-->>User: update isSharing, shareMessage
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (20)
✨ Finishing Touches📝 Generate docstrings
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 |
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 10 high |
🟢 Metrics 48 complexity · 0 duplication
Metric Results Complexity 48 Duplication 0
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Hey - I've found 4 issues, and left some high level feedback:
- SharingScreen currently references Icons.Default.Database which does not exist in material-icons-extended; replace it with a valid icon (e.g. Icons.Default.Storage) to avoid compile errors.
- The SharingOption.action type is declared as suspend () -> Result, but the lambdas return Result/Result<List>; align the function type with a concrete or generic Result type (e.g. Result, Result<List>, or a generic parameter) to avoid type mismatch at compile time.
- PeerSharingService and SettingsScreen use types that are not imported (FileNotFoundException and Color respectively); add the appropriate imports or fully qualify these names to ensure the project builds correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- SharingScreen currently references Icons.Default.Database which does not exist in material-icons-extended; replace it with a valid icon (e.g. Icons.Default.Storage) to avoid compile errors.
- The SharingOption.action type is declared as suspend () -> Result<Any>, but the lambdas return Result<Uri>/Result<List<Uri>>; align the function type with a concrete or generic Result type (e.g. Result<Uri>, Result<List<Uri>>, or a generic parameter) to avoid type mismatch at compile time.
- PeerSharingService and SettingsScreen use types that are not imported (FileNotFoundException and Color respectively); add the appropriate imports or fully qualify these names to ensure the project builds correctly.
## Individual Comments
### Comment 1
<location path="app/src/main/java/com/hayat/ui/screens/SharingScreen.kt" line_range="33-42" />
<code_context>
+ var isSharing by remember { mutableStateOf(false) }
</code_context>
<issue_to_address>
**issue (bug_risk):** Success/error state is never reset, so error messages can be displayed with success styling.
`showSuccess` is set to `true` on success but never reset to `false` before subsequent attempts or on failure. As a result, a failed share after a successful one shows the error inside a success-styled card. Reset `showSuccess` at the start of the click handler and/or in the failure branch so the visual state matches the outcome.
</issue_to_address>
### Comment 2
<location path="app/src/main/java/com/hayat/ui/screens/SharingScreen.kt" line_range="274-282" />
<code_context>
+
+ private val sharingService = PeerSharingService(context)
+
+ suspend fun shareApk(context: android.content.Context): Result<android.net.Uri> {
+ return sharingService.shareApk()
+ }
+
+ suspend fun shareDatabase(context: android.content.Context): Result<android.net.Uri> {
+ return sharingService.shareDatabase()
+ }
+
+ suspend fun shareAllAssets(context: android.content.Context): Result<List<android.net.Uri>> {
+ return sharingService.shareAllAssets()
+ }
</code_context>
<issue_to_address>
**suggestion:** SharingViewModel methods accept a Context parameter that is unused and redundant.
`SharingViewModel` already receives a `Context` in its constructor and uses it to create `PeerSharingService`. The `context` parameters in `shareApk`, `shareDatabase`, and `shareAllAssets` are never used and only propagated through composables and option definitions. Dropping these parameters and relying on the injected context will make the API clearer and avoid ambiguity about which `Context` is in effect.
Suggested implementation:
```
class SharingViewModel(private val context: android.content.Context) : androidx.lifecycle.ViewModel() {
private val sharingService = PeerSharingService(context)
suspend fun shareApk(context: android.content.Context): Result<android.net.Uri> {
return sharingService.shareApk()
}
suspend fun shareDatabase(context: android.content.Context): Result<android.net.Uri> {
return sharingService.shareDatabase()
}
suspend fun shareAllAssets(context: android.content.Context): Result<List<android.net.Uri>> {
return sharingService.shareAllAssets()
}
```
```
val icon: androidx.compose.ui.graphics.vector.ImageVector,
val title: String,
val description: String,
val action: suspend () -> Result<Any>
)
```
To fully apply this change across the file/codebase, you also need to:
1. Update all call sites that currently invoke these methods with a `Context` argument:
- Replace `viewModel.shareApk(context)` with `viewModel.shareApk()`.
- Replace `viewModel.shareDatabase(context)` with `viewModel.shareDatabase()`.
- Replace `viewModel.shareAllAssets(context)` with `viewModel.shareAllAssets()`.
2. Ensure any option definitions or composables that previously required a `Context` solely to pass into these methods no longer take or propagate that `Context` parameter where it's now unnecessary.
3. If there are function types like `suspend (android.content.Context) -> Result<Any>` used for actions tied to these methods, change them to `suspend () -> Result<Any>` and adjust the lambdas accordingly (e.g., `{ viewModel.shareApk() }`).
</issue_to_address>
### Comment 3
<location path="app/src/main/java/com/hayat/services/PeerSharingService.kt" line_range="63-72" />
<code_context>
+ val dbFile = File("/sdcard/Hayat/medical.db")
</code_context>
<issue_to_address>
**🚨 issue (security):** Hardcoded `/sdcard/Hayat` paths and broad storage permissions raise robustness and security concerns.
Directly using `/sdcard/Hayat/...` couples the app to a specific storage layout and typically requires broad permissions like `MANAGE_EXTERNAL_STORAGE`, which are discouraged and may be rejected on newer Android/Play Store targets. Prefer app-specific external directories (e.g. via `Context.getExternalFilesDir`) or the Storage Access Framework so paths are derived from the platform and you avoid high‑risk, blanket storage access.
</issue_to_address>
### Comment 4
<location path="scripts/generate_cheat_sheets.py" line_range="120-129" />
<code_context>
+ title_style = ParagraphStyle(
</code_context>
<issue_to_address>
**suggestion:** Arabic content is rendered with left-aligned, LTR-oriented styles, which may hurt readability.
For the Arabic sections in both single-language and bilingual cheat sheets, the paragraphs currently reuse the English styles (including left alignment). For RTL text, consider using `alignment=TA_RIGHT` and an Arabic-capable font registered via `TTFont` to improve readability and avoid shaping issues. Defining dedicated styles for Arabic headers and body text and applying them in the `language == "ar"` branches would address this.
Suggested implementation:
```python
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
```
```python
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
```
```python
styles = getSampleStyleSheet()
# Register Arabic-capable font for RTL sections
# NOTE: Make sure the path points to an actual Arabic-capable TTF file in your project.
pdfmetrics.registerFont(TTFont("ArabicFont", "fonts/ArabicFont.ttf"))
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
# Arabic-specific styles for RTL content
arabic_title_style = ParagraphStyle(
'ArabicTitle',
parent=styles['Heading1'],
fontName="ArabicFont",
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_RIGHT
)
arabic_body_style = ParagraphStyle(
'ArabicBody',
parent=styles['BodyText'],
fontName="ArabicFont",
fontSize=10,
leading=12,
spaceAfter=6,
alignment=TA_RIGHT
)
step_style = ParagraphStyle(
'StepStyle',
```
`).
Here are the concrete edits:
<file_operations>
<file_operation operation="edit" file_path="scripts/generate_cheat_sheets.py">
<<<<<<< SEARCH
from reportlab.lib.enums import TA_CENTER
=======
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
>>>>>>> REPLACE
<<<<<<< SEARCH
from reportlab.lib.pagesizes import A4
=======
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
>>>>>>> REPLACE
<<<<<<< SEARCH
styles = getSampleStyleSheet()
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
step_style = ParagraphStyle(
'StepStyle',
=======
styles = getSampleStyleSheet()
# Register Arabic-capable font for RTL sections
# NOTE: Make sure the path points to an actual Arabic-capable TTF file in your project.
pdfmetrics.registerFont(TTFont("ArabicFont", "fonts/ArabicFont.ttf"))
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
# Arabic-specific styles for RTL content
arabic_title_style = ParagraphStyle(
'ArabicTitle',
parent=styles['Heading1'],
fontName="ArabicFont",
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_RIGHT
)
arabic_body_style = ParagraphStyle(
'ArabicBody',
parent=styles['BodyText'],
fontName="ArabicFont",
fontSize=10,
leading=12,
spaceAfter=6,
alignment=TA_RIGHT
)
step_style = ParagraphStyle(
'StepStyle',
>>>>>>> REPLACE
</file_operation>
</file_operations>
<additional_changes>
To fully apply these styles:
1. In the sections where the cheat sheets are built, update the `language == "ar"` branches to use `arabic_title_style` for Arabic headers and `arabic_body_style` (or another Arabic-specific style if you have one for steps) for Arabic paragraph content, instead of `title_style` and the existing English paragraph styles.
2. Ensure the font file `"fonts/ArabicFont.ttf"` exists in your project and supports Arabic shaping; if your project already uses a specific Arabic font, reuse that font name/path instead of `"ArabicFont"` and `"fonts/ArabicFont.ttf"`.
3. If there are bilingual sections where Arabic and English are mixed, make sure the Arabic fragments use the Arabic styles while English fragments continue to use the existing LTR styles.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| var isSharing by remember { mutableStateOf(false) } | ||
| var shareMessage by remember { mutableStateOf("") } | ||
| var showSuccess by remember { mutableStateOf(false) } | ||
|
|
||
| val sharingOptions = listOf( | ||
| SharingOption( | ||
| icon = Icons.Default.Share, | ||
| title = "Share App (APK)", | ||
| description = "Share the Hayat AI application with others via Bluetooth or messaging apps", | ||
| action = { viewModel.shareApk(context) } |
There was a problem hiding this comment.
issue (bug_risk): Success/error state is never reset, so error messages can be displayed with success styling.
showSuccess is set to true on success but never reset to false before subsequent attempts or on failure. As a result, a failed share after a successful one shows the error inside a success-styled card. Reset showSuccess at the start of the click handler and/or in the failure branch so the visual state matches the outcome.
| suspend fun shareApk(context: android.content.Context): Result<android.net.Uri> { | ||
| return sharingService.shareApk() | ||
| } | ||
|
|
||
| suspend fun shareDatabase(context: android.content.Context): Result<android.net.Uri> { | ||
| return sharingService.shareDatabase() | ||
| } | ||
|
|
||
| suspend fun shareAllAssets(context: android.content.Context): Result<List<android.net.Uri>> { |
There was a problem hiding this comment.
suggestion: SharingViewModel methods accept a Context parameter that is unused and redundant.
SharingViewModel already receives a Context in its constructor and uses it to create PeerSharingService. The context parameters in shareApk, shareDatabase, and shareAllAssets are never used and only propagated through composables and option definitions. Dropping these parameters and relying on the injected context will make the API clearer and avoid ambiguity about which Context is in effect.
Suggested implementation:
class SharingViewModel(private val context: android.content.Context) : androidx.lifecycle.ViewModel() {
private val sharingService = PeerSharingService(context)
suspend fun shareApk(context: android.content.Context): Result<android.net.Uri> {
return sharingService.shareApk()
}
suspend fun shareDatabase(context: android.content.Context): Result<android.net.Uri> {
return sharingService.shareDatabase()
}
suspend fun shareAllAssets(context: android.content.Context): Result<List<android.net.Uri>> {
return sharingService.shareAllAssets()
}
val icon: androidx.compose.ui.graphics.vector.ImageVector,
val title: String,
val description: String,
val action: suspend () -> Result<Any>
)
To fully apply this change across the file/codebase, you also need to:
- Update all call sites that currently invoke these methods with a
Contextargument:- Replace
viewModel.shareApk(context)withviewModel.shareApk(). - Replace
viewModel.shareDatabase(context)withviewModel.shareDatabase(). - Replace
viewModel.shareAllAssets(context)withviewModel.shareAllAssets().
- Replace
- Ensure any option definitions or composables that previously required a
Contextsolely to pass into these methods no longer take or propagate thatContextparameter where it's now unnecessary. - If there are function types like
suspend (android.content.Context) -> Result<Any>used for actions tied to these methods, change them tosuspend () -> Result<Any>and adjust the lambdas accordingly (e.g.,{ viewModel.shareApk() }).
| val dbFile = File("/sdcard/Hayat/medical.db") | ||
|
|
||
| if (!dbFile.exists()) { | ||
| Log.e(TAG, "Database file not found") | ||
| return@withContext Result.failure(FileNotFoundException("Database not found")) | ||
| } | ||
|
|
||
| val uri = FileProvider.getUriForFile( | ||
| context, | ||
| "${context.packageName}.fileprovider", |
There was a problem hiding this comment.
🚨 issue (security): Hardcoded /sdcard/Hayat paths and broad storage permissions raise robustness and security concerns.
Directly using /sdcard/Hayat/... couples the app to a specific storage layout and typically requires broad permissions like MANAGE_EXTERNAL_STORAGE, which are discouraged and may be rejected on newer Android/Play Store targets. Prefer app-specific external directories (e.g. via Context.getExternalFilesDir) or the Storage Access Framework so paths are derived from the platform and you avoid high‑risk, blanket storage access.
| title_style = ParagraphStyle( | ||
| 'CustomTitle', | ||
| parent=styles['Heading1'], | ||
| fontSize=18, | ||
| textColor=colors.darkred, | ||
| spaceAfter=12, | ||
| alignment=TA_CENTER | ||
| ) | ||
|
|
||
| step_style = ParagraphStyle( |
There was a problem hiding this comment.
suggestion: Arabic content is rendered with left-aligned, LTR-oriented styles, which may hurt readability.
For the Arabic sections in both single-language and bilingual cheat sheets, the paragraphs currently reuse the English styles (including left alignment). For RTL text, consider using alignment=TA_RIGHT and an Arabic-capable font registered via TTFont to improve readability and avoid shaping issues. Defining dedicated styles for Arabic headers and body text and applying them in the language == "ar" branches would address this.
Suggested implementation:
from reportlab.lib.enums import TA_CENTER, TA_RIGHTfrom reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont styles = getSampleStyleSheet()
# Register Arabic-capable font for RTL sections
# NOTE: Make sure the path points to an actual Arabic-capable TTF file in your project.
pdfmetrics.registerFont(TTFont("ArabicFont", "fonts/ArabicFont.ttf"))
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
# Arabic-specific styles for RTL content
arabic_title_style = ParagraphStyle(
'ArabicTitle',
parent=styles['Heading1'],
fontName="ArabicFont",
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_RIGHT
)
arabic_body_style = ParagraphStyle(
'ArabicBody',
parent=styles['BodyText'],
fontName="ArabicFont",
fontSize=10,
leading=12,
spaceAfter=6,
alignment=TA_RIGHT
)
step_style = ParagraphStyle(
'StepStyle',`).
Here are the concrete edits:
<file_operations>
<file_operation operation="edit" file_path="scripts/generate_cheat_sheets.py">
<<<<<<< SEARCH
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
REPLACE
<<<<<<< SEARCH
from reportlab.lib.pagesizes import A4
from reportlab.lib.pagesizes import A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
REPLACE
<<<<<<< SEARCH
styles = getSampleStyleSheet()
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
step_style = ParagraphStyle(
'StepStyle',
=======
styles = getSampleStyleSheet()
# Register Arabic-capable font for RTL sections
# NOTE: Make sure the path points to an actual Arabic-capable TTF file in your project.
pdfmetrics.registerFont(TTFont("ArabicFont", "fonts/ArabicFont.ttf"))
# Custom styles
title_style = ParagraphStyle(
'CustomTitle',
parent=styles['Heading1'],
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_CENTER
)
# Arabic-specific styles for RTL content
arabic_title_style = ParagraphStyle(
'ArabicTitle',
parent=styles['Heading1'],
fontName="ArabicFont",
fontSize=18,
textColor=colors.darkred,
spaceAfter=12,
alignment=TA_RIGHT
)
arabic_body_style = ParagraphStyle(
'ArabicBody',
parent=styles['BodyText'],
fontName="ArabicFont",
fontSize=10,
leading=12,
spaceAfter=6,
alignment=TA_RIGHT
)
step_style = ParagraphStyle(
'StepStyle',
REPLACE
</file_operation>
</file_operations>
<additional_changes>
To fully apply these styles:
- In the sections where the cheat sheets are built, update the
language == "ar"branches to usearabic_title_stylefor Arabic headers andarabic_body_style(or another Arabic-specific style if you have one for steps) for Arabic paragraph content, instead oftitle_styleand the existing English paragraph styles. - Ensure the font file
"fonts/ArabicFont.ttf"exists in your project and supports Arabic shaping; if your project already uses a specific Arabic font, reuse that font name/path instead of"ArabicFont"and"fonts/ArabicFont.ttf". - If there are bilingual sections where Arabic and English are mixed, make sure the Arabic fragments use the Arabic styles while English fragments continue to use the existing LTR styles.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
This PR was created by qwen-chat coder for task ee42c794-bbdb-4ba0-8b66-fc4c6c31295c.
Summary by Sourcery
Introduce P2P sharing and printable emergency cheat sheets, and set up core Android app configuration for Hayat AI.
New Features:
Enhancements:
Build:
Documentation: