Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ constructor(
title: String,
companyName: String,
shouldOnlyShowDriverAwarenessDisclaimer: Boolean,
uiParams: TermsAndConditionsUIParamsDto?,
callback: (Result<Boolean>) -> Unit,
) {
// Align API behavior with iOS:
Expand All @@ -548,21 +549,32 @@ constructor(
return
}

if (shouldOnlyShowDriverAwarenessDisclaimer) {
val defaultParams: TermsAndConditionsUIParams = TermsAndConditionsUIParams.builder().build()
NavigationApi.showTermsAndConditionsDialog(
getActivity(),
companyName,
title,
defaultParams,
{ accepted -> callback(Result.success(accepted)) },
TermsAndConditionsCheckOption.SKIPPED,
)
} else {
NavigationApi.showTermsAndConditionsDialog(getActivity(), companyName, title) { accepted ->
callback(Result.success(accepted))
// Build UI customization parameters if provided
val termsUiParams: TermsAndConditionsUIParams? =
uiParams?.let {
TermsAndConditionsUIParams.builder()
.apply {
it.backgroundColor?.let { color -> setBackgroundColor(color.toInt()) }
it.titleColor?.let { color -> setTitleColor(color.toInt()) }
it.mainTextColor?.let { color -> setMainTextColor(color.toInt()) }
it.acceptButtonTextColor?.let { color -> setAcceptButtonTextColor(color.toInt()) }
it.cancelButtonTextColor?.let { color -> setCancelButtonTextColor(color.toInt()) }
}
.build()
}
}

val checkOption =
if (shouldOnlyShowDriverAwarenessDisclaimer) TermsAndConditionsCheckOption.SKIPPED
else TermsAndConditionsCheckOption.ENABLED

NavigationApi.showTermsAndConditionsDialog(
getActivity(),
companyName,
title,
termsUiParams,
{ accepted -> callback(Result.success(accepted)) },
checkOption,
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ class GoogleMapsNavigationSessionMessageHandler(
title: String,
companyName: String,
shouldOnlyShowDriverAwarenessDisclaimer: Boolean,
uiParams: TermsAndConditionsUIParamsDto?,
callback: (Result<Boolean>) -> Unit,
) {
sessionManager.showTermsAndConditionsDialog(
title,
companyName,
shouldOnlyShowDriverAwarenessDisclaimer,
uiParams,
callback,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,66 @@ data class NavInfoDto(
override fun hashCode(): Int = toList().hashCode()
}

/**
* UI customization parameters for the Terms and Conditions dialog.
*
* All color values are 32-bit ARGB integers (format: 0xAARRGGBB). All parameters are optional - if
* not provided, platform defaults will be used.
*
* Generated class from Pigeon that represents data sent in messages.
*/
data class TermsAndConditionsUIParamsDto(
/** Background color of the dialog box. */
val backgroundColor: Long? = null,
/** Text color for the dialog title. */
val titleColor: Long? = null,
/** Text color for the main terms and conditions text. */
val mainTextColor: Long? = null,
/** Text color for the accept button. */
val acceptButtonTextColor: Long? = null,
/** Text color for the cancel button. */
val cancelButtonTextColor: Long? = null,
) {
companion object {
fun fromList(pigeonVar_list: List<Any?>): TermsAndConditionsUIParamsDto {
val backgroundColor = pigeonVar_list[0] as Long?
val titleColor = pigeonVar_list[1] as Long?
val mainTextColor = pigeonVar_list[2] as Long?
val acceptButtonTextColor = pigeonVar_list[3] as Long?
val cancelButtonTextColor = pigeonVar_list[4] as Long?
return TermsAndConditionsUIParamsDto(
backgroundColor,
titleColor,
mainTextColor,
acceptButtonTextColor,
cancelButtonTextColor,
)
}
}

fun toList(): List<Any?> {
return listOf(
backgroundColor,
titleColor,
mainTextColor,
acceptButtonTextColor,
cancelButtonTextColor,
)
}

override fun equals(other: Any?): Boolean {
if (other !is TermsAndConditionsUIParamsDto) {
return false
}
if (this === other) {
return true
}
return MessagesPigeonUtils.deepEquals(toList(), other.toList())
}

override fun hashCode(): Int = toList().hashCode()
}

private open class messagesPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
Expand Down Expand Up @@ -2541,6 +2601,11 @@ private open class messagesPigeonCodec : StandardMessageCodec() {
195.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let { NavInfoDto.fromList(it) }
}
196.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
TermsAndConditionsUIParamsDto.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}
Expand Down Expand Up @@ -2815,6 +2880,10 @@ private open class messagesPigeonCodec : StandardMessageCodec() {
stream.write(195)
writeValue(stream, value.toList())
}
is TermsAndConditionsUIParamsDto -> {
stream.write(196)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down Expand Up @@ -6138,6 +6207,7 @@ interface NavigationSessionApi {
title: String,
companyName: String,
shouldOnlyShowDriverAwarenessDisclaimer: Boolean,
uiParams: TermsAndConditionsUIParamsDto?,
callback: (Result<Boolean>) -> Unit,
)

Expand Down Expand Up @@ -6317,10 +6387,12 @@ interface NavigationSessionApi {
val titleArg = args[0] as String
val companyNameArg = args[1] as String
val shouldOnlyShowDriverAwarenessDisclaimerArg = args[2] as Boolean
val uiParamsArg = args[3] as TermsAndConditionsUIParamsDto?
api.showTermsAndConditionsDialog(
titleArg,
companyNameArg,
shouldOnlyShowDriverAwarenessDisclaimerArg,
uiParamsArg,
) { result: Result<Boolean> ->
val error = result.exceptionOrNull()
if (error != null) {
Expand Down
55 changes: 55 additions & 0 deletions example/integration_test/t02_session_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,59 @@ void main() {
fail('Unsupported platform: ${Platform.operatingSystem}');
}
});

patrol('Test terms and conditions dialog with custom UI parameters', (
PatrolIntegrationTester $,
) async {
if (!Platform.isIOS) {
// Be sure location is enabled.
await $.native.enableLocation();
}

// Grant the location permission.
await checkLocationDialogAcceptance($);

/// Display navigation view.
final Key key = GlobalKey();
await pumpNavigationView(
$,
GoogleMapsNavigationView(
key: key,
onViewCreated: (GoogleNavigationViewController controller) {},
),
);

/// Reset TOS acceptance.
await GoogleMapsNavigator.resetTermsAccepted();
expect(await GoogleMapsNavigator.areTermsAccepted(), false);

/// Request native TOS dialog with custom UI parameters.
final Future<bool> tosAccepted =
GoogleMapsNavigator.showTermsAndConditionsDialog(
'test_title',
'test_company_name',
uiParams: const TermsAndConditionsUIParams(
backgroundColor: Color(0xFFFFFFFF),
titleColor: Color(0xFF1565C0),
mainTextColor: Color(0xFF424242),
acceptButtonTextColor: Color(0xFF2E7D32),
cancelButtonTextColor: Color(0xFFC62828),
),
);

// Tap ok.
if (Platform.isAndroid) {
await $.native.tap(Selector(text: "Got It"));
} else if (Platform.isIOS) {
await $.native.tap(Selector(text: "OK"));
} else {
fail('Unsupported platform: ${Platform.operatingSystem}');
}

// Check that the results match.
await tosAccepted.then((bool accept) {
expect(accept, true);
});
expect(await GoogleMapsNavigator.areTermsAccepted(), true);
});
}
7 changes: 7 additions & 0 deletions example/lib/pages/navigation_without_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class _NavigationWithoutMapPageState
companyName,
shouldOnlyShowDriverAwarenessDisclaimer:
shouldOnlyShowDriverAwarenessDisclaimer,
uiParams: const TermsAndConditionsUIParams(
backgroundColor: Color(0xFFECEFF1),
titleColor: Color(0xFF01579B),
mainTextColor: Color(0xFF263238),
acceptButtonTextColor: Color(0xFF00695C),
cancelButtonTextColor: Color(0xFFD32F2F),
),
);
showMessage(accepted ? 'Terms accepted' : 'Terms not accepted');
setState(() {
Expand Down
8 changes: 8 additions & 0 deletions example/lib/utils/terms_of_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@

// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:google_navigation_flutter/google_navigation_flutter.dart';

Future<bool> requestTermsAndConditionsAcceptance() async {
return (await GoogleMapsNavigator.areTermsAccepted()) ||
(await GoogleMapsNavigator.showTermsAndConditionsDialog(
'Example title',
'Example company',
uiParams: const TermsAndConditionsUIParams(
backgroundColor: Color(0xFFFFFFFF),
titleColor: Color(0xFF1565C0),
mainTextColor: Color(0xFF424242),
acceptButtonTextColor: Color(0xFF2E7D32),
cancelButtonTextColor: Color(0xFFC62828),
),
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,42 @@ class GoogleMapsNavigationSessionManager: NSObject {
func showTermsAndConditionsDialog(
title: String, companyName: String,
shouldOnlyShowDriverAwarenessDisclaimer: Bool,
uiParams: TermsAndConditionsUIParamsDto?,
completion: @escaping (Bool) -> Void
) {
GMSNavigationServices
.shouldOnlyShowDriverAwarenesssDisclaimer = shouldOnlyShowDriverAwarenessDisclaimer
GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(
withTitle: title, companyName: companyName
) { termsAccepted in
completion(termsAccepted)

// If customization params are provided, use the custom dialog
if let params = uiParams {
// Create UI params with custom colors (convert from ARGB Int64 to UIColor)
let uiParams = GMSNavigationTermsDialogUIParams(
backgroundColor: params.backgroundColor.map { UIColor(from: $0) },
titleFont: nil,
titleColor: params.titleColor.map { UIColor(from: $0) },
mainTextFont: nil,
mainTextColor: params.mainTextColor.map { UIColor(from: $0) },
buttonsFont: nil,
cancelButtonTextColor: params.cancelButtonTextColor.map { UIColor(from: $0) },
acceptButtonTextColor: params.acceptButtonTextColor.map { UIColor(from: $0) }
)

let options = GMSNavigationTermsAndConditionsOptions(companyName: companyName)
options.title = title
options.uiParams = uiParams

GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(
with: options
) { termsAccepted in
completion(termsAccepted)
}
} else {
// Use the simple API without customization
GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(
withTitle: title, companyName: companyName
) { termsAccepted in
completion(termsAccepted)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GoogleMapsNavigationSessionMessageHandler: NavigationSessionApi {
func showTermsAndConditionsDialog(
title: String, companyName: String,
shouldOnlyShowDriverAwarenessDisclaimer: Bool,
uiParams: TermsAndConditionsUIParamsDto?,
completion: @escaping (Result<Bool, Error>) -> Void
) {
if shouldOnlyShowDriverAwarenessDisclaimer {
Expand All @@ -42,7 +43,8 @@ class GoogleMapsNavigationSessionMessageHandler: NavigationSessionApi {
GoogleMapsNavigationSessionManager.shared.showTermsAndConditionsDialog(
title: title,
companyName: companyName,
shouldOnlyShowDriverAwarenessDisclaimer: shouldOnlyShowDriverAwarenessDisclaimer
shouldOnlyShowDriverAwarenessDisclaimer: shouldOnlyShowDriverAwarenessDisclaimer,
uiParams: uiParams
) { termsAccepted in
completion(Result.success(termsAccepted))
}
Expand Down
Loading