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

Test background fetch #25

Closed
wants to merge 6 commits into from
Closed

Test background fetch #25

wants to merge 6 commits into from

Conversation

cp-pratik-k
Copy link
Collaborator

@cp-pratik-k cp-pratik-k commented Mar 19, 2024

Summary by CodeRabbit

  • New Features

    • Introduced background fetch capabilities for app data.
    • Added new media preview options for images and videos.
    • Implemented automatic backup to Google Drive, including error handling for missing backup folders.
    • Updated the app to support new dependencies and SDK versions for better performance and compatibility.
  • Bug Fixes

    • Added a new error message for scenarios where the backup folder is not found, improving user feedback on backup failures.
  • Refactor

    • Major refactoring in home screen components and media item handling for enhanced upload status tracking.
    • Updated app dependencies and Gradle configurations for streamlined development and builds.
  • Documentation

    • Updated error codes and localized messages for better user communication.

Copy link

coderabbitai bot commented Mar 19, 2024

Walkthrough

This update brings significant enhancements to the app, focusing on integrating new dependencies and updating existing ones, refining the Android build environment, and expanding media handling capabilities. Key additions include the background_fetch package for background tasks, improved error handling with new error messages, and the introduction of image and video preview functionalities. The Android platform configurations have been meticulously updated to leverage the latest SDK versions and Gradle distributions, ensuring a modern and efficient build process. Overall, these changes aim to enhance user experience and app performance.

Changes

Files Change Summary
.idea/libraries/Dart_Packages.xml
.idea/libraries/Flutter_Plugins.xml
Added background_fetch; Updated dependencies and their configurations.
app/android/.../build.gradle
app/android/gradle.properties
app/android/settings.gradle
app/android/gradle/wrapper/gradle-wrapper.properties
Updated Android SDK versions, Gradle versions, and added new build configurations.
app/lib/.../main.dart
app/lib/ui/...
app/lib/domain/extensions/...
data/lib/errors/...
data/lib/models/media/...
Enhanced media handling, added background fetch functionality, and improved error handling.
data/lib/repositories/...
data/lib/services/...
Introduced Google Drive backup functionality and refined service operations.

A rabbit hopped through the code,
With a hefty, feature-laden load.
🌟 Twinkling lines of change it spread,
Across the files, swift it sped.
📱 For an app that gleams anew,
With every hop, improvements grew.
"To the future," it did cheer, 🚀
With every line, it drew near.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 05c379a and f1df5c6.
Files ignored due to path filters (4)
  • app/android/app/src/main/AndroidManifest.xml is excluded by: !**/*.xml
  • app/ios/Podfile.lock is excluded by: !**/*.lock
  • app/pubspec.lock is excluded by: !**/*.lock
  • app/pubspec.yaml is excluded by: !**/*.yaml
Files selected for processing (26)
  • .idea/libraries/Dart_Packages.xml (2 hunks)
  • .idea/libraries/Flutter_Plugins.xml (1 hunks)
  • app/android/app/build.gradle (2 hunks)
  • app/android/build.gradle (1 hunks)
  • app/android/gradle.properties (1 hunks)
  • app/android/gradle/wrapper/gradle-wrapper.properties (1 hunks)
  • app/android/settings.gradle (1 hunks)
  • app/assets/locales/app_en.arb (1 hunks)
  • app/lib/domain/extensions/app_error_extensions.dart (1 hunks)
  • app/lib/main.dart (3 hunks)
  • app/lib/ui/flow/home/components/app_media_item.dart (4 hunks)
  • app/lib/ui/flow/home/home_screen.dart (4 hunks)
  • app/lib/ui/flow/home/home_screen_view_model.dart (9 hunks)
  • app/lib/ui/flow/home/home_screen_view_model.freezed.dart (9 hunks)
  • app/lib/ui/flow/media_preview/image_preview_screen.dart (1 hunks)
  • app/lib/ui/flow/media_preview/media_preview.dart (1 hunks)
  • app/lib/ui/flow/media_preview/video_preview_screen.dart (1 hunks)
  • app/lib/ui/navigation/app_router.dart (2 hunks)
  • data/.flutter-plugins-dependencies (1 hunks)
  • data/lib/errors/app_error.dart (1 hunks)
  • data/lib/errors/l10n_error_codes.dart (1 hunks)
  • data/lib/models/media/media.dart (6 hunks)
  • data/lib/models/media/media.freezed.dart (14 hunks)
  • data/lib/models/media/media.g.dart (2 hunks)
  • data/lib/repositories/google_drive_auto_back_up_repository.dart (1 hunks)
  • data/lib/services/google_drive_service.dart (3 hunks)
