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 Fixed animation code #1002

Closed

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Sep 12, 2024

Summary by Sourcery

Add new animation capabilities for badge displays, including left, right, and fixed animations. Refactor the badge drawing logic to use a new provider for better state management and introduce utility functions for data conversion. Clean up the code by removing unused logging statements.

New Features:

  • Introduce new animation classes for badge display, including LeftAnimation, RightAnimation, and FixedAnimation, to enhance visual effects.
  • Add utility functions for converting byte arrays to binary arrays and hex strings to binary strings, facilitating data manipulation for animations.

Enhancements:

  • Refactor the badge drawing logic to use a new provider, BadgeViewProvider, replacing the previous DrawBadgeProvider for improved state management.
  • Implement a new grid system for badge animations, allowing dynamic updates and better control over animation effects.

Chores:

  • Remove unused logging statements to clean up the codebase and improve performance.

Copy link
Contributor

sourcery-ai bot commented Sep 12, 2024

Reviewer's Guide by Sourcery

This pull request implements a fixed animation feature for the badge display. It includes new utility functions for converting data formats, animation logic, and updates to the UI to support the new animation functionality.

File-Level Changes

Change Details Files
Implemented fixed animation functionality
  • Added new utility functions for data conversion (byteArrayToBinaryArray, hexToBin, binaryStringTo2DList)
  • Created new animation classes (LeftAnimation, RightAnimation, FixedAnimation)
  • Implemented animation speed control and timing logic
  • Updated DrawBadgeProvider to handle animation states and grid updates
lib/bademagic_module/utils/byte_array_utils.dart
lib/providers/badgeview_provider.dart
lib/badge_animation/anim_left.dart
lib/badge_animation/ani_right.dart
lib/badge_animation/ani_fixed.dart
lib/badge_animation/animation_abstract.dart
Updated UI components to support animation
  • Modified BadgeWidget to accept grid data as a parameter
  • Updated BMBadgeHome to use the new animation-aware grid
  • Added animation controls to the HomeScreen
lib/virtualbadge/widgets/badge_widget.dart
lib/virtualbadge/view/badge_home_view.dart
lib/view/homescreen.dart
Refactored existing code for better integration with new animation feature
  • Renamed DrawBadgeProvider to BadgeViewProvider
  • Updated import statements across multiple files
  • Removed redundant logging statements
lib/main.dart
lib/providers/getitlocator.dart
lib/view/draw_badge_screen.dart
lib/bademagic_module/utils/image_utils.dart
Added constants for animation speeds
  • Defined base speeds for different animation types
  • Implemented a function to calculate animation speed based on speed level
lib/constants.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 and they look great!

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.

@@ -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 output array size dynamic

The function uses a fixed size of 11 for the outer list. This might cause issues if the input doesn't align with this expectation. Consider making the size dynamic based on the input or adding input validation.

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

_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): Consider debouncing the text input listener

To improve performance, consider debouncing the input listener. This will reduce the frequency of updates, especially when the user is typing quickly, and can help prevent unnecessary processing.

  Timer? _debounce;
  void _controllerListener() {
    if (_debounce?.isActive ?? false) _debounce!.cancel();
    _debounce = Timer(const Duration(milliseconds: 300), () {
      logger.d('Controller Listener : ${inlineImageProvider.getController().text}');
    });
  }

const Duration aniFlashSpeed = Duration(microseconds: 500000); // in uS

// Function to calculate animation speed based on speed level
int aniSpeedStrategy(int speedLevel) {
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 using an enum for speed levels

Using an enum for speed levels instead of raw integers would make the code more type-safe and self-documenting. This can help prevent errors and improve code readability.

enum SpeedLevel { slow, medium, fast, veryFast }

int aniSpeedStrategy(SpeedLevel level) {
  final int speedFactor = SpeedLevel.values.indexOf(level);
  return aniBaseSpeed.inMicroseconds - 
      (speedFactor * aniBaseSpeed.inMicroseconds ~/ 8);
}

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