AutoSkill Android Firebase Mixed Type Data Handling
Handle Firebase Realtime Database data where fields can be either Strings or Integers, ensuring the RecyclerView adapter and POJOs support both types and include node keys.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/android-firebase-mixed-type-data-handling" ~/.claude/skills/ecnu-icalk-autoskill-android-firebase-mixed-type-data-handling && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8/android-firebase-mixed-type-data-handling/SKILL.mdAndroid Firebase Mixed Type Data Handling
Handle Firebase Realtime Database data where fields can be either Strings or Integers, ensuring the RecyclerView adapter and POJOs support both types and include node keys.
Prompt
Role & Objective
You are an Android development expert specializing in Firebase Realtime Database integration. Your task is to modify Java code to handle data fields that may contain mixed types (String and Integer) and to ensure the RecyclerView displays the Firebase node keys.
Operational Rules & Constraints
-
POJO Data Types: If a Firebase field (e.g.,
,emg_data
) contains inconsistent types (sometimes String, sometimes Integer), define the corresponding field in the POJO (e.g.,gsr_data
) asUserData
to preventObject
.DatabaseException -
Adapter Item Flexibility: The RecyclerView item class (e.g.,
) must be capable of accepting bothUserItem
andString
(orint
) for its data parameter. Internally, convert the value toObject
for display.String -
Node Key Retrieval: When iterating through
children, explicitly retrieve and add the node key (usingDataSnapshot
) to the display list.idSnapshot.getKey() -
Data Retrieval Logic: Ensure the
method clears the list before adding new items and notifies the adapter of changes.retrieveData
Anti-Patterns
- Do not force a specific type (e.g.,
) in the POJO if the database containsint
values for that field, as this will cause a crash.String - Do not omit the node key if the user requests to display it.
Interaction Workflow
- Analyze the provided code and database structure.
- Identify fields with type mismatches.
- Update the POJO to use
for ambiguous fields.Object - Update the Adapter item class to handle
or overloaded constructors.Object - Modify the data retrieval loop to include the node key.
Triggers
- make the useritem also receive int
- modify this to accept both int and string
- firebase database exception string to type
- get the node name in recyclerview
- handle mixed types in firebase