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 snowflake animation #1008

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Sep 13, 2024

#1007

Summary by Sourcery

Add a snowflake animation feature and refactor badge display logic to use a new provider system, enhancing the flexibility and control over badge animations. Introduce new animation classes for various effects and remove the deprecated provider.

New Features:

  • Introduce a snowflake animation feature for badge displays, allowing for dynamic visual effects.
  • Add new animation classes for various effects including left, right, up, down, and fixed animations.

Enhancements:

  • Refactor the badge drawing logic to use a new provider, badgeview_provider, replacing the previous drawbadge_provider.
  • Implement a new grid system for managing badge display states, improving the flexibility and control over badge animations.

Chores:

  • Remove the drawbadge_provider.dart file as it has been replaced by the new badgeview_provider implementation.

Copy link
Contributor

sourcery-ai bot commented Sep 13, 2024

Reviewer's Guide by Sourcery

This pull request implements a new snowflake animation feature for the badge display, along with several refactoring changes to improve the animation system and badge rendering. The changes include new utility functions for binary conversions, a restructured animation framework, and updates to the badge view and drawing logic.

File-Level Changes

Change Details Files
Implemented snowflake animation and refactored animation system
  • Added new SnowFlakeAnimation class
  • Created an abstract BadgeAnimation class for different animation types
  • Implemented various animation classes (LeftAnimation, RightAnimation, UpAnimation, DownAnimation, FixedAnimation)
  • Updated DrawBadgeProvider to handle new animation system
  • Added animation speed constants and calculation function
lib/badge_animation/ani_snowflake.dart
lib/badge_animation/animation_abstract.dart
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/providers/badgeview_provider.dart
lib/constants.dart
Added new utility functions for binary conversions
  • Implemented byteArrayToBinaryArray function
  • Added hexToBin function
  • Created binaryStringTo2DList function
lib/bademagic_module/utils/byte_array_utils.dart
Updated badge rendering and view logic
  • Modified BadgeWidget to accept grid as a parameter
  • Updated BadgePainter to use new color scheme
  • Changed DrawBadgeProvider to BadgeViewProvider in various files
lib/virtualbadge/widgets/badge_widget.dart
lib/virtualbadge/view/badge_painter.dart
lib/virtualbadge/view/badge_home_view.dart
lib/view/homescreen.dart
Refactored Converters class and added badgeAnimation function
  • Implemented badgeAnimation function in Converters class
  • Updated messageTohex function to use new conversion methods
lib/bademagic_module/utils/converters.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 refactoring the DrawBadgeProvider class to reduce its responsibilities. It's currently handling too many aspects of the application and could benefit from being split into more focused classes or services.
  • Look into abstracting common animation logic to reduce code duplication across different animation classes. This could improve maintainability and make it easier to add new animations in the future.
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.


String hexToBin(String hex) {
// Convert hex to binary string
String binaryString = BigInt.parse(hex, radix: 16).toRadixString(2);
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): Reconsider using BigInt for hex to binary conversion

Using BigInt ensures accuracy for large numbers, but it might be overkill for typical use cases and could impact performance. Consider using standard integer operations if the input size allows it.

Suggested change
String binaryString = BigInt.parse(hex, radix: 16).toRadixString(2);
String binaryString = int.parse(hex, radix: 16).toRadixString(2).padLeft((hex.length * 4), '0');

@@ -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: Split badgeAnimation function for better separation of concerns

This function is doing too much - both preparing the data and triggering the animation. Consider splitting it into separate functions for data preparation and animation triggering. This will improve readability and make the code easier to maintain and test.

Future<void> prepareBadgeData(String message) async {
  // Data preparation logic here
}

Future<void> triggerBadgeAnimation() async {
  // Animation triggering logic here
}

void badgeAnimation(String message) async {
  await prepareBadgeData(message);
  await triggerBadgeAnimation();
}

_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.

suggestion (performance): Implement debouncing for text input handling

Calling badgeAnimation on every text change could lead to performance issues with long text or rapid typing. Consider implementing a debounce mechanism to limit the frequency of these calls.

  Timer? _debounceTimer;
  void _controllerListener() {
    if (_debounceTimer?.isActive ?? false) _debounceTimer!.cancel();
    _debounceTimer = Timer(const Duration(milliseconds: 300), () {
      logger.d('Controller Listener : ${inlineImageProvider.getController().text}');
      // Add your badgeAnimation call here
    });
  }

}
}

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 changeGridValue function for improved readability

This function is quite complex and handles multiple responsibilities. Consider breaking it down into smaller, more focused functions to improve readability and maintainability.

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

  void _validateGridDimensions(List<List<int>> grid) {
    if (grid.length != homeViewGrid.length || grid[0].length != homeViewGrid[0].length) {
      throw ArgumentError('New grid dimensions do not match existing grid');
    }
  }

@@ -0,0 +1,15 @@
abstract class BadgeAnimation {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Simplify animation method signature using a parameter object

The animation method has many parameters, which can make it hard to use and maintain. Consider creating a parameter object to encapsulate these values, which would simplify the method signature and make it easier to add or remove parameters in the future.

abstract class BadgeAnimation {
  void animation(BadgeAnimationParams params);
}

class BadgeAnimationParams {
  final List<List<bool>> grid;
  // Add other parameters here

  BadgeAnimationParams({required this.grid});
}

@Jhalakupadhyay Jhalakupadhyay deleted the feature/ani_snowflake 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