Skip to content

Commit ed5aa8b

Browse files
authored
Merge pull request #42 from flutter-news-app-full-source-code/refactore-local-ads-to-integrate-management-properties
Refactore local ads to integrate management properties
2 parents 79b4e85 + 8b3d79c commit ed5aa8b

File tree

12 files changed

+311
-155
lines changed

12 files changed

+311
-155
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🛠️ core
22

3-
![coverage: percentage](https://img.shields.io/badge/coverage-98-green)
3+
![coverage: percentage](https://img.shields.io/badge/coverage-97-green)
44
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
55
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
66

lib/src/fixtures/local_ads.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,58 @@
11
import 'package:core/core.dart';
2+
// Import ContentStatus
23

34
/// A list of predefined local ads for fixture data.
45
final localAdsFixturesData = <LocalAd>[
5-
const LocalNativeAd(
6+
LocalNativeAd(
67
id: kLocalAd1Id,
78
title: 'Discover Our Premium Content',
89
subtitle: 'Unlock exclusive articles and an ad-free experience.',
910
imageUrl: 'https://example.com/ads/premium_native.png',
1011
targetUrl: 'https://example.com/premium',
12+
createdAt: DateTime.now(),
13+
updatedAt: DateTime.now(),
14+
status: ContentStatus.active,
1115
),
12-
const LocalBannerAd(
16+
LocalBannerAd(
1317
id: kLocalAd2Id,
1418
imageUrl: 'https://example.com/ads/banner_ad_1.png',
1519
targetUrl: 'https://example.com/offer1',
20+
createdAt: DateTime.now(),
21+
updatedAt: DateTime.now(),
22+
status: ContentStatus.active,
1623
),
17-
const LocalInterstitialAd(
24+
LocalInterstitialAd(
1825
id: kLocalAd3Id,
1926
imageUrl: 'https://example.com/ads/interstitial_ad_1.png',
2027
targetUrl: 'https://example.com/special_offer',
28+
createdAt: DateTime.now(),
29+
updatedAt: DateTime.now(),
30+
status: ContentStatus.active,
2131
),
22-
const LocalVideoAd(
32+
LocalVideoAd(
2333
id: kLocalAd4Id,
2434
videoUrl: 'https://example.com/ads/promo_video.mp4',
2535
targetUrl: 'https://example.com/watch_more',
36+
createdAt: DateTime.now(),
37+
updatedAt: DateTime.now(),
38+
status: ContentStatus.active,
2639
),
27-
const LocalNativeAd(
40+
LocalNativeAd(
2841
id: kLocalAd5Id,
2942
title: 'Stay Informed with Daily Briefings',
3043
subtitle: 'Get the top news delivered straight to your inbox.',
3144
imageUrl: 'https://example.com/ads/briefing_native.png',
3245
targetUrl: 'https://example.com/subscribe',
46+
createdAt: DateTime.now(),
47+
updatedAt: DateTime.now(),
48+
status: ContentStatus.active,
3349
),
34-
const LocalBannerAd(
50+
LocalBannerAd(
3551
id: kLocalAd6Id,
3652
imageUrl: 'https://example.com/ads/banner_ad_2.png',
3753
targetUrl: 'https://example.com/offer2',
54+
createdAt: DateTime.now(),
55+
updatedAt: DateTime.now(),
56+
status: ContentStatus.active,
3857
),
3958
];

lib/src/models/feed_decorators/local_ad.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ abstract class LocalAd extends FeedItem {
6969
/// The type of the ad (e.g., banner, native, interstitial, video).
7070
final String adType;
7171

72+
/// A unique identifier for the local ad instance, typically a UUID.
73+
String get id;
74+
7275
@override
7376
List<Object?> get props => [adType, type];
7477
}

lib/src/models/local_ads/local_banner_ad.dart

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:core/core.dart';
2+
import 'package:core/src/utils/utils.dart';
23
import 'package:json_annotation/json_annotation.dart';
34
import 'package:meta/meta.dart';
45

@@ -17,13 +18,17 @@ class LocalBannerAd extends LocalAd {
1718
required this.id,
1819
required this.imageUrl,
1920
required this.targetUrl,
21+
required this.createdAt,
22+
required this.updatedAt,
23+
required this.status,
2024
}) : super(adType: 'banner');
2125

2226
/// Creates a [LocalBannerAd] from JSON data.
2327
factory LocalBannerAd.fromJson(Map<String, dynamic> json) =>
2428
_$LocalBannerAdFromJson(json);
2529

2630
/// Unique identifier for the local banner ad.
31+
@override
2732
final String id;
2833

2934
/// The URL of the image for the local banner ad.
@@ -32,6 +37,17 @@ class LocalBannerAd extends LocalAd {
3237
/// The URL to navigate to when the local banner ad is clicked.
3338
final String targetUrl;
3439

40+
/// The creation timestamp of the local banner ad.
41+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
42+
final DateTime createdAt;
43+
44+
/// The last update timestamp of the local banner ad.
45+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
46+
final DateTime updatedAt;
47+
48+
/// The current status of the local banner ad.
49+
final ContentStatus status;
50+
3551
Map<String, dynamic> toJson() {
3652
final json = _$LocalBannerAdToJson(this);
3753
json['adType'] = adType;
@@ -40,15 +56,34 @@ class LocalBannerAd extends LocalAd {
4056
}
4157

4258
@override
43-
List<Object?> get props => [id, imageUrl, targetUrl, adType, type];
59+
List<Object?> get props => [
60+
id,
61+
imageUrl,
62+
targetUrl,
63+
createdAt,
64+
updatedAt,
65+
status,
66+
adType,
67+
type,
68+
];
4469

4570
/// Creates a copy of this [LocalBannerAd] but with the given fields replaced with
4671
/// the new values.
47-
LocalBannerAd copyWith({String? id, String? imageUrl, String? targetUrl}) {
72+
LocalBannerAd copyWith({
73+
String? id,
74+
String? imageUrl,
75+
String? targetUrl,
76+
DateTime? createdAt,
77+
DateTime? updatedAt,
78+
ContentStatus? status,
79+
}) {
4880
return LocalBannerAd(
4981
id: id ?? this.id,
5082
imageUrl: imageUrl ?? this.imageUrl,
5183
targetUrl: targetUrl ?? this.targetUrl,
84+
createdAt: createdAt ?? this.createdAt,
85+
updatedAt: updatedAt ?? this.updatedAt,
86+
status: status ?? this.status,
5287
);
5388
}
5489
}

lib/src/models/local_ads/local_banner_ad.g.dart

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/models/local_ads/local_interstitial_ad.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:core/core.dart';
2+
import 'package:core/src/utils/utils.dart';
23
import 'package:json_annotation/json_annotation.dart';
34
import 'package:meta/meta.dart';
45

@@ -18,13 +19,17 @@ class LocalInterstitialAd extends LocalAd {
1819
required this.id,
1920
required this.imageUrl,
2021
required this.targetUrl,
22+
required this.createdAt,
23+
required this.updatedAt,
24+
required this.status,
2125
}) : super(adType: 'interstitial');
2226

2327
/// Creates a [LocalInterstitialAd] from JSON data.
2428
factory LocalInterstitialAd.fromJson(Map<String, dynamic> json) =>
2529
_$LocalInterstitialAdFromJson(json);
2630

2731
/// Unique identifier for the local interstitial ad.
32+
@override
2833
final String id;
2934

3035
/// The URL of the image for the local interstitial ad.
@@ -33,6 +38,17 @@ class LocalInterstitialAd extends LocalAd {
3338
/// The URL to navigate to when the local interstitial ad is clicked.
3439
final String targetUrl;
3540

41+
/// The creation timestamp of the local interstitial ad.
42+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
43+
final DateTime createdAt;
44+
45+
/// The last update timestamp of the local interstitial ad.
46+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
47+
final DateTime updatedAt;
48+
49+
/// The current status of the local interstitial ad.
50+
final ContentStatus status;
51+
3652
Map<String, dynamic> toJson() {
3753
final json = _$LocalInterstitialAdToJson(this);
3854
json['adType'] = adType;
@@ -41,19 +57,34 @@ class LocalInterstitialAd extends LocalAd {
4157
}
4258

4359
@override
44-
List<Object?> get props => [id, imageUrl, targetUrl, adType, type];
60+
List<Object?> get props => [
61+
id,
62+
imageUrl,
63+
targetUrl,
64+
createdAt,
65+
updatedAt,
66+
status,
67+
adType,
68+
type,
69+
];
4570

4671
/// Creates a copy of this [LocalInterstitialAd] but with the given fields
4772
/// replaced with the new values.
4873
LocalInterstitialAd copyWith({
4974
String? id,
5075
String? imageUrl,
5176
String? targetUrl,
77+
DateTime? createdAt,
78+
DateTime? updatedAt,
79+
ContentStatus? status,
5280
}) {
5381
return LocalInterstitialAd(
5482
id: id ?? this.id,
5583
imageUrl: imageUrl ?? this.imageUrl,
5684
targetUrl: targetUrl ?? this.targetUrl,
85+
createdAt: createdAt ?? this.createdAt,
86+
updatedAt: updatedAt ?? this.updatedAt,
87+
status: status ?? this.status,
5788
);
5889
}
5990
}

lib/src/models/local_ads/local_interstitial_ad.g.dart

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/models/local_ads/local_native_ad.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:core/core.dart';
2+
import 'package:core/src/utils/utils.dart';
23
import 'package:json_annotation/json_annotation.dart';
34
import 'package:meta/meta.dart';
45

@@ -20,13 +21,17 @@ class LocalNativeAd extends LocalAd {
2021
required this.subtitle,
2122
required this.imageUrl,
2223
required this.targetUrl,
24+
required this.createdAt,
25+
required this.updatedAt,
26+
required this.status,
2327
}) : super(adType: 'native');
2428

2529
/// Creates a [LocalNativeAd] from JSON data.
2630
factory LocalNativeAd.fromJson(Map<String, dynamic> json) =>
2731
_$LocalNativeAdFromJson(json);
2832

2933
/// Unique identifier for the local native ad.
34+
@override
3035
final String id;
3136

3237
/// The main title or headline of the local native ad.
@@ -41,6 +46,17 @@ class LocalNativeAd extends LocalAd {
4146
/// The URL to navigate to when the local native ad is clicked.
4247
final String targetUrl;
4348

49+
/// The creation timestamp of the local native ad.
50+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
51+
final DateTime createdAt;
52+
53+
/// The last update timestamp of the local native ad.
54+
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
55+
final DateTime updatedAt;
56+
57+
/// The current status of the local native ad.
58+
final ContentStatus status;
59+
4460
Map<String, dynamic> toJson() {
4561
final json = _$LocalNativeAdToJson(this);
4662
json['adType'] = adType;
@@ -55,6 +71,9 @@ class LocalNativeAd extends LocalAd {
5571
subtitle,
5672
imageUrl,
5773
targetUrl,
74+
createdAt,
75+
updatedAt,
76+
status,
5877
adType,
5978
type,
6079
];
@@ -67,13 +86,19 @@ class LocalNativeAd extends LocalAd {
6786
String? subtitle,
6887
String? imageUrl,
6988
String? targetUrl,
89+
DateTime? createdAt,
90+
DateTime? updatedAt,
91+
ContentStatus? status,
7092
}) {
7193
return LocalNativeAd(
7294
id: id ?? this.id,
7395
title: title ?? this.title,
7496
subtitle: subtitle ?? this.subtitle,
7597
imageUrl: imageUrl ?? this.imageUrl,
7698
targetUrl: targetUrl ?? this.targetUrl,
99+
createdAt: createdAt ?? this.createdAt,
100+
updatedAt: updatedAt ?? this.updatedAt,
101+
status: status ?? this.status,
77102
);
78103
}
79104
}

0 commit comments

Comments
 (0)