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 Aspect ratio in the badge UI and updated the custom painter for the badge UI. #1147

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Jan 6, 2025

#1095
#1108

Summary by Sourcery

Update the badge UI to include aspect ratio and update the custom painter.

New Features:

  • Display the virtual badge with a fixed aspect ratio of 3.2.

Tests:

  • Update existing tests to accommodate for the aspect ratio change.

Copy link
Contributor

sourcery-ai bot commented Jan 6, 2025

Reviewer's Guide by Sourcery

This pull request introduces two main changes: the addition of aspect ratio to the badge UI and an update to the custom painter for the badge UI. The aspect ratio ensures the badge maintains its proportions across different screen sizes. The custom painter update improves the drawing logic for the badge, enhancing its visual representation by drawing a rectangular border around the badge and correctly positioning and sizing the cells within the badge.

Sequence diagram for badge painting process

sequenceDiagram
    participant BP as BadgePaint
    participant BU as BadgeUtils
    participant C as Canvas

    BP->>BU: getBadgeOffsetBackground(size)
    BU-->>BP: offsetBackground

    BP->>BU: getBadgeSize(offsetHeight, offsetWidth, size)
    BU-->>BP: badgeSize

    BP->>C: drawRRect(gridRect, rectPaint)

    BP->>BU: getCellStartCoordinate(offsetWidth, offsetHeight, badgeWidth, badgeHeight)
    BU-->>BP: cellStartCoordinate

    loop For each cell in grid
        BP->>C: save()
        BP->>C: translate()
        BP->>C: rotate()
        BP->>C: drawRect()
        BP->>C: restore()
    end
Loading

Class diagram showing the updated badge UI components

classDiagram
    class BadgeUtils {
        +getBadgeOffsetBackground(Size size) MapEntry~double, double~
        +getBadgeSize(double offsetHeight, double offsetWidth, Size size) MapEntry~double, double~
        +getCellStartCoordinate(double offsetWidth, double offsetHeight, double badgeWidth, double badgeHeight) MapEntry~double, double~
    }

    class BadgePaint {
        -BadgeUtils badgeUtils
        -List~List~bool~~ grid
        +paint(Canvas canvas, Size size) void
        +shouldRepaint(CustomPainter oldDelegate) bool
    }

    class BMBadge {
        +Widget build(BuildContext context)
    }

    BadgePaint --> BadgeUtils : uses
    BMBadge --> BadgePaint : uses
Loading

File-Level Changes

Change Details Files
Added aspect ratio support for the badge UI.
  • Wrapped the CustomPaint widget with an AspectRatio widget to maintain a 3.2 aspect ratio.
  • Used MediaQuery to get the screen width and calculate the size of the badge based on the aspect ratio.
  • Removed fixed height and width from the Container widget.
  • Added aspect ratio support for the DrawBadgeScreen to maintain consistent badge dimensions across different screens and devices.
  • Added aspect ratio support for the HomeScreen to maintain consistent badge dimensions across different screens and devices.
lib/virtualbadge/view/animated_badge.dart
lib/view/draw_badge_screen.dart
lib/view/homescreen.dart
Updated the custom painter for the badge UI.
  • Added a black rectangular border around the badge.
  • Introduced a new BadgeUtils class to calculate the size and position of the badge elements.
  • Modified the cell drawing logic to correctly position and size the cells within the badge based on the aspect ratio.
  • Refactored the code to use BadgeUtils for calculating badge offsets and sizes.
  • Updated the pan update handler to use the new cell positioning logic.
  • Removed the DrawBadgePaint class and replaced it with BadgePaint.
  • Added a BadgeUtils class to handle badge-related calculations, such as offset, size, and cell coordinates.
  • Updated the paint method to draw a rectangular border around the badge and position the cells correctly within the border.
lib/virtualbadge/view/badge_paint.dart
lib/virtualbadge/view/draw_badge.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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: all looks good
  • 🟢 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 and I'll use the feedback to improve your reviews.

@adityastic adityastic enabled auto-merge (squash) January 6, 2025 09:31
@adityastic adityastic merged commit 777ef9f into fossasia:flutter_app Jan 6, 2025
6 checks passed
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.

2 participants