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 logic to display the user drawn clipart to the badge. #981

Merged
merged 1 commit into from
Aug 17, 2024

Conversation

Jhalakupadhyay
Copy link
Contributor

@Jhalakupadhyay Jhalakupadhyay commented Aug 4, 2024

#979

Summary by Sourcery

Add logic to display user-drawn clipart on the badge by storing clipart in the image cache with filenames and keys. Enhance image cache handling and update related methods and widgets to support the new functionality. Update tests to reflect changes.

New Features:

  • Added logic to display user-drawn clipart on the badge by storing the clipart in the image cache with a filename and key.

Enhancements:

  • Modified the image cache to use a map with keys that can be either integers or lists containing filenames and keys.
  • Updated the addToCache and _addImageDataToCache methods to handle filenames for user-drawn clipart.
  • Enhanced the Converters class to read image data from files and convert it to LED hex format for user-drawn clipart.
  • Improved the InlineImageProvider to handle insertion of images using keys that can be either integers or lists.
  • Refactored the VectorGridView widget to use the updated image cache keys.

Tests:

  • Updated the Converters test to accommodate the new parameter in the convertBitmapToLEDHex method.

Copy link
Contributor

sourcery-ai bot commented Aug 4, 2024

Reviewer's Guide by Sourcery

This pull request enhances the logic to display user-drawn clipart on the badge. The changes include modifying the image cache to store filenames and keys, adding methods to read image data from files, and updating the conversion logic to handle these new data structures. Additionally, the retry logic in RetryBleState was simplified by removing the delay before retries.

File-Level Changes

Files Changes
lib/bademagic_module/utils/file_helper.dart
lib/bademagic_module/utils/converters.dart
lib/providers/imageprovider.dart
lib/view/widgets/vectorview.dart
lib/view/special_text_field.dart
Enhanced the logic to handle user-drawn clipart by storing filenames and keys in the image cache, reading image data from files, and converting it to LED hex format.

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.

Comment on lines +51 to +55
//storing the user drawn clipart to the badge in the form of a list
//the first element of the list is the filename and the second element is the key
//while parsing the vector we can take the filename and generate the hex for that vector
//therefore transfering the vector to the physiacl badge will be easier.
imageCacheProvider.imageCache[[filename, key]] = imageData;
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 improving the comment explaining the new cache structure

The current comment is a bit unclear. Consider explaining why this structure was chosen and how it benefits the system. For example: 'Store user-drawn clipart with both filename and key for easier vector-to-badge transfer. The filename allows hex generation, while the key maintains ordering.'

Suggested change
//storing the user drawn clipart to the badge in the form of a list
//the first element of the list is the filename and the second element is the key
//while parsing the vector we can take the filename and generate the hex for that vector
//therefore transfering the vector to the physiacl badge will be easier.
imageCacheProvider.imageCache[[filename, key]] = imageData;
/// Cache structure for user-drawn clipart:
/// Key: [filename, key] - Filename for hex generation, key for ordering
/// Value: imageData
/// This structure enables efficient vector-to-badge transfer
/// by providing both hex generation and order preservation.
imageCacheProvider.imageCache[[filename, key]] = imageData;

await _addImageDataToCache(image, filename);
}

Future<List<List<int>>?> readFromFile(String filename) 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: Consider enhancing error handling in readFromFile method

The current error handling returns null for all error cases. Consider differentiating between file not found and other IO errors. You might also want to propagate specific errors to the caller for better error handling upstream.

Future<List<List<int>>> readFromFile(String filename) async {
  try {
    // Existing implementation here
  } on FileSystemException catch (e) {
    if (e.osError?.errorCode == 2) {
      throw FileNotFoundException('File not found: $filename');
    }
    throw FileReadException('Error reading file: $filename', e);
  }
}

class FileNotFoundException implements Exception {
  final String message;
  FileNotFoundException(this.message);
}

class FileReadException implements Exception {
  final String message;
  final Exception originalException;
  FileReadException(this.message, this.originalException);
}

Comment on lines 47 to 48
logger.d("Retrying ($attempt/$_maxRetries)...");
await Future.delayed(
const Duration(seconds: 2)); // Wait before retrying
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (performance): Reconsider removing the delay between Bluetooth retry attempts

Removing the delay between retry attempts could lead to rapid, successive retries. This might overwhelm the Bluetooth stack or the device. Consider reintroducing a delay, possibly with an exponential backoff strategy for more robust error handling.

@@ -45,8 +45,6 @@ abstract class RetryBleState extends BleState {
attempt++;
if (attempt < _maxRetries) {
logger.d("Retrying ($attempt/$_maxRetries)...");
await Future.delayed(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have some delay when retrying. You can reduce the delay but Retrying would not make sense if the failure is transient and you're trying again without waiting

@Jhalakupadhyay Jhalakupadhyay merged commit 3ece383 into fossasia:flutter_app Aug 17, 2024
6 checks passed
Jhalakupadhyay added a commit to Jhalakupadhyay/badgemagic-android that referenced this pull request Sep 7, 2024
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