Files skipped from review due to trivial changes (2)
  • app/android/gradle/wrapper/gradle-wrapper.properties
  • data/.flutter-plugins-dependencies
Additional comments: 45
app/android/gradle.properties (1)
  • 4-6: The additions to gradle.properties are appropriate for enhancing Android build features and configurations. These settings are commonly used in modern Android projects to improve build performance and compatibility.
data/lib/errors/l10n_error_codes.dart (1)
  • 5-5: Adding the backUpFolderNotFound error code to AppErrorL10nCodes enhances error handling by providing a specific message for a common error scenario. This is a good practice for improving user experience.
app/lib/ui/flow/media_preview/video_preview_screen.dart (1)
  • 4-20: The VideoPreviewScreen widget currently displays a placeholder text. Consider adding a TODO comment to indicate plans for implementing actual video preview functionality, such as integrating a video player package.
app/android/settings.gradle (1)
  • 26-26: Updating the com.android.application plugin to version '8.3.0' aligns with the PR's goal of enhancing the Android build configuration. Ensure that all project modules are compatible with this new plugin version.
app/android/build.gradle (3)
  • 2-6: Updating Kotlin to version '1.9.23' and configuring SDK versions are positive changes that ensure the project's compatibility with the latest Android APIs and Kotlin features.
  • 15-15: Updating the classpath for com.google.gms:google-services to version 4.4.1 ensures compatibility with the latest Google services features.
  • 23-23: Adding a Maven repository for the background_fetch module is necessary for resolving dependencies and aligns with the PR's objective of integrating background fetch functionality.
app/lib/domain/extensions/app_error_extensions.dart (1)
  • 16-17: Adding a case for AppErrorL10nCodes.backUpFolderNotFound in the l10nMessage extension method enhances error handling by providing a localized message for a specific scenario. This is a good practice for improving user experience.
app/lib/ui/flow/media_preview/media_preview.dart (1)
  • 6-29: The showPreview method in the AppMediaView class provides a clean and efficient way to display media previews, with proper error handling for unsupported media types. This enhances the app's media handling capabilities.
data/lib/errors/app_error.dart (1)
  • 44-48: Introducing the BackUpFolderNotFound class as a specific type of AppError is a good practice for handling distinct error scenarios. This enhances error handling by providing a clear message for a specific issue.
app/assets/locales/app_en.arb (1)
  • 17-17: The addition of the "back_up_folder_not_found_error" message is consistent with the existing error messages in terms of naming convention and format. This enhances the application's error handling capabilities by providing a clear message for a specific error scenario.
app/lib/ui/navigation/app_router.dart (4)
  • 2-3: The imports for ImagePreviewScreen and VideoPreviewScreen are correctly added, enabling navigation to these screens.
  • 25-42: The imagePreview method is correctly implemented, taking required parameters and returning an AppRoute object for navigating to the ImagePreviewScreen.
  • 35-41: The videoPreview method currently does not pass any parameters to VideoPreviewScreen. If VideoPreviewScreen requires parameters similar to ImagePreviewScreen for consistency or future use, consider adding them.
  • 48-55: The routes for image and video preview screens are correctly added to the routes list using GoRoute.
app/lib/ui/flow/media_preview/image_preview_screen.dart (3)
  • 1-6: The imports are relevant and necessary for the functionality of the ImagePreviewScreen widget.
  • 8-20: The ImagePreviewScreen class is correctly defined with required parameters and a sensible default for showCloseBtn. Consider adding documentation to this class to explain its purpose and usage, enhancing code maintainability.
  • 26-62: The build method for ImagePreviewScreen is well-implemented, correctly handling both local and network images. The use of Hero widget for animations and InteractiveViewer for pinch-to-zoom functionality are good practices.
app/android/app/build.gradle (3)
  • 28-29: Using rootProject.ext for compileSdkVersion is a best practice for managing SDK versions centrally, ensuring consistency across modules.
  • 29-29: Setting the ndkVersion directly is correct and ensures the use of a specific NDK version for native code compilation.
  • 50-50: Using rootProject.ext for targetSdkVersion aligns with best practices for central management of SDK versions, promoting consistency and ease of updates.
