Skip to content

Element Info Activity

Jonatan Lindemann edited this page Aug 3, 2025 · 2 revisions

InfoExtension Abstract Class

The InfoExtension class is an abstract base class handles data loading, UI population, note management, achievements, statistics, and more for the element details page.


Features

Data Loading

  • Reads element data from asset JSON files, parses it, and updates the UI.
  • Handles errors gracefully, displaying a message if loading fails.

UI Management

  • Populates a wide range of UI components with element properties, including:
    • Name, discovery info, physical and chemical properties, electron configuration, hazards, and more.
  • Dynamically updates UI for next/previous navigation and element-specific content.
  • Supports pro-version features for advanced data (e.g., speeds of sound, modulus, hardness).

Note Management

  • Each element supports user notes, stored in shared preferences as XML-like tagged strings.
  • Only one TextWatcher is attached per EditText, preventing bugs with note overwrites.
  • Notes are loaded and saved in real time as users edit them.

Achievements and Statistics

  • Tracks user progress viewing elements and awards achievements.
  • Increments statistics each time an element is viewed.

Preferences and Customization

  • Many UI sections are shown/hidden based on user preferences (e.g., favorite bar, various property layouts).
  • Temperature units and other display options are customizable.

Media and External Links

  • Loads element images, 3D models, and emission spectra with Picasso.
  • Opens Wikipedia links in custom Chrome tabs if available.

Key Methods

  • readJson(): Loads current element data from a JSON file and triggers UI update.
  • updateElementUI(jsonObject: JSONObject): Populates all UI fields with parsed element data.
  • handleNotes(elementCode: String, eText: EditText): Loads, displays, and saves element-specific notes. Ensures only one TextWatcher is active.
  • setOxidationStates(oxidationNeg1: String, oxidationPos1: String): Updates UI for oxidation state badges.
  • setHazards(...): Populates hazard labels and explanations.
  • favoriteBarSetup(): Shows/hides favorite bar sections based on preferences.
  • wikiListener(url: String?): Sets up Wikipedia button to open links in Chrome Custom Tabs.
  • formatSuperscript(text: String): Formats strings with superscript Unicode for display (used in electron configs, etc.).
  • updateAchievementProgress(increment: Int), updateStats(): Updates user achievements and stats.

Notes on Bug Fixes

  • Previous versions could overwrite notes when switching elements, especially via next/previous navigation.
    This is now fixed by:
    • Always using the latest notes string when saving.
    • Ensuring only one TextWatcher is attached to the notes EditText at a time.
    • Validating tag indices before modifying the stored notes string.

Usage

To use InfoExtension, subclass it and implement/override as needed for specific element info activities.

class ElementInfoActivity : InfoExtension() {
    // ... additional logic ...
}

Recommendations

  • For new features, consider migrating notes to a JSON object in preferences for robustness.
  • Use ViewBinding to reduce boilerplate code.
  • Consider moving long UI update logic into smaller helper methods for maintainability.

Related Files

  • IsotopesActivityExperimental: For isotope details navigation.
  • Preferences classes: For all user-configurable options.
  • AchievementModel and StatisticsModel: For user tracking.

See Also

Shipped utilities


  • Periodic Table (Main Table)
  • Element info pages
  • Favorite bar in elements page
  • Unit settings
  • Isotope Table
  • Dictionary
  • pH-indicators
  • Electrochemical series
  • Formulas
  • Ionization energy table
  • Solubility table
  • Table with Poisson's Numbers (PRO)
  • Table of Nuclide (PRO)
  • Table of Constants (PRO)
  • Dynamic Material You
  • Calculator for molar weight
  • Table of Geological Data
  • Page for sources information
  • Calculator for molar weight
  • Table of Geological Data
  • Page for sources information
  • Emission Spectrum Table
  • CAS Numbers
  • EG Numbers
  • Achievements for using the app
  • Profile Page (EARLY VERSION)
  • Flashcards (4.0.0)
  • Unit Converter (4.0.0)
  • Crystal Structure (4.0.0)

Work in progress


  • PRO Version outside Google Play
  • Predictive back gesture (show previous activity)
  • Sources Page
  • Solid-Water distribution coefficient (Kd)
  • Chemical Reaction Balancing (WORK IN PROGRESS)
  • Neutron cross sections
  • Prevalence of elements
  • Electron affinity
  • Visualization of temperatures
  • Sort Table List
  • Sort Properties in Element Info

Clone this wiki locally