-
Notifications
You must be signed in to change notification settings - Fork 213
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
feat: Added the updated base structure for handling the animations #1012
Conversation
…badge. feat: Added the modes support for left right top down fixed and animation support for flash and marquee. animation right
…badge. feat: Added the modes support for left right top down fixed and animation support for flash and marquee. animation right feat:Added the base structure for the animations with speed controll.
Reviewer's Guide by SourceryThis pull request implements a new base structure for handling animations in the BadgeMagic app. It introduces new utility functions for converting data formats, updates the UI to support animations, and adds new providers and abstract classes for managing badge animations and effects. File-Level Changes
Tips
|
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 @Jhalakupadhyay - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding more inline comments to explain complex logic, particularly in new utility functions like
binaryStringTo2DList
. - Review the debug logging statements (e.g.,
logger.d
) and consider removing them or implementing a way to disable them in production builds.
Here's what I looked at during the review
- 🟡 General issues: 5 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
binaryArray[rowIndex].addAll(binaryRepresentation); | ||
|
||
rowIndex = (rowIndex + 1) % 11; | ||
} |
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.
suggestion: Simplify nested loop structure in binaryStringTo2DList
The current nested loop structure is complex and hard to follow. Consider simplifying it by using integer division and modulo operations to determine the row and column for each bit.
List<List<int>> binary2DList = List.generate(maxHeight, (_) => []);
for (int i = 0; i < binaryString.length; i++) {
int row = i ~/ 8;
int col = i % 8;
if (row < maxHeight) {
binary2DList[row].add(int.parse(binaryString[i]));
}
}
@@ -26,6 +29,7 @@ class HomeScreen extends StatefulWidget { | |||
} | |||
|
|||
class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin { | |||
final ValueNotifier<String> textNotifier = ValueNotifier<String>(''); |
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.
suggestion: Remove unused textNotifier
This ValueNotifier is declared but never used. Consider removing it if it's not needed for future functionality.
final ValueNotifier<String> textNotifier = ValueNotifier<String>(''); | |
// Remove the following line: | |
// final ValueNotifier<String> textNotifier = ValueNotifier<String>(''); |
void _controllerListner() { | ||
logger | ||
.d('Controller Listener : ${inlineImageProvider.getController().text}'); | ||
converters.badgeAnimation(inlineImageProvider.getController().text.isEmpty | ||
? "" | ||
: inlineImageProvider.getController().text); | ||
inlineImageProvider.controllerListener(); | ||
} |
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.
suggestion (performance): Optimize badge animation updates
The badgeAnimation
call on every text change could be inefficient for longer inputs. Consider debouncing this operation or updating only when the text input is complete.
void _controllerListener() {
final text = inlineImageProvider.getController().text;
logger.d('Controller Listener: $text');
if (_debounce?.isActive ?? false) _debounce!.cancel();
_debounce = Timer(const Duration(milliseconds: 300), () {
converters.badgeAnimation(text.isEmpty ? "" : text);
});
inlineImageProvider.controllerListener();
}
int aniSpeedStrategy(int speedLevel) { | ||
int speedInMicroseconds = aniBaseSpeed.inMicroseconds - | ||
(speedLevel * aniBaseSpeed.inMicroseconds ~/ 8); | ||
return speedInMicroseconds; | ||
} |
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.
suggestion: Clarify animation speed calculation
The speed calculation seems arbitrary. Consider adding a comment explaining the logic behind this calculation or explore a more nuanced approach that might provide better control over animation speeds.
int aniSpeedStrategy(int speedLevel) { | |
int speedInMicroseconds = aniBaseSpeed.inMicroseconds - | |
(speedLevel * aniBaseSpeed.inMicroseconds ~/ 8); | |
return speedInMicroseconds; | |
} | |
int aniSpeedStrategy(int speedLevel) { | |
final maxSpeedReduction = aniBaseSpeed.inMicroseconds * 7 ~/ 8; | |
final speedReduction = (speedLevel * maxSpeedReduction) ~/ 8; | |
return aniBaseSpeed.inMicroseconds - speedReduction; | |
} |
Map<int, BadgeAnimation?> animationMap = { | ||
// 0: LeftAnimation(), | ||
// 1: RightAnimation(), | ||
// 2: UpAnimation(), | ||
// 3: DownAnimation(), | ||
// 4: FixedAnimation(), | ||
// 5: SnowFlakeAnimation(), | ||
// 6: PictureAnimation(), | ||
// 7: AniAnimation(), | ||
// 8: LaserAnimation(), |
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.
issue (bug_risk): Implement missing animations
The animation map is currently empty and commented out. This suggests that the animation system is not fully implemented, which could lead to runtime errors or unexpected behavior. Prioritize implementing these animations or provide a default fallback.
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.
Nice comments from sourcery to look at
@@ -28,3 +28,56 @@ List<int> hexStringToByteArray(String hexString) { | |||
logger.d(data.length); | |||
return data; | |||
} | |||
|
|||
List<List<int>> byteArrayToBinaryArray(List<int> byteArray) { | |||
List<List<int>> binaryArray = List.generate(11, (_) => []); |
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.
Use badge height
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.
ok
List.generate(11, (i) => List.generate(44, (j) => 0)); | ||
badgeList.setNewGrid(image); | ||
} else { | ||
List<String> hexStrings = await messageTohex(message); |
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.
We should avoid these 3 operations and decide a scheme to store messages to one format which can be used across the app. List<List> would be a good candidate. It does not make sense to have these translations for every step when we could built our logic just on one kind of data
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.
But in order to get the bitmap (List<List>) we would first need to have the hexstring and then convert it to bitmap.
Can you clarify what you mean by avoiding the operations.
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.
Hex String -> Byte Array, Byte Array -> Binary Array, Binary Array -> Bool Array. Why not Hex String -> Bool Array
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.
I have not seen this conversion so far is it possible?
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.
Give me some time I will look into it and if I can make it then it will be very efficient.
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.
So we're trying to minimize the number of conversions. HexString to something you can work off of everywhere. Maybe 2 conversions is fine but not more
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.
So HexString -> ByteArray is fine. Then maybe ByteArray -> Bool Array when needed.
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.
I don't see a point in holding up 4 bytes of memory whereas you can get away with just a bit
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.
Correction, flutter uses 8 bytes int so more memory usage for no reason
List<List<bool>> homeViewGrid = | ||
List.generate(11, (i) => List.generate(44, (j) => false)); | ||
|
||
//List that contains the state of each cell of the badge for draw view | ||
List<List<bool>> drawViewGrid = | ||
List.generate(11, (i) => List.generate(44, (j) => false)); | ||
|
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.
This needs to be cleaned. 2 seperate widgets for draw and display seperately
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.
this I will clear in seperate PR where I will add separate custom paint class for the drawbadge
…rom the hexString to boolean 2D list.
…ic-android into flutter_app
…ic-android into flutter_app
ae0b572
to
6f16c2a
Compare
6f16c2a
to
7ef4c74
Compare
Summary by Sourcery
Add new utility functions for byte and binary data conversion, introduce a new provider for managing badge animations and drawing, and refactor existing components to integrate with the new provider structure. This update enhances the animation handling capabilities and improves the modularity of the badge rendering system.
New Features:
badgeAnimation
function in theConverters
class to handle badge animations based on message input.DrawBadgeProvider
class to manage badge drawing and animation states, replacing the previousDrawBadgeProvider
implementation.Enhancements:
BadgeWidget
to accept a grid parameter, allowing for more flexible badge rendering.HomeScreen
to initialize and manage animations using the newDrawBadgeProvider
.Chores:
drawbadge_provider.dart
withbadgeview_provider.dart
across multiple files to align with the new provider structure.