-
Notifications
You must be signed in to change notification settings - Fork 236
feat: Add Support for Renaming (Alias) BLE Devices in App #1362
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
base: development
Are you sure you want to change the base?
feat: Add Support for Renaming (Alias) BLE Devices in App #1362
Conversation
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> feat: add badge scan mode selection and filtering support fix: save and apply scan mode and badge names via provider fix: unused variables and imports fix: added comments fix: resolved conflicts
Reviewer's GuideThis PR adds alias-based support for BLE devices by introducing two new ChangeNotifier providers (BadgeScanProvider and BadgeAliasProvider), extending the SettingsScreen to configure scan modes and custom aliases, and refactoring the BLE scanning and transfer flow to recognize and display aliases. Sequence diagram for BLE scan and connect with alias supportsequenceDiagram
actor User
participant SettingsScreen
participant BadgeScanProvider
participant BadgeAliasProvider
participant BadgeMessageProvider
participant ScanState
participant ConnectState
User->>SettingsScreen: Configure scan mode and aliases
SettingsScreen->>BadgeScanProvider: setMode(), setBadgeNames()
SettingsScreen->>BadgeAliasProvider: setAlias()
User->>BadgeMessageProvider: checkAndTransfer(..., context)
BadgeMessageProvider->>ScanState: new ScanState(..., mode, allowedNames, aliasProvider)
ScanState->>ScanState: Scan for BLE devices
ScanState->>BadgeAliasProvider: getAlias(realName)
ScanState->>ConnectState: On match (by name or alias), pass displayName
ConnectState->>BadgeMessageProvider: Complete connection and transfer
Class diagram for new and updated providers (BadgeScanProvider, BadgeAliasProvider)classDiagram
class BadgeScanProvider {
- BadgeScanMode _mode
- List<String> _badgeNames
+ BadgeScanMode get mode
+ List<String> get badgeNames
+ void setMode(BadgeScanMode mode)
+ void setBadgeNames(List<String> names)
+ void addBadgeName(String name)
+ void removeBadgeNameAt(int index)
+ void updateBadgeName(int index, String newName)
}
class BadgeAliasProvider {
- Map<String, String> _aliases
+ String? getAlias(String deviceName)
+ void setAlias(String deviceName, String alias)
+ void removeAlias(String deviceName)
+ void clearAll()
+ Map<String, String> get allAliases
}
BadgeScanProvider <|-- ChangeNotifier
BadgeAliasProvider <|-- ChangeNotifier
Class diagram for updated ScanState and ConnectState BLE flowclassDiagram
class ScanState {
+ DataTransferManager manager
+ BadgeScanMode mode
+ List<String> allowedNames
+ BadgeAliasProvider aliasProvider
+ Future<BleState?> processState()
}
class ConnectState {
+ ScanResult scanResult
+ DataTransferManager manager
+ String displayName
+ Future<BleState?> processState()
}
ScanState --|> NormalBleState
ConnectState --|> RetryBleState
ScanState --> ConnectState : on device found
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 @samruddhi-Rahegaonkar - I've reviewed your changes - here's some feedback:
- The new ConnectState signature takes a displayName but doesn’t assign it to any field—add a member and initialize it in the constructor so the displayName is actually used.
- You have nearly identical badge/alias form logic in SettingsScreen and BadgeScanSettingsWidget—consider extracting that into a shared widget or consolidating one to reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new ConnectState signature takes a displayName but doesn’t assign it to any field—add a member and initialize it in the constructor so the displayName is actually used.
- You have nearly identical badge/alias form logic in SettingsScreen and BadgeScanSettingsWidget—consider extracting that into a shared widget or consolidating one to reduce duplication.
## Individual Comments
### Comment 1
<location> `lib/view/settings_screen.dart:166` </location>
<code_context>
+ }
+ }
+ }
+ provider.setBadgeNames(badgeNames); // Save aliases
+ final aliasProvider =
+ Provider.of<BadgeAliasProvider>(context, listen: false);
</code_context>
<issue_to_address>
The comment '// Save aliases' is misleading here.
setBadgeNames only updates badge names. Consider removing or clarifying the comment to prevent confusion.
</issue_to_address>
### Comment 2
<location> `lib/bademagic_module/bluetooth/scan_state.dart:63` </location>
<code_context>
+ );
+
+ isCompleted = true;
+ FlutterBluePlus.stopScan();
+ toast.showToast('Device found. Connecting...');
+
</code_context>
<issue_to_address>
Calling stopScan inside the scan result handler may cause race conditions.
If scan results arrive rapidly, stopScan could be called multiple times, disrupting the scan process. Use a flag or similar mechanism to ensure stopScan is only invoked once.
</issue_to_address>
### Comment 3
<location> `lib/bademagic_module/bluetooth/connect_state.dart:10` </location>
<code_context>
final ScanResult scanResult;
final DataTransferManager manager;
- ConnectState({required this.manager, required this.scanResult});
+ ConnectState(
+ {required this.manager,
+ required this.scanResult,
</code_context>
<issue_to_address>
The displayName parameter is added but not stored or used in ConnectState.
Remove displayName from the constructor if it's unnecessary, or add it as a field if it will be used.
</issue_to_address>
### Comment 4
<location> `lib/providers/BadgeAliasProvider.dart:4` </location>
<code_context>
+import 'package:flutter/material.dart';
+
+class BadgeAliasProvider with ChangeNotifier {
+ final Map<String, String> _aliases = {}; // Key: deviceName, Value: alias
+
+ /// Get alias by badge/device name
</code_context>
<issue_to_address>
The alias map uses deviceName as the key, which may cause issues if device names are not unique.
If device names aren't guaranteed unique, use a unique identifier (e.g., MAC address) as the key to avoid collisions.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
7869e69
to
5bc8ff4
Compare
Build StatusBuild successful. APKs to test: https://github.com/fossasia/badgemagic-app/actions/runs/16625217196/artifacts/3649383008. Screenshots (Android)
Screenshots (iPhone)
Screenshots (iPad)
|
@nope3472 please review this |
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.
Add a check in the settings UI to warn/prevent duplicate real badge names or duplicate aliases per user.
-Else Great work.
Good catch! I have added check for duplicate prevention 👍 |
7e35a08
to
dc7f557
Compare
@nope3472 please review this again |
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.
-The implementation of alias support is well integrated (provider, settings, UI).
- Would it be possible to add an option to reset/remove an alias and revert to the default device name?
@nope3472 I think we should add only one alias to badge name so it is okay if we dont have option to add or remove either way its optional. |
fix: fixed the issues according to review fix: format code to match Dart standards fix: added check for duplicate checking fix: show succesfully connected as alias name
544e3b8
to
5dbdbc0
Compare
24c8585
to
00f2e24
Compare
@samruddhi-Rahegaonkar update the branch please |
Fixes #1359
Changes
Screenshots / Recordings
Checklist:
constants.dart
without hard coding any value.Summary by Sourcery
Add support for aliasing BLE devices by introducing new providers for scan configuration and alias storage, update scanning logic to recognize aliases, and enhance settings and UI components to configure and persist these mappings
New Features:
Enhancements:
Chores:
Summary by Sourcery
Add support for aliasing BLE devices by introducing new providers, updating scan and transfer logic to use real names or aliases, and enhancing the settings UI to configure and persist these mappings
New Features:
Bug Fixes:
Enhancements:
Build: