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

feat: Added the scroll down animation #1005

Closed

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Sep 12, 2024

Summary by Sourcery

Add a new badge animation feature with various animation types and refactor the badge drawing logic by introducing a new BadgeViewProvider. Enhance data processing with new utility functions for byte and binary conversions, and clean up the code by removing unused logger statements.

New Features:

  • Introduce a new badge animation feature with multiple animation types including left, right, up, down, and fixed animations.
  • Add functionality to convert byte arrays to binary arrays and hex strings to binary strings, enhancing data processing capabilities.

Enhancements:

  • Refactor the badge drawing and animation logic by replacing the DrawBadgeProvider with a new BadgeViewProvider, improving the structure and maintainability of the code.
  • Implement a new grid system for managing badge display states, allowing for more flexible and dynamic badge rendering.

Chores:

  • Remove unused logger statements to clean up the codebase and improve readability.

Copy link
Contributor

sourcery-ai bot commented Sep 12, 2024

Reviewer's Guide by Sourcery

This pull request implements a scroll down animation feature for a badge display system. The changes include new utility functions for byte array and binary conversions, modifications to the badge view and animation logic, and the addition of new animation classes.

File-Level Changes

Change Details Files
Added utility functions for byte array and binary conversions
  • Implemented byteArrayToBinaryArray function
  • Added hexToBin function for hex to binary conversion
  • Created binaryStringTo2DList function
lib/bademagic_module/utils/byte_array_utils.dart
Implemented badge animation functionality
  • Added badgeAnimation function to handle animation logic
  • Implemented animation speed calculation
  • Created new DrawBadgeProvider class with animation control methods
lib/bademagic_module/utils/converters.dart
lib/providers/badgeview_provider.dart
Updated badge view components
  • Modified BadgeWidget to use grid prop
  • Updated BMBadgeHome to use Provider for grid state
  • Changed BadgePainter to use new color scheme
lib/virtualbadge/widgets/badge_widget.dart
lib/virtualbadge/view/badge_home_view.dart
lib/virtualbadge/view/badge_painter.dart
Added new animation classes
  • Created LeftAnimation, RightAnimation, UpAnimation, DownAnimation, and FixedAnimation classes
  • Implemented abstract BadgeAnimation class
lib/badge_animation/anim_left.dart
lib/badge_animation/ani_right.dart
lib/badge_animation/ani_up.dart
lib/badge_animation/ani_dpwn.dart
lib/badge_animation/ani_fixed.dart
lib/badge_animation/animation_abstract.dart
Updated constants and providers
  • Added animation speed constants
  • Implemented aniSpeedStrategy function
  • Updated import statements to use new badgeview_provider
lib/constants.dart
lib/main.dart
lib/providers/getitlocator.dart
lib/view/draw_badge_screen.dart

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@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 @Jhalakupadhyay - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding more explanatory comments for complex animation calculations, especially in the DrawBadgeProvider class.
  • Ensure all references to drawbadge_provider.dart have been updated to badgeview_provider.dart throughout the project.
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

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 to tell me if it was helpful.

@@ -28,3 +28,56 @@ List<int> hexStringToByteArray(String hexString) {
logger.d(data.length);
return data;
}

List<List<int>> byteArrayToBinaryArray(List<int> byteArray) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider making the byteArrayToBinaryArray function more flexible

The function assumes a fixed size of 11 rows, which might not be suitable for different badge sizes. Consider parameterizing the number of rows or deriving it from the input array size.

List<List<int>> byteArrayToBinaryArray(List<int> byteArray, {int? rows}) {
  int numRows = rows ?? (byteArray.length * 8 + 7) ~/ 8;
  List<List<int>> binaryArray = List.generate(numRows, (_) => []);

@@ -43,6 +43,22 @@ class Converters {
return hexStrings;
}

void badgeAnimation(String message) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Refactor badgeAnimation function to improve separation of concerns

This function is doing too much - converting messages, manipulating data, and updating UI state. Consider splitting it into smaller, more focused functions and moving UI updates to a more appropriate place in the widget tree.

Future<void> processBadgeMessage(String message) async {
  final convertedMessage = await convertMessage(message);
  final badgeData = generateBadgeData(convertedMessage);
  updateBadgeState(badgeData);
}

void updateBadgeState(List<List<int>> badgeData) {
  // Update UI state here
}

_startImageCaching();
super.initState();

_tabController = TabController(length: 3, vsync: this);
}

void _controllerListner() {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Fix typo in function name and reconsider its responsibilities

The function name has a typo ('Listner' should be 'Listener'). Also, this function is directly manipulating UI state through converters.badgeAnimation, which could make the code harder to test and maintain. Consider refactoring to improve separation of concerns.

}
}

void changeGridValue(List<List<int>> newGrid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Refactor complex animation logic in changeGridValue

This function is quite complex and handles multiple responsibilities. Consider breaking it down into smaller, more focused functions. Also, replace magic numbers (like 11 and 44) with named constants or configurable parameters.

  void changeGridValue(List<List<int>> newGrid) {
    _updateGrid(newGrid);
    _animateGridChanges();
  }

  void _updateGrid(List<List<int>> newGrid) {
    // Implementation details...
  }

  void _animateGridChanges() {
    // Implementation details...
  }

AnimationController? _controller;
int animationSpeed = aniBaseSpeed.inMilliseconds;
int counter = 0;
Timer? timer;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider using Flutter's animation framework instead of Timer

Using a Timer for animations might not provide the smoothest experience. Consider using Flutter's AnimationController for more efficient and smoother animations.

AnimationController? _animationController;

@Jhalakupadhyay Jhalakupadhyay deleted the feature/ani_down branch September 22, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant