-
Notifications
You must be signed in to change notification settings - Fork 815
feat: implemented the sound meter #2739
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
Conversation
# This is the 1st commit message: Implemented LUX meter # This is the commit message #2: added const # This is the commit message fossasia#3: Improved responsiveness and made reusable widgets # This is the commit message fossasia#4: renamed file # This is the commit message fossasia#5: Updated view as per PSLab # This is the commit message fossasia#6: Implemented sound meter # This is the commit message fossasia#7: feat: implemented LUX meter (fossasia#2733) fix: handled theming for instrument screens (fossasia#2732) chore(deps): bump org.jetbrains.kotlin.android in /android Bumps [org.jetbrains.kotlin.android](https://github.com/JetBrains/kotlin) from 1.8.22 to 2.1.21. - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md) - [Commits](JetBrains/kotlin@v1.8.22...v2.1.21) --- updated-dependencies: - dependency-name: org.jetbrains.kotlin.android dependency-version: 2.1.21 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Adjusted view Changes
Reviewer's GuideThis PR integrates a new Sound Meter feature into the Flutter app by adding a dedicated screen with a live noise data stream, chart, and gauge card, updating navigation, parameterizing existing stats widget, and introducing necessary constants and dependencies. Sequence Diagram for Navigating to Sound Meter ScreensequenceDiagram
actor User
participant InstrumentsScreen
participant Navigator
participant SoundMeterScreen
User->>InstrumentsScreen: Selects Sound Meter (item 15)
InstrumentsScreen->>Navigator: pushNamedAndRemoveUntil("/soundmeter", ...)
Navigator->>SoundMeterScreen: Creates and displays
SoundMeterScreen-->>User: Shows Sound Meter UI
Sequence Diagram for Sound Data FlowsequenceDiagram
participant UI (SoundMeterScreen)
participant SoundMeterStateProvider
participant NoiseMeter
participant Timer
activate SoundMeterStateProvider
SoundMeterStateProvider->>NoiseMeter: Initialize & Listen for noise readings
SoundMeterStateProvider->>Timer: Start periodic timer (e.g., every 1s)
deactivate SoundMeterStateProvider
loop Data Collection
NoiseMeter-->>SoundMeterStateProvider: onData (NoiseReading)
activate SoundMeterStateProvider
SoundMeterStateProvider->>SoundMeterStateProvider: _currentDb = noiseReading.meanDecibel
SoundMeterStateProvider->>SoundMeterStateProvider: notifyListeners()
deactivate SoundMeterStateProvider
SoundMeterStateProvider-->>UI (SoundMeterScreen): Update with new _currentDb
Timer-->>SoundMeterStateProvider: onTick
activate SoundMeterStateProvider
SoundMeterStateProvider->>SoundMeterStateProvider: _currentTime = new time
SoundMeterStateProvider->>SoundMeterStateProvider: _updateData() (updates _dbData, _timeData, dbChartData)
SoundMeterStateProvider->>SoundMeterStateProvider: notifyListeners()
deactivate SoundMeterStateProvider
SoundMeterStateProvider-->>UI (SoundMeterScreen): Update chart with new dbChartData
end
Class Diagram for SoundMeterScreen and its UI ComponentsclassDiagram
class SoundMeterScreen {
+StatefulWidget
+createState() _SoundMeterScreenState
}
class _SoundMeterScreenState {
+State<SoundMeterScreen>
+build(BuildContext context) Widget
-_buildChartSection() Widget
-_sideTitleWidgets(double value, TitleMeta meta) Widget
-_buildChart(...) Widget
}
class SoundMeterCard {
+StatefulWidget
+createState() _SoundMeterCardState
}
class _SoundMeterCardState {
+State<SoundMeterCard>
+build(BuildContext context) Widget
}
class CommonScaffold {
+Widget
+String title
+Widget body
}
class SoundMeterStateProvider {
+ChangeNotifier
}
SoundMeterScreen --|> StatefulWidget
_SoundMeterScreenState --|> State
SoundMeterScreen o-- _SoundMeterScreenState : creates
_SoundMeterScreenState "1" *-- "1" SoundMeterCard : uses
_SoundMeterScreenState "1" *-- "1" CommonScaffold : uses
_SoundMeterScreenState ..> SoundMeterStateProvider : consumes
SoundMeterCard --|> StatefulWidget
_SoundMeterCardState --|> State
SoundMeterCard o-- _SoundMeterCardState : creates
_SoundMeterCardState ..> SoundMeterStateProvider : consumes
Class Diagram for SoundMeterStateProviderclassDiagram
class SoundMeterStateProvider {
+ChangeNotifier
-_currentDb: double
-_noiseSubscription: StreamSubscription<NoiseReading>
-_timeTimer: Timer
-_dbData: List<double>
-_timeData: List<double>
+dbChartData: List<FlSpot>
-_noiseMeter: NoiseMeter
-_startTime: double
-_currentTime: double
-_maxLength: int
-_dbMin: double
-_dbMax: double
-_dbSum: double
-_dataCount: int
+initializeSensors()
+disposeSensors()
+dispose()
-_updateData()
+getCurrentDb() double
+getMinDb() double
+getMaxDb() double
+getAverageDb() double
+getDbChartData() List<FlSpot>
+getTimeInterval() double
}
class NoiseMeter {
+noise: Stream<NoiseReading>
}
SoundMeterStateProvider --|> ChangeNotifier
SoundMeterStateProvider ..> NoiseMeter : uses
Updated Class Diagram for Instrumentstats WidgetclassDiagram
class Instrumentstats {
+StatelessWidget
+String title
+double maxValue
+double minValue
+double avgValue
+String unit ## Added
+double titleFontSize
+double statFontSize
+build(BuildContext context) Widget
}
class StatItem {
+String label
+dynamic value
+double fontSize
}
Instrumentstats --|> StatelessWidget
Instrumentstats "1" *-- "3" StatItem : composes >
Class Diagram for SoundMeterCard and DependenciesclassDiagram
class SoundMeterCard {
+StatefulWidget
}
class _SoundMeterCardState {
+State<SoundMeterCard>
+build(BuildContext context) Widget
}
class Instrumentstats {
+String unit
}
class GaugeWidget {
+double currentValue
+String unit
}
class SoundMeterStateProvider
SoundMeterCard o-- _SoundMeterCardState
_SoundMeterCardState ..> SoundMeterStateProvider : uses
_SoundMeterCardState "1" *-- "1" Instrumentstats : uses
_SoundMeterCardState "1" *-- "1" GaugeWidget : uses
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:
- Remove the embedded quotes in the danger line labelResolver (currently '"Dangerous"') so the chart label renders correctly without extra quotation marks.
- In SoundMeterCard you’re passing the unit as a hardcoded 'dB' string—use the constants.db constant instead for consistency.
- The Instrumentstats class name doesn’t follow Dart’s UpperCamelCase naming convention (should be InstrumentStats) – please rename it for clarity.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Remove the embedded quotes in the danger line labelResolver (currently '"Dangerous"') so the chart label renders correctly without extra quotation marks.
- In SoundMeterCard you’re passing the unit as a hardcoded 'dB' string—use the constants.db constant instead for consistency.
- The Instrumentstats class name doesn’t follow Dart’s UpperCamelCase naming convention (should be InstrumentStats) – please rename it for clarity.
## Individual Comments
### Comment 1
<location> `lib/view/widgets/soundmeter_card.dart:56` </location>
<code_context>
+ maxValue: maxDb,
+ minValue: minDb,
+ avgValue: avgDb,
+ unit: 'dB',
+ ),
+ ),
</code_context>
<issue_to_address>
Use the db constant instead of a string literal
Referencing the constant ensures consistency and simplifies updates if the value changes.
Suggested implementation:
```
unit: db,
```
Make sure that the constant `db` is defined and imported in this file. If it is not already present, you should define it (e.g., `const db = 'dB';`) or import it from the appropriate constants file.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Build successful. APKs to test: https://github.com/fossasia/pslab-android/actions/runs/15711034566/artifacts/3346486489 |
Fixes #2738
Changes
Screenshots / Recordings
screen-20250613-215930.mp4
Checklist:
strings.xml
,dimens.xml
andcolors.xml
without hard coding any value.strings.xml
,dimens.xml
orcolors.xml
.Summary by Sourcery
Port the sound meter instrument to the Flutter app by integrating noise sensor data, creating new UI components for real-time and historical dB measurements, updating navigation routing, and supporting dynamic unit handling.
New Features:
Enhancements:
Build: