Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix: state lost on orientation change in sensor activities #2576

Draft
wants to merge 15 commits into
base: development
Choose a base branch
from

Conversation

marcnause
Copy link
Contributor

@marcnause marcnause commented Nov 11, 2024

Fixes #2528

Changes

  • refactor: move duplicate code to base class
  • refactor: move duplicates layout components (sensor control dock) to new layout file and replace it with in existing layout files
  • feat: save and restore state of sensor dock and data arrays on orientation change
  • refactor: improve thread handling

Screenshots / Recordings

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Refactor sensor activity classes to extend a new AbstractSensorActivity base class, addressing state loss on orientation change and reducing code duplication.

Bug Fixes:

  • Fix state loss on orientation change in sensor activities by refactoring sensor activity classes.

Enhancements:

  • Refactor sensor activity classes to extend a new AbstractSensorActivity base class, reducing code duplication and improving maintainability.

Summary by Sourcery

Refactor sensor activities to extend a new AbstractSensorActivity base class, addressing state loss on orientation change and reducing code duplication. Move duplicate layout components to a new layout file and replace them with in existing layout files.

Bug Fixes:

  • Fix state loss on orientation change in sensor activities by refactoring sensor activity classes.

Enhancements:

  • Refactor sensor activity classes to extend a new AbstractSensorActivity base class, reducing code duplication and improving maintainability.
  • Move duplicate layout components to a new layout file and replace them with in existing layout files.

Summary by Sourcery

Refactor sensor activities to extend a new AbstractSensorActivity base class, addressing state loss on orientation change and reducing code duplication. Introduce a new feature to save and restore the state of the sensor dock on orientation change. Enhance layout management by moving duplicate components to a new layout file and using tags.

New Features:

  • Save and restore the state of the sensor dock on orientation change.

Bug Fixes:

  • Fix state loss on orientation change in sensor activities.

Enhancements:

  • Refactor sensor activity classes to extend a new AbstractSensorActivity base class, reducing code duplication and improving maintainability.
  • Move duplicate layout components to a new layout file and replace them with in existing layout files.
  • Improve thread handling in sensor activities.

Copy link

sourcery-ai bot commented Nov 11, 2024

Reviewer's Guide by Sourcery

The changes refactor sensor activity classes by introducing an abstract base class and shared layout to handle common functionality, improving code reuse and fixing state loss on orientation changes. The implementation uses inheritance and layout includes to centralize common sensor control dock UI and behavior.

Class diagram for refactored sensor activities

classDiagram
    class AbstractSensorActivity {
        <<abstract>>
        +I2C getScienceLab()
        +AsyncTask<Void, Void, Void> getSensorDataFetch()
        +int getLayoutResId()
        +int getTitleResId()
    }
    class SensorMPU6050 {
        +SensorDataFetch sensorDataFetch
        +MPU6050 sensorMPU6050
        +LineChart mChartAcceleration
        +LineChart mChartGyroscope
        +List<Entry> entriesAx
        +List<Entry> entriesAy
        +List<Entry> entriesAz
        +List<Entry> entriesGx
        +List<Entry> entriesGy
        +List<Entry> entriesGz
    }
    class SensorMLX90614 {
        +SensorDataFetch sensorDataFetch
        +MLX90614 sensorMLX90614
        +LineChart mChartObjectTemperature
        +LineChart mChartAmbientTemperature
        +List<Entry> entriesObjectTemperature
        +List<Entry> entriesAmbientTemperature
    }
    class SensorMPU925X {
        +SensorDataFetch sensorDataFetch
        +MPU925x sensorMPU925X
        +LineChart mChartAcceleration
        +LineChart mChartGyroscope
        +List<Entry> entriesax
        +List<Entry> entriesay
        +List<Entry> entriesaz
        +List<Entry> entriesgx
        +List<Entry> entriesgy
        +List<Entry> entriesgz
    }
    AbstractSensorActivity <|-- SensorMPU6050
    AbstractSensorActivity <|-- SensorMLX90614
    AbstractSensorActivity <|-- SensorMPU925X
    note for AbstractSensorActivity "Base class for sensor activities"
    note for SensorMPU6050 "Refactored to extend AbstractSensorActivity"
    note for SensorMLX90614 "Refactored to extend AbstractSensorActivity"
    note for SensorMPU925X "Refactored to extend AbstractSensorActivity"
