Skip to content
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🛠️ core

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

Expand Down
31 changes: 25 additions & 6 deletions lib/src/fixtures/local_ads.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
import 'package:core/core.dart';
// Import ContentStatus

/// A list of predefined local ads for fixture data.
final localAdsFixturesData = <LocalAd>[
const LocalNativeAd(
LocalNativeAd(
id: kLocalAd1Id,
title: 'Discover Our Premium Content',
subtitle: 'Unlock exclusive articles and an ad-free experience.',
imageUrl: 'https://example.com/ads/premium_native.png',
targetUrl: 'https://example.com/premium',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
const LocalBannerAd(
LocalBannerAd(
id: kLocalAd2Id,
imageUrl: 'https://example.com/ads/banner_ad_1.png',
targetUrl: 'https://example.com/offer1',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
const LocalInterstitialAd(
LocalInterstitialAd(
id: kLocalAd3Id,
imageUrl: 'https://example.com/ads/interstitial_ad_1.png',
targetUrl: 'https://example.com/special_offer',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
const LocalVideoAd(
LocalVideoAd(
id: kLocalAd4Id,
videoUrl: 'https://example.com/ads/promo_video.mp4',
targetUrl: 'https://example.com/watch_more',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
const LocalNativeAd(
LocalNativeAd(
id: kLocalAd5Id,
title: 'Stay Informed with Daily Briefings',
subtitle: 'Get the top news delivered straight to your inbox.',
imageUrl: 'https://example.com/ads/briefing_native.png',
targetUrl: 'https://example.com/subscribe',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
const LocalBannerAd(
LocalBannerAd(
id: kLocalAd6Id,
imageUrl: 'https://example.com/ads/banner_ad_2.png',
targetUrl: 'https://example.com/offer2',
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
status: ContentStatus.active,
),
];
3 changes: 3 additions & 0 deletions lib/src/models/feed_decorators/local_ad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ abstract class LocalAd extends FeedItem {
/// The type of the ad (e.g., banner, native, interstitial, video).
final String adType;

/// A unique identifier for the local ad instance, typically a UUID.
String get id;

@override
List<Object?> get props => [adType, type];
}
39 changes: 37 additions & 2 deletions lib/src/models/local_ads/local_banner_ad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:core/src/utils/utils.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';

Expand All @@ -17,13 +18,17 @@ class LocalBannerAd extends LocalAd {
required this.id,
required this.imageUrl,
required this.targetUrl,
required this.createdAt,
required this.updatedAt,
required this.status,
}) : super(adType: 'banner');

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

/// Unique identifier for the local banner ad.
@override
final String id;

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

/// The creation timestamp of the local banner ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime createdAt;

/// The last update timestamp of the local banner ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime updatedAt;

/// The current status of the local banner ad.
final ContentStatus status;

Map<String, dynamic> toJson() {
final json = _$LocalBannerAdToJson(this);
json['adType'] = adType;
Expand All @@ -40,15 +56,34 @@ class LocalBannerAd extends LocalAd {
}

@override
List<Object?> get props => [id, imageUrl, targetUrl, adType, type];
List<Object?> get props => [
id,
imageUrl,
targetUrl,
createdAt,
updatedAt,
status,
adType,
type,
];

/// Creates a copy of this [LocalBannerAd] but with the given fields replaced with
/// the new values.
LocalBannerAd copyWith({String? id, String? imageUrl, String? targetUrl}) {
LocalBannerAd copyWith({
String? id,
String? imageUrl,
String? targetUrl,
DateTime? createdAt,
DateTime? updatedAt,
ContentStatus? status,
}) {
return LocalBannerAd(
id: id ?? this.id,
imageUrl: imageUrl ?? this.imageUrl,
targetUrl: targetUrl ?? this.targetUrl,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
status: status ?? this.status,
);
}
}
21 changes: 21 additions & 0 deletions lib/src/models/local_ads/local_banner_ad.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion lib/src/models/local_ads/local_interstitial_ad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:core/src/utils/utils.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';

Expand All @@ -18,13 +19,17 @@ class LocalInterstitialAd extends LocalAd {
required this.id,
required this.imageUrl,
required this.targetUrl,
required this.createdAt,
required this.updatedAt,
required this.status,
}) : super(adType: 'interstitial');

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

/// Unique identifier for the local interstitial ad.
@override
final String id;

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

/// The creation timestamp of the local interstitial ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime createdAt;

/// The last update timestamp of the local interstitial ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime updatedAt;

/// The current status of the local interstitial ad.
final ContentStatus status;

Map<String, dynamic> toJson() {
final json = _$LocalInterstitialAdToJson(this);
json['adType'] = adType;
Expand All @@ -41,19 +57,34 @@ class LocalInterstitialAd extends LocalAd {
}

@override
List<Object?> get props => [id, imageUrl, targetUrl, adType, type];
List<Object?> get props => [
id,
imageUrl,
targetUrl,
createdAt,
updatedAt,
status,
adType,
type,
];

/// Creates a copy of this [LocalInterstitialAd] but with the given fields
/// replaced with the new values.
LocalInterstitialAd copyWith({
String? id,
String? imageUrl,
String? targetUrl,
DateTime? createdAt,
DateTime? updatedAt,
ContentStatus? status,
}) {
return LocalInterstitialAd(
id: id ?? this.id,
imageUrl: imageUrl ?? this.imageUrl,
targetUrl: targetUrl ?? this.targetUrl,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
status: status ?? this.status,
);
}
}
21 changes: 21 additions & 0 deletions lib/src/models/local_ads/local_interstitial_ad.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions lib/src/models/local_ads/local_native_ad.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:core/src/utils/utils.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';

Expand All @@ -20,13 +21,17 @@ class LocalNativeAd extends LocalAd {
required this.subtitle,
required this.imageUrl,
required this.targetUrl,
required this.createdAt,
required this.updatedAt,
required this.status,
}) : super(adType: 'native');

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

/// Unique identifier for the local native ad.
@override
final String id;

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

/// The creation timestamp of the local native ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime createdAt;

/// The last update timestamp of the local native ad.
@JsonKey(fromJson: dateTimeFromJson, toJson: dateTimeToJson)
final DateTime updatedAt;

/// The current status of the local native ad.
final ContentStatus status;

Map<String, dynamic> toJson() {
final json = _$LocalNativeAdToJson(this);
json['adType'] = adType;
Expand All @@ -55,6 +71,9 @@ class LocalNativeAd extends LocalAd {
subtitle,
imageUrl,
targetUrl,
createdAt,
updatedAt,
status,
adType,
type,
];
Expand All @@ -67,13 +86,19 @@ class LocalNativeAd extends LocalAd {
String? subtitle,
String? imageUrl,
String? targetUrl,
DateTime? createdAt,
DateTime? updatedAt,
ContentStatus? status,
}) {
return LocalNativeAd(
id: id ?? this.id,
title: title ?? this.title,
subtitle: subtitle ?? this.subtitle,
imageUrl: imageUrl ?? this.imageUrl,
targetUrl: targetUrl ?? this.targetUrl,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
status: status ?? this.status,
);
}
}
Loading
Loading