Commit cbcec65
Fix/parcelable systemmessageentry (#26)
* fix: Address import crash, enhance logging, and refine UI
This commit addresses several issues and incorporates your feedback:
1. **Import Crash (Signal 9 Fix)**:
* File reading and JSON parsing operations during file import are now performed on a background thread using Kotlin Coroutines. This prevents ANRs that could lead to a SIGKILL.
* A file size check (e.g., max 10MB) is implemented before attempting to read the file content to mitigate OutOfMemoryErrors with very large files.
* Specific OutOfMemoryError catching added for better error reporting.
* UI updates (Toasts, dialog state changes) are correctly dispatched back to the Main thread.
2. **Extensive Logging for Import**:
* Comprehensive logging has been added throughout the entire import process. This includes URI handling, file reading (with size and snippets), JSON parsing, duplicate checking logic, dialog interactions, and SharedPreferences operations to aid in future debugging.
3. **UI Refinements (`DatabaseListPopup`)**:
* **"Export" Button Text**: The text on the "Export" button now consistently remains "Export" and no longer changes to "Share" when selection mode is active. The button's onClick behavior remains conditional.
* **"All" Checkbox Repositioning**: The "Select All/None" checkbox and its "All" text in the footer are now positioned on the left side. The footer Row uses `Arrangement.SpaceBetween` to keep Import/Export buttons to the right, and a Spacer is used to maintain layout stability when the "All" checkbox is hidden. Vertical alignment with row checkboxes should be consistent.
* fix: Resolve compilation errors and revert button style
This commit addresses compilation errors from the previous major update and reverts a recent button styling change based on your feedback.
- Reverted the main "Database" button on PhotoReasoningScreen to have a 1.dp black border, undoing the previous modification that made it borderless.
- Fixed Toast.makeText overload resolution ambiguity by explicitly casting dynamic string content to CharSequence to aid compiler type inference.
- Corrected the call to the `processImportedEntries` helper function in `DatabaseListPopup` to match its actual definition, removing named lambda parameters (e.g., `askForOverwrite`, `shouldSkipAll`) that were causing compilation errors. The function accesses necessary state and callbacks from its surrounding scope.
* Okay, I've made some corrections to the import logic and Toasts to address the compilation errors you were seeing.
Specifically, I've:
- Adjusted how the `processImportedEntries` helper function is called throughout the DatabaseListPopup to ensure it matches its definition. This should clear up errors related to incorrect parameters.
- Clarified the `Toast.makeText` calls by explicitly casting string variables to `CharSequence` to resolve any ambiguity.
- Restored the 1.dp black border to the main "Database" button, as you requested.
* fix: Resolve critical compilation errors
This commit addresses several compilation errors that prevented the build from succeeding, primarily in the import/export functionality of the system message database.
- Added missing Kotlin Coroutine imports (`Dispatchers`, `launch`, `withContext`) to `PhotoReasoningScreen.kt` to resolve "Unresolved reference: withContext" errors.
- Corrected all call sites of the internal `processImportedEntries` helper function within `DatabaseListPopup`. Calls now strictly match the function's defined parameters (expecting only `imported` and `currentSystemEntries` lists). This fixes errors related to missing parameters, incorrect argument counts, and type mismatches.
- Ensured that `Toast.makeText` calls using dynamic string content (variables or template strings) have their text argument explicitly cast to `CharSequence` to resolve "Overload resolution ambiguity" errors.
* fix: Resolve "Expecting a top level declaration" and other compilation errors
This commit addresses a critical "Expecting a top level declaration" syntax error in `PhotoReasoningScreen.kt`, likely caused by extraneous content at the end of the file. I've corrected the file to ensure it ends cleanly after the last valid composable declaration.
Additionally, this commit re-applies and verifies fixes for previously targeted compilation errors:
- Ensures correct Kotlin Coroutine imports (`Dispatchers`, `launch`, `withContext`) are present.
- Corrects all call sites of the internal `processImportedEntries` helper function within `DatabaseListPopup` to strictly match its defined parameters.
- Ensures `Toast.makeText` calls using dynamic string content have their text argument explicitly cast to `CharSequence`.
* Update PhotoReasoningScreen.kt
* Fix: Make SystemMessageEntry Parcelable to prevent crash
Makes the `SystemMessageEntry` class implement `android.os.Parcelable`
using the `@Parcelize` annotation. This is to resolve an
`IllegalArgumentException: Parcel: unknown type for value SystemMessageEntry`
that occurred when instances of this class were processed in a way
that required them to be Parcelable, such as being saved with
`rememberSaveable` or in a Bundle during Activity state restoration,
particularly in `PhotoReasoningScreen.kt`.
Automated testing of this change could not be completed due to
limitations in the build environment (missing Android SDK).
The change follows standard Android development practices for resolving
this type of serialization error.
* Update local.properties
* Fix: Add kotlin-parcelize plugin to app build.gradle
Adds the `kotlin-parcelize` Gradle plugin to the `app/build.gradle.kts`
file. This is necessary to resolve compilation errors such as
"Unresolved reference: parcelize" and issues with Parcelable
implementation (missing `describeContents()`) when using the
`@Parcelize` annotation.
This change addresses build failures encountered after making
`SystemMessageEntry` Parcelable. The previous changes
correctly updated the data class, and this provides the
necessary build tooling support for it.
* Refactor: Align kotlin.plugin.serialization version with Kotlin version
I've updated the version of the `org.jetbrains.kotlin.plugin.serialization`
Gradle plugin in `app/build.gradle.kts` from `1.9.0` to `1.9.20`.
This aligns it with your project's overall Kotlin version (`1.9.20`),
which is a general best practice.
I made this change following attempts to resolve a build failure
related to the `kotlin-parcelize` plugin. While this specific change
might not directly address the `parcelize` resolution if the root cause
lies elsewhere (e.g., your CI environment not using latest commits), it
ensures better consistency in Kotlin plugin versions.
* Feature: Reorder AI prompt components
Modifies PhotoReasoningViewModel.kt to change the order in which
information is sent to the Generative AI model. The new order is:
1. System Message (as the first message in the chat history with "user" role)
2. Chat History (previous user/model messages)
3. Current User Input
Previously, the system message was prepended to the current user input.
This change makes the system message a more distinct initial instruction
for the AI model.
Changes include:
- Modified `rebuildChatHistory()` to prepend the system message.
- Modified `clearChatHistory()` to initialize with the system message.
- Removed system message prepending from the `reason()` method.
Note: The `com.google.ai.client.generativeai` SDK (version 0.9.0)
used in this application is deprecated. You should consider migrating
to the recommended Firebase SDK for future development and potentially
more robust support for system instructions.
Automated testing of this change could not be completed due to
persistent Android SDK configuration issues in the test environment.
* I've made some changes to `PhotoReasoningViewModel.kt` to include the content of your System Message Database in the context sent to the Generative AI model with each request.
Here’s how the information will now be ordered:
1. Active System Message
2. Formatted System Message Database Entries (as a single text block)
3. Chat History (previous messages between you and the model)
4. Your Current Input
I implemented this change based on your request.
To make this work, I added a helper function called `formatDatabaseEntriesAsText` to format the database entries. I also updated `rebuildChatHistory` and `clearChatHistory` to include this formatted text in the chat history sent to the model.
Here are some potential impacts to keep in mind:
- This will significantly increase the data payload sent to the AI, which might affect token limits, cost, and how quickly it responds.
- The model's behavior might change because of the larger and more varied initial context. I recommend you test this thoroughly.
A quick note on the SDK:
The `com.google.ai.client.generativeai` SDK (version 0.9.0) used in this application is deprecated. You might want to consider migrating to the recommended Firebase SDK for future development.
Regarding testing:
I wasn't able to complete automated testing for this change due to some persistent Android SDK configuration issues in the test environment.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>1 parent 058e9df commit cbcec65
File tree
7 files changed
+258
-130
lines changed- app
- src/main/kotlin/com/google/ai/sample
- feature/multimodal
- util
7 files changed
+258
-130
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
Lines changed: 184 additions & 93 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 96 | + | |
102 | 97 | | |
103 | 98 | | |
104 | 99 | | |
| |||
452 | 447 | | |
453 | 448 | | |
454 | 449 | | |
455 | | - | |
| 450 | + | |
456 | 451 | | |
457 | 452 | | |
458 | 453 | | |
| |||
462 | 457 | | |
463 | 458 | | |
464 | 459 | | |
465 | | - | |
| 460 | + | |
466 | 461 | | |
467 | 462 | | |
468 | 463 | | |
469 | 464 | | |
470 | 465 | | |
471 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
472 | 485 | | |
473 | 486 | | |
474 | 487 | | |
| |||
513 | 526 | | |
514 | 527 | | |
515 | 528 | | |
516 | | - | |
| 529 | + | |
517 | 530 | | |
518 | 531 | | |
519 | 532 | | |
| |||
522 | 535 | | |
523 | 536 | | |
524 | 537 | | |
525 | | - | |
| 538 | + | |
526 | 539 | | |
527 | 540 | | |
528 | 541 | | |
| |||
532 | 545 | | |
533 | 546 | | |
534 | 547 | | |
535 | | - | |
| 548 | + | |
536 | 549 | | |
537 | 550 | | |
538 | 551 | | |
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
542 | | - | |
| 555 | + | |
543 | 556 | | |
544 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
545 | 569 | | |
546 | | - | |
| 570 | + | |
547 | 571 | | |
548 | 572 | | |
549 | 573 | | |
| |||
597 | 621 | | |
598 | 622 | | |
599 | 623 | | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
600 | 627 | | |
601 | 628 | | |
602 | 629 | | |
603 | 630 | | |
604 | 631 | | |
605 | 632 | | |
606 | | - | |
| 633 | + | |
607 | 634 | | |
608 | 635 | | |
609 | 636 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
614 | 648 | | |
615 | 649 | | |
616 | 650 | | |
| |||
627 | 661 | | |
628 | 662 | | |
629 | 663 | | |
630 | | - | |
| 664 | + | |
631 | 665 | | |
632 | 666 | | |
633 | 667 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | | - | |
| 12 | + | |
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| 57 | + | |
53 | 58 | | |
54 | | - | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| 63 | + | |
58 | 64 | | |
59 | | - | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
File mode changed.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 1 | + | |
0 commit comments