.idea/libraries/Flutter_Plugins.xml (2)
  • 16-20: The addition of new dependencies such as google_sign_in_ios, photo_manager, firebase_core, background_fetch, and flutter_displaymode aligns with the PR objectives to enhance the app's functionality and update dependencies.
  • 25-25: Updating fluttertoast to version 8.2.4 and removing permission_handler_html are consistent with the PR's goals of updating and refining dependencies.
data/lib/models/media/media.g.dart (2)
  • 13-13: The addition of the webContentLink field to the deserialization function enhances the AppMedia model's compatibility with external data sources.
  • 15-15: Renaming thumbnailPath to thumbnailLink in the serialization function improves clarity and aligns with the data model's intended usage.
app/lib/main.dart (2)
  • 3-3: The import of the background_fetch package is correctly added, enabling the application to perform background fetch tasks.
  • 48-79: The configuration and handling of background fetch tasks, including the scheduling of periodic tasks and handling of headless tasks, are correctly implemented. This aligns with best practices for background task handling in Flutter applications.
data/lib/services/google_drive_service.dart (3)
  • 26-28: The initialization of the DriveApi client is correctly handled, ensuring proper use of the Google Drive API.
  • 36-36: Modifying the query in getBackupFolderId() to include trashed=false is a best practice, ensuring that the application only considers active folders.
  • 91-93: The added error handling for a 404 error with the BackUpFolderNotFound exception improves the application's error management by providing a clear and specific error message.
data/lib/repositories/google_drive_auto_back_up_repository.dart (4)
  • 9-27: The provider setup for GoogleDriveAutoBackUpRepo is well-implemented, ensuring that the repository is properly instantiated with all necessary dependencies. The use of ref.listen for listening to changes in auto backup preferences and the clean-up logic in ref.onDispose are correctly handled.
  • 29-47: The constructor of GoogleDriveAutoBackUpRepo correctly initializes the repository with its dependencies and sets up a listener for Google account changes. This setup is crucial for handling auto backup functionality based on the user's account status.
  • 49-51: The method updateGoogleDriveAutoBackUpStatus correctly updates the internal status for auto backup. However, consider adding a comment explaining the purpose of this method, as it directly modifies an internal state which might not be immediately clear to other developers.
  • 82-85: The dispose method correctly cleans up resources, specifically the subscription to Google account changes. This is a good practice for avoiding memory leaks and ensuring that the repository does not continue to receive updates after it has been disposed of.
data/lib/models/media/media.dart (2)
  • 9-16: The introduction of UploadStatus enum and UploadProgress class is a good design choice for tracking the upload status of media items. These models are well-defined and should provide a solid foundation for managing upload processes within the application.
  • 130-140: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [88-202]

The modifications to the AppMedia class, including the addition of webContentLink and thumbnailLink properties, and the update of methods to accommodate these changes, are well-implemented. These changes are essential for integrating Google Drive file handling more effectively. However, ensure that all instances where AppMedia objects are created or updated throughout the application are adjusted to include these new properties.

Verification successful

The modifications to the AppMedia class, including the addition of webContentLink and thumbnailLink properties, and the update of methods to accommodate these changes, appear to be well-implemented across the application. The instances found in media.dart and the string representation in media.freezed.dart confirm that AppMedia objects are created or updated with the new properties as required. This supports the conclusion that the application has been adjusted to include these new properties wherever AppMedia objects are handled.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for instances where AppMedia objects are created or updated without the new properties.
ast-grep --lang dart --pattern $'AppMedia($_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_, $_)'

Length of output: 115



Script:

#!/bin/bash
# Search for instances where AppMedia objects are created or updated, without specifying the exact number of parameters.
rg "AppMedia\(" --type dart

Length of output: 712

app/lib/ui/flow/home/components/app_media_item.dart (2)
  • 16-24: Replacing the isUploading boolean with a status property of type UploadStatus in the AppMediaItem widget is a significant improvement. This change allows for a more nuanced representation of the upload process, enabling the UI to reflect different states such as waiting, uploading, success, or failure.
  • 69-113: The modifications to the widget building logic in _sourceIndicators and the main build method to accommodate different upload statuses are well-implemented. The use of conditional rendering based on the status property to display appropriate indicators (e.g., progress indicator, waiting icon) enhances the user experience by providing visual feedback on the upload process.
app/lib/ui/flow/home/home_screen.dart (1)
  • 163-193: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [129-208]

The changes in the _buildMediaList method to handle UploadProgress objects and the inclusion of Hero widgets for media item previews are well-thought-out enhancements. These modifications improve the app's functionality by allowing for the tracking of upload progress and providing a smoother user experience with media previews. However, ensure that the Hero widget's tag property is unique across the app to avoid any potential conflicts.

