-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[interactive_media_ads] Adds support to set general SDK settings #9648
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
Changes from all commits
4b126be
bb4550e
c4fc99a
62edcca
e0c10a2
171d050
66c6ec8
6ffe107
a38e789
d94cb5b
6b9c519
b6235d6
032d8e7
b2c2a60
7b17129
de045bf
2798ecf
c0b52fd
cc03997
6ad5d1a
8792a50
bfa41ee
9962724
377d7f5
215b38a
09f7205
eb8bdb5
7ecb8c1
85d6f62
4bd107b
dac72ba
ed438ae
427e307
3f08cfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
import '../platform_interface/platform_ima_settings.dart'; | ||
import 'interactive_media_ads.g.dart'; | ||
|
||
/// Android implementation of [PlatformImaSettings]. | ||
final class AndroidImaSettings extends PlatformImaSettings { | ||
/// Constructs an [AndroidImaSettings]. | ||
AndroidImaSettings(super.params) : super.implementation(); | ||
|
||
/// The native Android ImaSdkSettings. | ||
/// | ||
/// Defines general SDK settings that are used when creating an `AdsLoader`. | ||
@internal | ||
late final Future<ImaSdkSettings> nativeSettingsFuture = _createSettings(); | ||
|
||
@override | ||
Future<void> setAutoPlayAdBreaks(bool autoPlayAdBreaks) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setAutoPlayAdBreaks(autoPlayAdBreaks); | ||
} | ||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many methods in this class follow the same pattern of awaiting To improve maintainability and reduce boilerplate, consider introducing a private helper method to encapsulate this pattern. For example: Future<void> _withSettings(Future<void> Function(ImaSdkSettings) callback) async {
final ImaSdkSettings settings = await nativeSettingsFuture;
await callback(settings);
} You could then refactor the methods like this: @override
Future<void> setAutoPlayAdBreaks(bool autoPlayAdBreaks) {
return _withSettings(
(ImaSdkSettings settings) => settings.setAutoPlayAdBreaks(autoPlayAdBreaks),
);
} |
||
|
||
@override | ||
Future<void> setDebugMode(bool enabled) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setDebugMode(enabled); | ||
} | ||
|
||
@override | ||
Future<void> setFeatureFlags(Map<String, String> featureFlags) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setFeatureFlags(featureFlags); | ||
} | ||
|
||
@override | ||
Future<void> setMaxRedirects(int maxRedirects) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setMaxRedirects(maxRedirects); | ||
} | ||
|
||
@override | ||
Future<void> setPlayerType(String playerType) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setPlayerType(playerType); | ||
} | ||
|
||
@override | ||
Future<void> setPlayerVersion(String playerVersion) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setPlayerVersion(playerVersion); | ||
} | ||
|
||
@override | ||
Future<void> setPpid(String ppid) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setPpid(ppid); | ||
} | ||
|
||
@override | ||
Future<void> setSessionID(String sessionID) async { | ||
final ImaSdkSettings settings = await nativeSettingsFuture; | ||
await settings.setSessionId(sessionID); | ||
} | ||
|
||
Future<ImaSdkSettings> _createSettings() async { | ||
final ImaSdkSettings settings = | ||
await ImaSdkFactory.instance.createImaSdkSettings(); | ||
if (params.language case final String language) { | ||
await settings.setLanguage(language); | ||
} | ||
return settings; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.