Skip to content

Commit

Permalink
Merge pull request #232 from GetStream/agp/8.4.1
Browse files Browse the repository at this point in the history
Migrate to Kotlin 2.0.0 and Compose compiler plugin
  • Loading branch information
skydoves authored Jun 7, 2024
2 parents 9bb039b + 76ae98a commit 5850711
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
versionName = Configurations.versionName
}

packagingOptions {
packaging {
resources {
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
}
Expand Down
1 change: 1 addition & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ java {

dependencies {
compileOnly(libs.android.gradlePlugin)
compileOnly(libs.compose.compiler.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.spotless.gradlePlugin)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,27 @@
package io.getstream.whatsappclone

import com.android.build.api.dsl.CommonExtension
import java.io.File
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension

/**
* Configure Compose-specific options
*/
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")

commonExtension.apply {
buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.findVersion("androidxComposeCompiler").get().toString()
}

kotlinOptions {
freeCompilerArgs = freeCompilerArgs + buildComposeMetricsParameters()
}
}
}

private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = File(project.buildDir, "compose-metrics")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath
)
}

val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = File(project.buildDir, "compose-reports")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath
)
extensions.configure<ComposeCompilerGradlePluginExtension> {
enableStrongSkippingMode = true
reportsDestination = layout.buildDirectory.dir("compose_compiler")
}
return metricParameters.toList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ package io.getstream.whatsappclone
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

/**
* Configure base Kotlin with Android options
*/
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
commonExtension.apply {
compileSdk = 34
Expand All @@ -25,7 +22,6 @@ internal fun Project.configureKotlinAndroid(
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}

lint {
Expand All @@ -50,14 +46,8 @@ internal fun Project.configureKotlinAndroid(
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
add("coreLibraryDesugaring", libs.findLibrary("android.desugarJdkLibs").get())
}
}

fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.google.secrets) apply false
alias(libs.plugins.spotless) apply false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.glide.GlideImage
import io.getstream.whatsappclone.designsystem.icon.WhatsAppIcons
Expand All @@ -57,7 +58,9 @@ fun WhatsAppCallHistory(
.size(56.dp)
.clip(CircleShape),
imageModel = { whatsAppUser.picture },
previewPlaceholder = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
previewPlaceholder = painterResource(
id = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
)
)

Column(modifier = Modifier.padding(start = 12.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -57,7 +58,7 @@ fun WhatsAppCallHistoryInfoBody(
top.linkTo(parent.top)
},
imageModel = { whatsAppUser.picture },
previewPlaceholder = R.drawable.placeholder
previewPlaceholder = painterResource(id = R.drawable.placeholder)
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fun WhatsAppChannels(
Box(modifier = Modifier.fillMaxSize()) {
ChannelsScreen(
isShowingHeader = false,
onItemClick = { channel ->
onChannelClick = { channel ->
whatsChannelsViewModel.navigateToMessages(channel.cid)
}
)
Expand All @@ -54,7 +54,7 @@ fun WhatsAppChannels(
.size(58.dp),
containerColor = GREEN500,
shape = CircleShape,
onClick = { }
onClick = { whatsChannelsViewModel.createChannel() }
) {
Icon(
imageVector = WhatsAppIcons.Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,38 @@
package io.getstream.whatsappclone.chats.channels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import io.getstream.chat.android.client.ChatClient
import io.getstream.whatsappclone.navigation.AppComposeNavigator
import io.getstream.whatsappclone.navigation.WhatsAppScreens
import javax.inject.Inject
import kotlin.random.Random
import kotlinx.coroutines.launch

@HiltViewModel
class WhatsChannelsViewModel @Inject constructor(
private val composeNavigator: AppComposeNavigator
private val composeNavigator: AppComposeNavigator,
private val chatClient: ChatClient
) : ViewModel() {

private val user = chatClient.clientState.user

fun navigateToMessages(channelId: String) {
composeNavigator.navigate(WhatsAppScreens.Messages.createRoute(channelId))
}

fun createChannel() {
viewModelScope.launch {
val me = user.value
if (me != null) {
chatClient.createChannel(
channelType = "messaging",
channelId = "channel${Random.nextInt(10000)}",
memberIds = listOf(me.id),
extraData = mapOf()
).await()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.animation.crossfade.CrossfadePlugin
Expand Down Expand Up @@ -121,7 +122,9 @@ private fun WhatsAppMessageUserInfo(
component = rememberImageComponent {
+CrossfadePlugin()
},
previewPlaceholder = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
previewPlaceholder = painterResource(
id = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
)
)

Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -63,7 +64,9 @@ fun WhatsAppStatus() {
.size(56.dp)
.clip(CircleShape),
imageModel = { "https://placekitten.com/200/300" },
previewPlaceholder = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
previewPlaceholder = painterResource(
id = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
)
)

Column(modifier = Modifier.padding(start = 12.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal fun ReactionsMenu(
val scope = rememberCoroutineScope()
val modifier = Modifier
.background(
color = VideoTheme.colors.barsBackground,
color = VideoTheme.colors.basePrimary,
shape = RoundedCornerShape(2.dp)
)
.wrapContentWidth()
Expand All @@ -107,14 +107,14 @@ internal fun ReactionsMenu(
Dialog(onDismiss) {
Card(
modifier = modifier.wrapContentWidth(),
backgroundColor = VideoTheme.colors.barsBackground
backgroundColor = VideoTheme.colors.basePrimary
) {
Column(Modifier.padding(16.dp)) {
Row(horizontalArrangement = Arrangement.Center) {
ReactionItem(
modifier = Modifier
.background(
color = VideoTheme.colors.appBackground,
color = VideoTheme.colors.basePrimary,
shape = RoundedCornerShape(2.dp)
)
.fillMaxWidth(),
Expand Down Expand Up @@ -163,7 +163,7 @@ private fun ReactionItem(
textAlign = TextAlign.Center,
modifier = textModifier.padding(12.dp),
text = "$mappedEmoji ${reaction.displayText}",
color = VideoTheme.colors.textHighEmphasis
color = VideoTheme.colors.baseSenary
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import android.os.Build
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -32,7 +32,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -44,8 +46,8 @@ import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.compose.ui.components.call.activecall.CallContent
import io.getstream.video.android.compose.ui.components.call.controls.ControlActions
import io.getstream.video.android.compose.ui.components.call.controls.actions.FlipCameraAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.GenericAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.LeaveCallAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.ReactionAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.ToggleCameraAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.ToggleMicrophoneAction
import io.getstream.video.android.core.Call
Expand Down Expand Up @@ -110,9 +112,12 @@ private fun WhatsAppVideoCallContent(
call = call,
actions = listOf(
{
ReactionAction(
GenericAction(
icon = ImageVector.vectorResource(
id = io.getstream.video.android.ui.common.R.drawable.stream_video_ic_reaction
),
modifier = Modifier.size(52.dp),
onCallAction = { isShowingReactionDialog = true }
onAction = { isShowingReactionDialog = true }
)
},
{
Expand Down Expand Up @@ -148,9 +153,12 @@ private fun WhatsAppVideoCallContent(
call = call,
actions = listOf(
{
ReactionAction(
GenericAction(
icon = ImageVector.vectorResource(
id = io.getstream.video.android.ui.common.R.drawable.stream_video_ic_reaction
),
modifier = Modifier.size(52.dp),
onCallAction = { isShowingReactionDialog = true }
onAction = { isShowingReactionDialog = true }
)
},
{
Expand Down
Loading

0 comments on commit 5850711

Please sign in to comment.