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 code for the left scroll animation. #997

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Sep 8, 2024

#995

Summary by Sourcery

Add new badge animation features, including a right scroll animation and a singleton token generator. Refactor the BadgePainter for optimized repainting and replace DrawBadgeProvider with BadgeViewProvider. Introduce constants for animation speed and remove unnecessary debug logging.

New Features:

  • Introduce a singleton TokenGenerator class with a refreshable cancellation token.
  • Add a RightAnimation class implementing a badge animation that scrolls content to the right.
  • Implement a badgeAnimation function in the Converters class to handle badge animations based on message input.

Enhancements:

  • Refactor BadgePainter to optimize repainting by comparing the current grid with the previous grid state.
  • Implement a singleton pattern for the Converters class to ensure a single instance is used throughout the application.
  • Add animation speed constants and a strategy function to calculate animation speed based on a speed level.

Chores:

  • Replace DrawBadgeProvider with BadgeViewProvider across the project to manage badge view state.
  • Remove logger debug statements from various utility functions to clean up the codebase.

Copy link
Contributor

sourcery-ai bot commented Sep 8, 2024

Reviewer's Guide by Sourcery

This pull request implements the left scroll animation for the badge display. It introduces new utility functions for byte array and binary conversions, updates the badge painting logic, and implements an animation system with speed control.

File-Level Changes

Change Details Files
Implemented left scroll animation and related utility functions
  • Added byteArrayToBinaryArray, hexToBin, and binaryStringTo2DList functions
  • Updated Converters class with new methods for badge animation
  • Implemented animation speed control with constants and strategy function
lib/bademagic_module/utils/byte_array_utils.dart
lib/bademagic_module/utils/converters.dart
lib/constants.dart
Updated badge painting and animation logic
  • Refactored BadgePainter class for improved performance
  • Implemented new DrawBadgeProvider with animation controls
  • Updated BadgeWidget to use the new grid system
lib/virtualbadge/view/badge_painter.dart
lib/providers/badgeview_provider.dart
lib/virtualbadge/widgets/badge_widget.dart
Integrated animation system with the main application
  • Updated HomeScreen to use the new animation system
  • Modified InlineImageProvider to work with the new animation
  • Added TokenGenerator for managing cancellation tokens
lib/view/homescreen.dart
lib/providers/imageprovider.dart
lib/bademagic_module/utils/token_generator.dart
Added new animation classes and abstractions
  • Created BadgeAnimation abstract class
  • Implemented RightAnimation class
lib/badge_animation/animation_abstract.dart
lib/badge_animation/ani_right.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:

  • The new animation system in DrawBadgeProvider is a good improvement, but consider breaking it down into smaller, more focused classes to reduce complexity.
  • Ensure that the new timer-based animation system is optimized for performance and battery life, especially on mobile devices.
  • Consider implementing the missing animation types (UpAnimation, DownAnimation, etc.) to fully utilize the new BadgeAnimation abstract class.
Here's what I looked at during the review
  • 🟡 General issues: 3 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.

return binaryString;
}

List<List<int>> binaryStringTo2DList(String binaryString) {
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): Simplify and optimize binaryStringTo2DList function

The current implementation uses complex nested loops. Consider rewriting this function to use a single loop with index manipulation for better efficiency and readability.

List<List<int>> binaryStringTo2DList(String binaryString) {
  final int maxHeight = 11;
  final int width = binaryString.length ~/ maxHeight;
  return List.generate(maxHeight, (i) =>
    binaryString.substring(i * width, (i + 1) * width).split('').map(int.parse).toList()
  );
}

..color = Colors.grey.shade800
..style = PaintingStyle.fill;

double radians = math.pi / 4;
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): Use compile-time constant for rotation

For better precision and potentially faster execution, consider using a compile-time constant for the rotation value instead of calculating it at runtime.

Suggested change
double radians = math.pi / 4;
const double radians = math.pi / 4;

_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): Optimize animation updates in _controllerListner

Consider implementing debouncing for the animation calls to prevent excessive updates during rapid text changes. Also, review the relationship between this method and controllerListener to avoid potential circular dependencies or unnecessary double updates.

  void _controllerListener() {
    final debouncer = Debouncer(milliseconds: 300);
    debouncer.run(() {
      if (mounted) {
        logger.d('Controller Listener: ${inlineImageProvider.getController().text}');
      }
    });
  }

@Jhalakupadhyay Jhalakupadhyay deleted the feature/left_animation branch September 8, 2024 17:04
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