Loading

File-Level Changes

Change Details Files
Created an abstract base class to handle common sensor activity functionality
  • Added AbstractSensorActivity class with shared sensor control dock logic
  • Implemented state saving/restoration for orientation changes
  • Centralized thread handling and sensor data fetching
  • Added abstract methods for layout ID, title ID and sensor data fetch implementation
app/src/main/java/io/pslab/sensors/AbstractSensorActivity.java
Refactored sensor activity classes to extend the new base class
  • Removed duplicate code by inheriting from AbstractSensorActivity
  • Simplified sensor activity implementations to focus on sensor-specific logic
  • Improved error handling with consistent logging
  • Converted ArrayList to List interface usage
app/src/main/java/io/pslab/sensors/SensorMPU6050.java
app/src/main/java/io/pslab/sensors/SensorMLX90614.java
app/src/main/java/io/pslab/sensors/SensorMPU925X.java
app/src/main/java/io/pslab/sensors/SensorCCS811.java
app/src/main/java/io/pslab/sensors/SensorTSL2561.java
app/src/main/java/io/pslab/sensors/SensorBMP180.java
app/src/main/java/io/pslab/sensors/SensorSHT21.java
app/src/main/java/io/pslab/sensors/SensorAPDS9960.java
app/src/main/java/io/pslab/sensors/SensorHMC5883L.java
app/src/main/java/io/pslab/sensors/SensorVL53L0X.java
app/src/main/java/io/pslab/sensors/SensorADS1115.java
Extracted common sensor control dock layout into a separate file
  • Created reusable sensor_control_dock.xml layout
  • Replaced duplicate layout code with tags
  • Updated string resources for consistent millisecond display
app/src/main/res/layout/sensor_control_dock.xml
app/src/main/res/layout/sensor_tsl2561.xml
app/src/main/res/layout/sensor_ads1115.xml
app/src/main/res/layout/sensor_apds9960.xml
app/src/main/res/layout/sensor_bmp180.xml
app/src/main/res/layout/sensor_ccs811.xml
app/src/main/res/layout/sensor_hmc5883l.xml
app/src/main/res/layout/sensor_mlx90614.xml
app/src/main/res/layout/sensor_mpu6050.xml
app/src/main/res/layout/sensor_mpu925x.xml
app/src/main/res/layout/sensor_sht21.xml
app/src/main/res/layout/sensor_vl53l0x.xml
app/src/main/res/values/strings.xml
app/src/main/res/values-ar/strings.xml
app/src/main/res/values-pl/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values-si/string.xml

Assessment against linked issues

Issue Objective Addressed Explanation
#2528 Maintain screen state when device orientation changes in sensor activities

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@marcnause marcnause added Enhancement Improvement to an existing feature Instrument: Sensors java Pull requests that update Java code labels Nov 11, 2024
Copy link

github-actions bot commented Nov 11, 2024

@marcnause marcnause added the In Progress Developer is working on the problem label Nov 11, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @marcnause - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please remove the WIP tag from the title if these changes are ready for review and merge.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@marcnause
Copy link
Contributor Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @marcnause - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@marcnause marcnause force-pushed the 2528-sensor-activities-are-not-designed-for-orientation-change branch from c8639ec to 89f41f3 Compare November 19, 2024 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement to an existing feature In Progress Developer is working on the problem Instrument: Sensors java Pull requests that update Java code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sensor Activities are not designed for orientation change
1 participant