From d4ad9ea0f5eb8327d747452f03581fa49d8a5645 Mon Sep 17 00:00:00 2001 From: yamilmedina Date: Mon, 13 Nov 2023 17:52:49 +0100 Subject: [PATCH] chore: configure maps build process --- AR-builder.groovy | 4 +- app/src/main/AndroidManifest.xml | 4 + .../ui/home/conversations/MessageItem.kt | 10 +-- .../home/conversations/model/MessageTypes.kt | 83 +++++++++++++++++++ .../model/MessageTypesPreview.kt | 8 ++ .../main/kotlin/scripts/variants.gradle.kts | 5 ++ 6 files changed, 105 insertions(+), 9 deletions(-) diff --git a/AR-builder.groovy b/AR-builder.groovy index 3b409e7b8bf..e79fcd62e5c 100644 --- a/AR-builder.groovy +++ b/AR-builder.groovy @@ -106,7 +106,8 @@ pipeline { steps { withCredentials([ string(credentialsId: 'GITHUB_PACKAGES_USER', variable: 'GITHUB_USER'), - string(credentialsId: 'GITHUB_PACKAGES_TOKEN', variable: 'GITHUB_TOKEN') + string(credentialsId: 'GITHUB_PACKAGES_TOKEN', variable: 'GITHUB_TOKEN'), + string(credentialsId: 'MAPS_API_KEY', variable: 'GOOGLE_MAPS_API_KEY') ]) { sh '''FILE=/${propertiesFile} if test -f "$FILE"; then @@ -117,6 +118,7 @@ pipeline { echo "ndk.dir="$NDK_HOME >> ${propertiesFile} echo "github.package_registry.user="$GITHUB_USER >> ${propertiesFile} echo "github.package_registry.token="$GITHUB_TOKEN >> ${propertiesFile} + echo "maps.apiKey="$GOOGLE_MAPS_API_KEY >> ${propertiesFile} ''' } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bbb40da9683..145d1e5e8fc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -77,6 +77,10 @@ android:theme="@style/AppTheme.SplashScreen" tools:replace="android:allowBackup,android:supportsRtl"> + + { Column { - MessageImage( - asset = messageContent.asset, - imgParams = ImageMessageParams(messageContent.width, messageContent.height), - uploadStatus = messageContent.uploadStatus, - downloadStatus = messageContent.downloadStatus, - onImageClick = onImageClick - ) - PartialDeliveryInformation(messageContent.deliveryStatus) + MapStaticImage() } } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypes.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypes.kt index 79a4c009b10..152678845d8 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypes.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypes.kt @@ -21,7 +21,10 @@ package com.wire.android.ui.home.conversations.model import android.content.res.Resources +import android.graphics.Bitmap +import android.os.Bundle import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.combinedClickable @@ -34,11 +37,24 @@ import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.unit.dp +import androidx.compose.ui.viewinterop.AndroidView +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import com.google.android.gms.maps.CameraUpdateFactory +import com.google.android.gms.maps.MapView +import com.google.android.gms.maps.model.LatLng +import com.google.maps.android.ktx.awaitMap import com.wire.android.di.hiltViewModelScoped import com.wire.android.model.Clickable import com.wire.android.model.ImageAsset @@ -65,6 +81,7 @@ import com.wire.kalium.logic.data.message.Message.DownloadStatus.DOWNLOAD_IN_PRO import com.wire.kalium.logic.data.message.Message.DownloadStatus.FAILED_DOWNLOAD import com.wire.kalium.logic.data.message.Message.UploadStatus.FAILED_UPLOAD import com.wire.kalium.logic.data.message.Message.UploadStatus.UPLOAD_IN_PROGRESS +import kotlinx.coroutines.launch import org.commonmark.Extension import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension import org.commonmark.ext.gfm.tables.TablesExtension @@ -261,3 +278,69 @@ fun mapToDisplayMentions(uiText: UIText, resources: Resources): Pair = remember { mutableStateOf(null) } + val coroutineScope = rememberCoroutineScope() + + if (mapBitmap.value != null) { + Image( + bitmap = mapBitmap.value!!.asImageBitmap(), + contentDescription = "Map snapshot", + ) + } else { + AndroidView({ map }) { mapView -> + coroutineScope.launch { + val googleMap = mapView.awaitMap() +// val zoom = calculateZoom() + googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 10f)) +// googleMap.addMarker { position(location) } + googleMap.snapshot { + mapBitmap.value = it + } + } + } + } + DisposableEffect(location) { + mapBitmap.value = null + onDispose { mapBitmap.value = null } + } + } +} + +@Composable +fun rememberMapViewWithLifecycle(): MapView { + val context = LocalContext.current + val mapView = remember { MapView(context) } + + // Makes MapView follow the lifecycle of this composable + val lifecycle = LocalLifecycleOwner.current.lifecycle + DisposableEffect(lifecycle, mapView) { + val lifecycleObserver = getMapLifecycleObserver(mapView) + lifecycle.addObserver(lifecycleObserver) + onDispose { + lifecycle.removeObserver(lifecycleObserver) + } + } + + return mapView +} + +private fun getMapLifecycleObserver(mapView: MapView): LifecycleEventObserver = + LifecycleEventObserver { _, event -> + when (event) { + Lifecycle.Event.ON_CREATE -> mapView.onCreate(Bundle()) + Lifecycle.Event.ON_START -> mapView.onStart() + Lifecycle.Event.ON_RESUME -> mapView.onResume() + Lifecycle.Event.ON_PAUSE -> mapView.onPause() + Lifecycle.Event.ON_STOP -> mapView.onStop() + Lifecycle.Event.ON_DESTROY -> mapView.onDestroy() + else -> throw IllegalStateException() + } + } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypesPreview.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypesPreview.kt index 3c1e6bc5e00..cf97fe7fed4 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypesPreview.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/MessageTypesPreview.kt @@ -588,3 +588,11 @@ fun PreviewMessageWithMarkdownTablesAndBlocks() { ) } } + +@PreviewMultipleThemes +@Composable +fun PreviewLocationMessage() { + WireTheme { + MapStaticImage() + } +} diff --git a/buildSrc/src/main/kotlin/scripts/variants.gradle.kts b/buildSrc/src/main/kotlin/scripts/variants.gradle.kts index cc281e09be0..2afabe816a9 100644 --- a/buildSrc/src/main/kotlin/scripts/variants.gradle.kts +++ b/buildSrc/src/main/kotlin/scripts/variants.gradle.kts @@ -30,6 +30,7 @@ import customization.Features import customization.overrideResourcesForAllFlavors import flavor.FlavorDimensions import flavor.ProductFlavors +import getLocalProperty plugins { id("com.android.application") apply false } // DO NOT USE CAPITAL LETTER FOR THE BUILD TYPE NAME OR JENKINS WILL BE MAD @@ -57,8 +58,12 @@ fun NamedDomainObjectContainer.createAppFlavour( dimension = flavour.dimensions applicationId = flavorApplicationId versionNameSuffix = "-${flavour.buildName}" + resValue("string", "app_name", flavour.appName) manifestPlaceholders["sharedUserId"] = sharedUserId + + val mapsKey = project.getLocalProperty("maps.apiKey", "not-set") + manifestPlaceholders["mapsKey"] = mapsKey } }