Skip to content

Commit

Permalink
Merge pull request #221 from ouchadam/release-candidate
Browse files Browse the repository at this point in the history
[Auto] Release Candidate
  • Loading branch information
ouchadam authored Oct 24, 2022
2 parents fc9a864 + 173591e commit 02e8743
Show file tree
Hide file tree
Showing 24 changed files with 564 additions and 514 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/assemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/app/dapk/st/graph/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ internal class FeatureModules internal constructor(
chatEngineModule.engine,
context,
storeModule.value.messageStore(),
deviceMeta,
)
}
val homeModule by unsafeLazy { HomeModule(chatEngineModule.engine, storeModule.value, buildMeta) }
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ ext.kotlinTest = { dependencies ->
dependencies.testImplementation Dependencies.mavenCentral.kluent
dependencies.testImplementation Dependencies.mavenCentral.kotlinTest
dependencies.testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.7.20"
dependencies.testImplementation 'io.mockk:mockk:1.13.2'
dependencies.testImplementation Dependencies.mavenCentral.mockk
dependencies.testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'

dependencies.testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
dependencies.testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
}

ext.kotlinFixtures = { dependencies ->
dependencies.testFixturesImplementation 'io.mockk:mockk:1.13.1'
dependencies.testFixturesImplementation Dependencies.mavenCentral.mockk
dependencies.testFixturesImplementation Dependencies.mavenCentral.kluent
dependencies.testFixturesImplementation Dependencies.mavenCentral.kotlinCoroutinesCore
}
Expand Down
35 changes: 12 additions & 23 deletions chat-engine/src/main/kotlin/app/dapk/st/engine/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ sealed class RoomEvent {
abstract val utcTimestamp: Long
abstract val author: RoomMember
abstract val meta: MessageMeta
abstract val edited: Boolean

val time: String by lazy(mode = LazyThreadSafetyMode.NONE) {
val instant = Instant.ofEpochMilli(utcTimestamp)
ZonedDateTime.ofInstant(instant, DEFAULT_ZONE).toLocalTime().format(MESSAGE_TIME_FORMAT)
}

data class Encrypted(
override val eventId: EventId,
Expand All @@ -112,10 +118,8 @@ sealed class RoomEvent {
override val meta: MessageMeta,
) : RoomEvent() {

val time: String by lazy(mode = LazyThreadSafetyMode.NONE) {
val instant = Instant.ofEpochMilli(utcTimestamp)
ZonedDateTime.ofInstant(instant, DEFAULT_ZONE).toLocalTime().format(MESSAGE_TIME_FORMAT)
}
override val edited: Boolean = false

}

data class Message(
Expand All @@ -124,15 +128,9 @@ sealed class RoomEvent {
val content: String,
override val author: RoomMember,
override val meta: MessageMeta,
val edited: Boolean = false,
override val edited: Boolean = false,
val redacted: Boolean = false,
) : RoomEvent() {

val time: String by lazy(mode = LazyThreadSafetyMode.NONE) {
val instant = Instant.ofEpochMilli(utcTimestamp)
ZonedDateTime.ofInstant(instant, DEFAULT_ZONE).toLocalTime().format(MESSAGE_TIME_FORMAT)
}
}
) : RoomEvent()

data class Reply(
val message: RoomEvent,
Expand All @@ -143,13 +141,9 @@ sealed class RoomEvent {
override val utcTimestamp: Long = message.utcTimestamp
override val author: RoomMember = message.author
override val meta: MessageMeta = message.meta
override val edited: Boolean = message.edited

val replyingToSelf = replyingTo.author == message.author

val time: String by lazy(mode = LazyThreadSafetyMode.NONE) {
val instant = Instant.ofEpochMilli(utcTimestamp)
ZonedDateTime.ofInstant(instant, DEFAULT_ZONE).toLocalTime().format(MESSAGE_TIME_FORMAT)
}
}

data class Image(
Expand All @@ -158,14 +152,9 @@ sealed class RoomEvent {
val imageMeta: ImageMeta,
override val author: RoomMember,
override val meta: MessageMeta,
val edited: Boolean = false,
override val edited: Boolean = false,
) : RoomEvent() {

val time: String by lazy(mode = LazyThreadSafetyMode.NONE) {
val instant = Instant.ofEpochMilli(utcTimestamp)
ZonedDateTime.ofInstant(instant, DEFAULT_ZONE).toLocalTime().format(MESSAGE_TIME_FORMAT)
}

data class ImageMeta(
val width: Int?,
val height: Int?,
Expand Down
10 changes: 6 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ ext.Dependencies.with {

androidxComposeUi = "androidx.compose.ui:ui:${composeVer}"
androidxComposeFoundation = "androidx.compose.foundation:foundation:${composeVer}"
androidxComposeMaterial = "androidx.compose.material3:material3:1.0.0-beta03"
androidxComposeMaterial = "androidx.compose.material3:material3:1.0.0-rc01"
androidxComposeIconsExtended = "androidx.compose.material:material-icons-extended:${composeVer}"
androidxActivityCompose = "androidx.activity:activity-compose:1.4.0"
androidxActivityCompose = "androidx.activity:activity-compose:1.6.0"
kotlinCompilerExtensionVersion = "1.3.2"

firebaseCrashlyticsPlugin = "com.google.firebase:firebase-crashlytics-gradle:2.9.1"
firebaseCrashlyticsPlugin = "com.google.firebase:firebase-crashlytics-gradle:2.9.2"
firebaseBom = "com.google.firebase:firebase-bom:31.0.1"

jdkLibs = "com.android.tools:desugar_jdk_libs:1.1.5"
}

Expand Down Expand Up @@ -144,7 +146,7 @@ ext.Dependencies.with {
accompanistSystemuicontroller = "com.google.accompanist:accompanist-systemuicontroller:0.25.1"

junit = "junit:junit:4.13.2"
kluent = "org.amshove.kluent:kluent:1.70"
kluent = "org.amshove.kluent:kluent:1.71"
mockk = 'io.mockk:mockk:1.13.2'

matrixOlm = "org.matrix.android:olm-sdk:3.2.12"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package app.dapk.st.design.components

import androidx.compose.animation.core.Animatable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import kotlin.math.roundToInt

private val selfBackgroundShape = RoundedCornerShape(12.dp, 0.dp, 12.dp, 12.dp)
private val othersBackgroundShape = RoundedCornerShape(0.dp, 12.dp, 12.dp, 12.dp)

data class BubbleMeta(
val shape: RoundedCornerShape,
val background: Color,
val isSelf: Boolean,
)

fun BubbleMeta.isNotSelf() = !this.isSelf

@Composable
fun LazyItemScope.AlignedDraggableContainer(
avatar: Avatar,
isSelf: Boolean,
wasPreviousMessageSameSender: Boolean,
onReply: () -> Unit,
content: @Composable BubbleMeta.() -> Unit
) {
val rowWithMeta = @Composable {
DraggableRow(
avatar = avatar,
isSelf = isSelf,
wasPreviousMessageSameSender = wasPreviousMessageSameSender,
onReply = { onReply() }
) {
content(
when (isSelf) {
true -> BubbleMeta(selfBackgroundShape, SmallTalkTheme.extendedColors.selfBubble, isSelf = true)
false -> BubbleMeta(othersBackgroundShape, SmallTalkTheme.extendedColors.othersBubble, isSelf = false)
}
)
}
}

when (isSelf) {
true -> SelfContainer(rowWithMeta)
false -> OtherContainer(rowWithMeta)
}
}

@Composable
private fun LazyItemScope.OtherContainer(content: @Composable () -> Unit) {
Box(modifier = Modifier.Companion.fillParentMaxWidth(0.95f), contentAlignment = Alignment.TopStart) {
content()
}
}

@Composable
private fun LazyItemScope.SelfContainer(content: @Composable () -> Unit) {
Box(modifier = Modifier.Companion.fillParentMaxWidth(), contentAlignment = Alignment.TopEnd) {
Box(modifier = Modifier.Companion.fillParentMaxWidth(0.85f), contentAlignment = Alignment.TopEnd) {
content()
}
}
}

@Composable
private fun DraggableRow(
isSelf: Boolean,
wasPreviousMessageSameSender: Boolean,
onReply: () -> Unit,
avatar: Avatar,
content: @Composable () -> Unit
) {

val screenWidthDp = LocalConfiguration.current.screenWidthDp.dp
val localDensity = LocalDensity.current

val coroutineScope = rememberCoroutineScope()
val offsetX = remember { Animatable(0f) }

Row(
Modifier.padding(horizontal = 12.dp)
.offset { IntOffset(offsetX.value.roundToInt(), 0) }
.draggable(
orientation = Orientation.Horizontal,
state = rememberDraggableState {
if ((offsetX.value + it) > 0) {
coroutineScope.launch { offsetX.snapTo(offsetX.value + it) }
}
},
onDragStopped = {
with(localDensity) {
if (offsetX.value > (screenWidthDp.toPx() * 0.15)) {
onReply()
}
}

coroutineScope.launch {
offsetX.animateTo(targetValue = 0f)
}
}
)
) {
when (isSelf) {
true -> {
// do nothing
}

false -> SenderAvatar(wasPreviousMessageSameSender, avatar)
}
content()
}
}

@Composable
private fun SenderAvatar(wasPreviousMessageSameSender: Boolean, avatar: Avatar) {
val displayImageSize = 32.dp
when {
wasPreviousMessageSameSender -> {
Spacer(modifier = Modifier.width(displayImageSize))
}

avatar.url == null -> {
MissingAvatarIcon(avatar.name, displayImageSize)
}

else -> {
MessengerUrlIcon(avatar.url, displayImageSize)
}
}
}

data class Avatar(val url: String?, val name: String)
Loading

0 comments on commit 02e8743

Please sign in to comment.