generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
831 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,7 @@ app.*.symbols | |
app.*.map.json | ||
|
||
# Test related | ||
coverage | ||
coverage | ||
|
||
# Mockito generated files. | ||
*.mocks.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
format-version: | ||
- 1 | ||
- 0 | ||
- 0 | ||
native-assets: {} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:review_service/src/review_service/review_condition_interface.dart'; | ||
import 'package:review_service/src/review_service/review_settings.dart'; | ||
|
||
/// Asynchronous implementation of [ReviewCondition]. | ||
class AsynchronousReviewCondition<TReviewSettings extends ReviewSettings> | ||
implements ReviewCondition<TReviewSettings> { | ||
final Future<bool> Function(TReviewSettings, DateTime) _condition; | ||
|
||
AsynchronousReviewCondition(this._condition); | ||
|
||
@override | ||
Future<bool> validate(TReviewSettings currentSettings, DateTime currentDateTime) { | ||
return _condition(currentSettings, currentDateTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:logger/logger.dart'; | ||
import 'package:review_service/src/review_service/review_prompter.dart'; | ||
|
||
/// Implementation of [ReviewPrompter] that logs information. | ||
final class LoggingReviewPrompter implements ReviewPrompter { | ||
final Logger logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LoggingReviewPrompter"/> class. | ||
/// </summary> | ||
LoggingReviewPrompter({Logger? logger}) : logger = logger ?? Logger(); | ||
|
||
@override | ||
Future<void> tryPrompt() async { | ||
logger.i('TryPrompt was invoked.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:review_service/src/review_service/review_settings.dart'; | ||
import 'package:review_service/src/review_service/review_settings_source.dart'; | ||
|
||
/// In-memory implementation of [ReviewSettingsSource]. | ||
final class MemoryReviewSettingsSource<TReviewSettings extends ReviewSettings> implements ReviewSettingsSource<TReviewSettings> { | ||
TReviewSettings _reviewSettings = const ReviewSettings() as TReviewSettings; | ||
|
||
@override | ||
Future<TReviewSettings> read() { | ||
return Future.value(_reviewSettings); | ||
} | ||
|
||
@override | ||
Future<void> write(TReviewSettings reviewSettings) { | ||
_reviewSettings = reviewSettings; | ||
|
||
return Future.value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:review_service/src/review_service/review_condition_interface.dart'; | ||
import 'package:review_service/src/review_service/review_conditions_builder.extensions.dart'; | ||
import 'package:review_service/src/review_service/review_settings.dart'; | ||
|
||
/// Provide a way to gather the review conditions. | ||
abstract interface class ReviewConditionsBuilder<TReviewSettings extends ReviewSettings> { | ||
/// Gets the review conditions. | ||
List<ReviewCondition<TReviewSettings>> get conditions; | ||
} | ||
|
||
/// Implementation of [ReviewConditionsBuilder]. | ||
/// Provides methods to get an empty or default [ReviewConditionsBuilder]. | ||
final class ReviewConditionsBuilderImplementation<TReviewSettings extends ReviewSettings> | ||
implements ReviewConditionsBuilder<TReviewSettings> { | ||
|
||
ReviewConditionsBuilderImplementation(); | ||
|
||
@override | ||
List<ReviewCondition<TReviewSettings>> conditions = []; | ||
|
||
static ReviewConditionsBuilder<TReviewSettings> | ||
empty<TReviewSettings extends ReviewSettings>() { | ||
return ReviewConditionsBuilderImplementation<TReviewSettings>(); | ||
} | ||
|
||
static ReviewConditionsBuilder<TReviewSettings> | ||
defaultBuilder<TReviewSettings extends ReviewSettings>() { | ||
return ReviewConditionsBuilderImplementation<TReviewSettings>() | ||
..minimumApplicationLaunchCount(3) | ||
..minimumElapsedTimeSinceApplicationFirstLaunch(const Duration(days: 5)) | ||
..minimumPrimaryActionsCompleted(2) | ||
..minimumElapsedTimeSinceLastReviewRequest(const Duration(days: 15)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:review_service/src/review_service/review_settings.dart'; | ||
|
||
/// A condition used to determine if a review should be requested based on [ReviewSettings]. | ||
abstract interface class ReviewCondition<TReviewSettings extends ReviewSettings> { | ||
/// Validates that the condition is satisfied. | ||
Future<bool> validate( | ||
TReviewSettings currentSettings, | ||
DateTime currentDateTime, | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
lib/src/review_service/review_conditions_builder.extensions.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:review_service/src/review_service/asynchronous_review_condition.dart'; | ||
import 'package:review_service/src/review_service/review_condition_builder.dart'; | ||
import 'package:review_service/src/review_service/review_settings.dart'; | ||
import 'package:review_service/src/review_service/synchronous_review_condition.dart'; | ||
|
||
/// Extensions for [ReviewConditionsBuilder]. | ||
extension ReviewConditionBuilderExtensions<TReviewSettings extends ReviewSettings> | ||
on ReviewConditionsBuilder<TReviewSettings> { | ||
|
||
/// The number of completed primary actions must be greater than the review settings. | ||
ReviewConditionsBuilder<TReviewSettings> minimumPrimaryActionsCompleted(int minimumActionCompleted) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>( | ||
(reviewSettings, currentDateTime) => reviewSettings.primaryActionCompletedCount >= minimumActionCompleted, | ||
)); | ||
return this; | ||
} | ||
|
||
/// The number of completed secondary actions must be greater than the review settings. | ||
ReviewConditionsBuilder<TReviewSettings> minimumSecondaryActionsCompleted(int minimumActionCompleted) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>( | ||
(reviewSettings, currentDateTime) => reviewSettings.secondaryActionCompletedCount >= minimumActionCompleted, | ||
)); | ||
return this; | ||
} | ||
|
||
/// The number of times the application has been launched must be greater than the review settings. | ||
ReviewConditionsBuilder<TReviewSettings> minimumApplicationLaunchCount(int minimumCount) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>( | ||
(reviewSettings, currentDateTime) => reviewSettings.applicationLaunchCount >= minimumCount, | ||
)); | ||
return this; | ||
} | ||
|
||
/// The elapsed time since the first application launch must be greater than the review settings. | ||
ReviewConditionsBuilder<TReviewSettings> minimumElapsedTimeSinceApplicationFirstLaunch(Duration minimumTimeElapsed) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>( | ||
(reviewSettings, currentDateTime) => reviewSettings.firstApplicationLaunch != null && | ||
reviewSettings.firstApplicationLaunch!.add(minimumTimeElapsed).isBefore(currentDateTime), | ||
)); | ||
return this; | ||
} | ||
|
||
/// The time elapsed since the last review requested must be greater than the review settings. | ||
ReviewConditionsBuilder<TReviewSettings> minimumElapsedTimeSinceLastReviewRequest(Duration minimumTimeElapsed) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>( | ||
(reviewSettings, currentDateTime) => reviewSettings.lastRequest == null || | ||
reviewSettings.lastRequest!.add(minimumTimeElapsed).isBefore(currentDateTime), | ||
)); | ||
return this; | ||
} | ||
|
||
/// Adds a custom synchronous condition. | ||
ReviewConditionsBuilder<TReviewSettings> custom(bool Function(TReviewSettings, DateTime) condition) { | ||
conditions.add(SynchronousReviewCondition<TReviewSettings>(condition)); | ||
return this; | ||
} | ||
|
||
/// Adds a custom asynchronous condition. | ||
ReviewConditionsBuilder<TReviewSettings> customAsync( | ||
Future<bool> Function(TReviewSettings, DateTime) condition) { | ||
conditions.add(AsynchronousReviewCondition<TReviewSettings>(condition)); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:in_app_review/in_app_review.dart'; | ||
import 'package:logger/logger.dart'; | ||
|
||
/// Provides ways to prompt user to review the current application. | ||
abstract interface class ReviewPrompter { | ||
factory ReviewPrompter({ | ||
required Logger logger, | ||
}) = _ReviewPrompter; | ||
|
||
/// Prompts the user to rate the current application using the platform's default application store. | ||
Future<void> tryPrompt(); | ||
} | ||
|
||
/// Implementation of [ReviewPrompter]. | ||
final class _ReviewPrompter implements ReviewPrompter { | ||
final Logger _logger; | ||
|
||
_ReviewPrompter({ | ||
required Logger logger, | ||
}) : _logger = logger; | ||
|
||
@override | ||
Future<void> tryPrompt() async { | ||
_logger.d('Trying to prompt user to review the current application.'); | ||
|
||
if (await InAppReview.instance.isAvailable()) { | ||
InAppReview.instance.requestReview(); | ||
|
||
_logger.i('Prompted user to review the current application.'); | ||
} else { | ||
_logger.i( | ||
'Failed to prompt user to review the current application because the platform does not support it.'); | ||
} | ||
} | ||
} |
Oops, something went wrong.