Skip to content

Commit

Permalink
chore: configure maps build process
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina committed Nov 13, 2023
1 parent 6a82804 commit d4ad9ea
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 9 deletions.
4 changes: 3 additions & 1 deletion AR-builder.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
'''
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
android:theme="@style/AppTheme.SplashScreen"
tools:replace="android:allowBackup,android:supportsRtl">

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${mapsKey}" />

<activity
android:name=".ui.AppLockActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import com.wire.android.ui.home.conversations.messages.QuotedMessageStyle
import com.wire.android.ui.home.conversations.messages.QuotedUnavailable
import com.wire.android.ui.home.conversations.messages.ReactionPill
import com.wire.android.ui.home.conversations.model.DeliveryStatusContent
import com.wire.android.ui.home.conversations.model.MapStaticImage
import com.wire.android.ui.home.conversations.model.MessageBody
import com.wire.android.ui.home.conversations.model.MessageFlowStatus
import com.wire.android.ui.home.conversations.model.MessageFooter
Expand Down Expand Up @@ -474,14 +475,7 @@ private fun MessageContent(
when (messageContent) {
is UIMessageContent.ImageMessage -> {
Column {
MessageImage(
asset = messageContent.asset,
imgParams = ImageMessageParams(messageContent.width, messageContent.height),
uploadStatus = messageContent.uploadStatus,
downloadStatus = messageContent.downloadStatus,
onImageClick = onImageClick
)
PartialDeliveryInformation(messageContent.deliveryStatus)
MapStaticImage()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -261,3 +278,69 @@ fun mapToDisplayMentions(uiText: UIText, resources: Resources): Pair<List<Displa
Pair(listOf(), uiText.asString(resources))
}
}

@Composable
fun MapStaticImage(location: LatLng = LatLng(52.5200066, 13.404954)) {
Column(
modifier = Modifier
.wrapContentSize()
) {
val map = rememberMapViewWithLifecycle()
val mapBitmap: MutableState<Bitmap?> = 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,11 @@ fun PreviewMessageWithMarkdownTablesAndBlocks() {
)
}
}

@PreviewMultipleThemes
@Composable
fun PreviewLocationMessage() {
WireTheme {
MapStaticImage()
}
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/scripts/variants.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,8 +58,12 @@ fun NamedDomainObjectContainer<ApplicationProductFlavor>.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
}
}

Expand Down

0 comments on commit d4ad9ea

Please sign in to comment.