app/lib/ui/flow/home/home_screen_view_model.freezed.dart (1)
  • 26-27: The update to the HomeViewState class to use List<UploadProgress> for the uploadingMedias property is a significant and necessary change for accurately tracking the upload status of media items. This change aligns with the overall improvements in handling media uploads within the application. Ensure that all parts of the application that interact with the uploadingMedias property are updated accordingly to handle the List<UploadProgress> type.

Also applies to: 47-47, 96-96, 116-116, 163-163, 178-214, 269-284

data/lib/models/media/media.freezed.dart (3)
  • 25-25: The addition of the webContentLink property to the AppMedia class.

This change aligns with the PR objectives to enhance media handling capabilities. Ensure that all usages of AppMedia throughout the codebase are updated to consider this new property where necessary.

  • 27-27: Renaming thumbnailPath to thumbnailLink in the AppMedia class.

This renaming makes the property's purpose clearer, especially in the context of web content. Verify that all references to the old thumbnailPath property in the codebase have been updated to thumbnailLink.

  • 55-57: Changes related to the addition of webContentLink and the renaming of thumbnailPath to thumbnailLink are consistently applied across the file.

These changes are correctly implemented in various parts of the file, including the mixin, copyWith method, JSON serialization, and toString method. It's crucial to ensure that the serialization and deserialization tests for AppMedia are updated to reflect these changes.

Also applies to: 87-89, 112-122, 187-189, 217-252, 312-314, 337-341, 375-389, 419-421, 453-455, 477-481

.idea/libraries/Dart_Packages.xml (2)
  • 47-53: The addition of the background_fetch package in the packageNameToDirsMap section is correctly formatted and consistent with the structure used for other packages. This ensures that the IDE can properly locate and reference the library.
  • 1128-1128: The addition of the root URL for the background_fetch library in the CLASSES section is correctly implemented, ensuring that the IDE can accurately reference the library's classes.

Comment on lines +55 to +80
Future<void> autoBackUp() async {
if (_googleAccount == null || !_googleDriveAutoBackUpStatus) {
return;
}
final hasAccess = await _localMediaService.requestPermission();
if (!hasAccess) return;
final backUpFolderId = await _googleDriveService.getBackupFolderId();
if (backUpFolderId == null) return;

final mediaCount = await _localMediaService.getMediaCount();
final localMedias =
await _localMediaService.getLocalMedia(start: 0, end: mediaCount);
final googleDriveMedias = await _googleDriveService.getDriveMedias(
backUpFolderId: backUpFolderId);
final Set<String> googleDrivePaths =
googleDriveMedias.map((media) => media.path).toSet();
final uploadingMedias = localMedias
.where((localMedia) => !googleDrivePaths.contains(localMedia.path))
.toList();
for (final media in uploadingMedias) {
await _googleDriveService.uploadInGoogleDrive(
media: media,
folderID: backUpFolderId,
);
}
}
Copy link

Choose a reason for hiding this comment

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

The autoBackUp method encapsulates the logic for performing auto backup to Google Drive. It correctly checks for necessary conditions before proceeding with the backup process. However, there are a few areas for improvement:

  • Error handling: Consider adding try-catch blocks around external service calls (_localMediaService.requestPermission, _googleDriveService.getBackupFolderId, etc.) to handle potential failures gracefully.
  • Performance: The method retrieves all local media and then filters out those already backed up. For large media collections, this could be inefficient. Consider optimizing this process, possibly by maintaining a local cache of backed-up media or by fetching only new/modified media since the last backup.

@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:cloud_gallery/domain/extensions/date_extensions.dart';
import 'package:collection/collection.dart';
import 'package:data/errors/app_error.dart';
Copy link

Choose a reason for hiding this comment

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

The refactoring of auto backup logic and error handling in HomeViewStateNotifier is well-executed, providing a more robust and error-resilient approach to handling media backups and uploads. The introduction of app_error.dart for better error management is a good practice. However, consider the following improvements:

  • In the _autoBackUpMedias method, ensure that the backup process is efficiently handling large sets of media items, possibly by batching uploads or prioritizing newer items.
  • In the uploadMediaOnGoogleDrive method, add more detailed error handling to provide specific feedback to the user in case of failures.

Also applies to: 43-62, 76-137, 178-202, 262-304

@cp-pratik-k cp-pratik-k deleted the test_background_fetch branch April 11, 2024 14:09
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