|
| 1 | +// Copyright 2025 Samsung Electronics Co., Ltd. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/foundation.dart' show immutable, objectRuntimeType; |
| 6 | + |
| 7 | +/// Ad information class for DASH. This class contains all the necessary information about an ad. |
| 8 | +@immutable |
| 9 | +class AdInfoFromDash { |
| 10 | + /// Create a new instance of [AdInfoFromDash]. |
| 11 | + const AdInfoFromDash({ |
| 12 | + required this.adId, |
| 13 | + required this.cancelIndicator, |
| 14 | + required this.startTime, |
| 15 | + required this.endTime, |
| 16 | + required this.durationTime, |
| 17 | + required this.outOfNetworkIndicator, |
| 18 | + }); |
| 19 | + |
| 20 | + /// The unique identifier for the ad event from DASH. |
| 21 | + final int adId; |
| 22 | + |
| 23 | + /// When set to "true", indicates that a previously sent segmentation event, has been cancelled. |
| 24 | + final bool cancelIndicator; |
| 25 | + |
| 26 | + /// The start time of the ad in milliseconds. |
| 27 | + final int startTime; |
| 28 | + |
| 29 | + /// The end time of the ad in milliseconds. |
| 30 | + final int endTime; |
| 31 | + |
| 32 | + /// The duration of the ad in milliseconds. |
| 33 | + final int durationTime; |
| 34 | + |
| 35 | + /// When set to "1", indicates that the splice event is AD insert start time point, AD start time, end time and Duration are valid. |
| 36 | + /// When set to "0", indicates that the splice event is AD end time point, only end time is valid. |
| 37 | + final int outOfNetworkIndicator; |
| 38 | + |
| 39 | + /// Parse the ad information from a map. Returns null if the map is null or empty. Otherwise, returns a new instance of [AdInfoFromDash]. |
| 40 | + static AdInfoFromDash? fromAdInfoMap(Map<Object?, Object?>? adInfo) { |
| 41 | + if (adInfo!.isNotEmpty) { |
| 42 | + final int adId = adInfo['id']! as int; |
| 43 | + final int startTime = adInfo['start_ms']! as int; |
| 44 | + final int endTime = adInfo['end_ms']! as int; |
| 45 | + final int durationTime = adInfo['duration_ms']! as int; |
| 46 | + final int outOfNetworkIndicator = |
| 47 | + adInfo['out_of_network_indicator']! as int; |
| 48 | + final bool cancelIndicator = adInfo['cancel_indicator']! as bool; |
| 49 | + |
| 50 | + return AdInfoFromDash( |
| 51 | + adId: adId, |
| 52 | + cancelIndicator: cancelIndicator, |
| 53 | + startTime: startTime, |
| 54 | + endTime: endTime, |
| 55 | + durationTime: durationTime, |
| 56 | + outOfNetworkIndicator: outOfNetworkIndicator, |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + return null; |
| 61 | + } |
| 62 | + |
| 63 | + @override |
| 64 | + String toString() { |
| 65 | + return '${objectRuntimeType(this, 'AdInfoFromDash')}(' |
| 66 | + 'adId: $adId, ' |
| 67 | + 'cancelIndicator: $cancelIndicator, ' |
| 68 | + 'startTime: $startTime, ' |
| 69 | + 'endTime: $endTime, ' |
| 70 | + 'durationTime: $durationTime, ' |
| 71 | + 'outOfNetworkIndicator: $outOfNetworkIndicator)'; |
| 72 | + } |
| 73 | + |
| 74 | + @override |
| 75 | + bool operator ==(Object other) => |
| 76 | + identical(this, other) || |
| 77 | + other is AdInfoFromDash && |
| 78 | + runtimeType == other.runtimeType && |
| 79 | + adId == other.adId && |
| 80 | + cancelIndicator == other.cancelIndicator && |
| 81 | + startTime == other.startTime && |
| 82 | + endTime == other.endTime && |
| 83 | + durationTime == other.durationTime && |
| 84 | + outOfNetworkIndicator == other.outOfNetworkIndicator; |
| 85 | + |
| 86 | + @override |
| 87 | + int get hashCode => Object.hash( |
| 88 | + adId, |
| 89 | + cancelIndicator, |
| 90 | + startTime, |
| 91 | + endTime, |
| 92 | + durationTime, |
| 93 | + outOfNetworkIndicator, |
| 94 | + ); |
| 95 | +} |
0 commit comments