Skip to content

Commit

Permalink
Merge branch 'develop' into fix/bottom-sheet-dividers
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Apr 18, 2024
2 parents aa9922f + d2cc015 commit 7141291
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 113 deletions.
57 changes: 28 additions & 29 deletions app/src/main/kotlin/com/wire/android/model/ImageAsset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,43 @@ import com.wire.kalium.logic.data.user.UserAssetId
import okio.Path

@Stable
sealed class ImageAsset(private val imageLoader: WireSessionImageLoader) {
/**
* Value that uniquely identifies this Asset,
* can be used for caching purposes, for example.
*/
abstract val uniqueKey: String

@Stable
data class UserAvatarAsset(
private val imageLoader: WireSessionImageLoader,
val userAssetId: UserAssetId
) : ImageAsset(imageLoader) {
override val uniqueKey: String
get() = userAssetId.toString()
}
sealed class ImageAsset {

/**
* Represents an image asset that is stored locally on the device, and it isn't necessarily bounded to any specific conversation or
* message, i.e. some preview images that the user selected from local device gallery.
*/
@Stable
data class LocalImageAsset(
private val imageLoader: WireSessionImageLoader,
data class Local(
val dataPath: Path,
val idKey: String
) : ImageAsset(imageLoader) {
) : ImageAsset()

sealed class Remote(private val imageLoader: WireSessionImageLoader) : ImageAsset() {

/**
* Value that uniquely identifies this Asset,
* can be used for caching purposes, for example.
*/
abstract val uniqueKey: String

@Composable
fun paint(
fallbackData: Any? = null,
withCrossfadeAnimation: Boolean = false
) = when {
LocalInspectionMode.current -> painterResource(id = R.drawable.ic_welcome_1)
else -> imageLoader.paint(asset = this, fallbackData = fallbackData, withCrossfadeAnimation = withCrossfadeAnimation)
}
}

@Stable
data class UserAvatarAsset(
private val imageLoader: WireSessionImageLoader,
val userAssetId: UserAssetId
) : Remote(imageLoader) {
override val uniqueKey: String
get() = idKey
get() = userAssetId.toString()
}

@Stable
Expand All @@ -68,20 +76,11 @@ sealed class ImageAsset(private val imageLoader: WireSessionImageLoader) {
val messageId: String,
val isSelfAsset: Boolean,
val isEphemeral: Boolean = false
) : ImageAsset(imageLoader) {
) : Remote(imageLoader) {
override fun toString(): String = "$conversationId:$messageId:$isSelfAsset:$isEphemeral"
override val uniqueKey: String
get() = toString()
}

@Composable
fun paint(
fallbackData: Any? = null,
withCrossfadeAnimation: Boolean = false
) = when {
LocalInspectionMode.current -> painterResource(id = R.drawable.ic_welcome_1)
else -> imageLoader.paint(asset = this, fallbackData = fallbackData, withCrossfadeAnimation = withCrossfadeAnimation)
}
}

fun String.parseIntoPrivateImageAsset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ fun MessageImage(
transferStatus: AssetTransferStatus,
onImageClick: Clickable,
shouldFillMaxWidth: Boolean = false,
isImportedMediaAsset: Boolean = false
) {
Box(
Modifier
.padding(top = MaterialTheme.wireDimensions.spacing4x)
.clip(shape = RoundedCornerShape(dimensions().messageAssetBorderRadius))
.background(
color = MaterialTheme.wireColorScheme.onPrimary, shape = RoundedCornerShape(dimensions().messageAssetBorderRadius)
color = MaterialTheme.wireColorScheme.onPrimary,
shape = RoundedCornerShape(dimensions().messageAssetBorderRadius)
)
.border(
width = dimensions().spacing1x,
Expand Down Expand Up @@ -212,9 +212,9 @@ fun MessageImage(
)
}

asset != null -> {
if (isImportedMediaAsset) ImportedImageMessage(asset, shouldFillMaxWidth)
else DisplayableImageMessage(asset, imgParams.normalizedWidth, imgParams.normalizedHeight)
asset != null -> when (asset) {
is ImageAsset.Local -> ImportedImageMessage(asset, shouldFillMaxWidth)
is ImageAsset.Remote -> DisplayableImageMessage(asset, imgParams.normalizedWidth, imgParams.normalizedHeight)
}

// Show error placeholder
Expand All @@ -230,7 +230,7 @@ fun MessageImage(

@Composable
fun MediaAssetImage(
asset: ImageAsset?,
asset: ImageAsset.Remote?,
width: Dp,
height: Dp,
transferStatus: AssetTransferStatus?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import coil.compose.AsyncImage
import coil.compose.SubcomposeAsyncImage
import com.wire.android.R
import com.wire.android.model.ImageAsset
Expand All @@ -52,7 +53,7 @@ import okio.Path

@Composable
fun DisplayableImageMessage(
imageData: ImageAsset,
imageData: ImageAsset.Remote,
width: Dp,
height: Dp,
modifier: Modifier = Modifier
Expand Down Expand Up @@ -82,8 +83,10 @@ fun AsyncImageMessage(
.width(width)
.height(height),
loading = { _ ->
Box(modifier = Modifier.size(MaterialTheme.wireDimensions.spacing24x),
contentAlignment = Alignment.Center) {
Box(
modifier = Modifier.size(MaterialTheme.wireDimensions.spacing24x),
contentAlignment = Alignment.Center
) {
WireCircularProgressIndicator(
progressColor = MaterialTheme.wireColorScheme.primary,
modifier = Modifier.padding(dimensions().spacing24x)
Expand All @@ -97,12 +100,12 @@ fun AsyncImageMessage(

@Composable
fun ImportedImageMessage(
imageData: ImageAsset,
imageData: ImageAsset.Local,
shouldFillMaxWidth: Boolean,
modifier: Modifier = Modifier
) {
Image(
painter = imageData.paint(),
AsyncImage(
model = imageData.dataPath.toFile(),
contentDescription = stringResource(R.string.content_description_image_message),
modifier = if (!shouldFillMaxWidth) modifier
.width(dimensions().importedMediaAssetSize)
Expand Down Expand Up @@ -165,15 +168,15 @@ fun ImageMessageFailed(width: Dp, height: Dp, isDownloadFailure: Boolean) {
tint = MaterialTheme.colorScheme.error,
modifier = Modifier
)
Spacer(modifier = Modifier.height(MaterialTheme.wireDimensions.spacing8x))
Text(
text = stringResource(
id = if (isDownloadFailure) R.string.error_downloading_image_message
else R.string.error_uploading_image_message
),
textAlign = TextAlign.Center,
style = MaterialTheme.wireTypography.subline01.copy(color = MaterialTheme.wireColorScheme.error)
)
}
Spacer(modifier = Modifier.height(MaterialTheme.wireDimensions.spacing8x))
Text(
text = stringResource(
id = if (isDownloadFailure) R.string.error_downloading_image_message
else R.string.error_uploading_image_message
),
textAlign = TextAlign.Center,
style = MaterialTheme.wireTypography.subline01.copy(color = MaterialTheme.wireColorScheme.error)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import com.wire.android.model.ImageAsset
import com.wire.android.util.ui.WireSessionImageLoader

@Composable
fun ZoomableImage(imageAsset: ImageAsset, contentDescription: String, imageScale: Float = 1.0f) {
fun ZoomableImage(imageAsset: ImageAsset.Remote, contentDescription: String, imageScale: Float = 1.0f) {
var offsetX by remember { mutableStateOf(0f) }
var offsetY by remember { mutableStateOf(0f) }
var zoom by remember { mutableStateOf(1f) }
Expand All @@ -47,7 +46,8 @@ fun ZoomableImage(imageAsset: ImageAsset, contentDescription: String, imageScale
Image(
painter = imageAsset.paint(),
contentDescription = contentDescription,
modifier = Modifier.align(Alignment.Center)
modifier = Modifier
.align(Alignment.Center)
.graphicsLayer(
scaleX = zoom,
scaleY = zoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveSelfDeletionTim
import com.wire.kalium.logic.feature.selfDeletingMessages.PersistNewSelfDeletionTimerUseCase
import com.wire.kalium.logic.feature.user.GetSelfUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -303,7 +306,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
ImportMediaSnackbarMessages.MaxAssetSizeExceeded(importedAsset.assetSizeExceeded!!)
)
}
importMediaState = importMediaState.copy(importedAssets = mutableListOf(importedAsset))
importMediaState = importMediaState.copy(importedAssets = persistentListOf(importedAsset))
}
}
}
Expand All @@ -314,7 +317,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
handleImportedAsset(fileUri)
} ?: listOf()

importMediaState = importMediaState.copy(importedAssets = importedMediaAssets)
importMediaState = importMediaState.copy(importedAssets = importedMediaAssets.toPersistentList())

importedMediaAssets.firstOrNull { it.assetSizeExceeded != null }?.let {
onSnackbarMessage(ImportMediaSnackbarMessages.MaxAssetSizeExceeded(it.assetSizeExceeded!!))
Expand Down Expand Up @@ -430,8 +433,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
assetBundle = assetBundle,
width = imgWidth,
height = imgHeight,
assetSizeExceeded = assetSizeExceeded,
wireSessionImageLoader = wireSessionImageLoader
assetSizeExceeded = assetSizeExceeded
)
}

Expand All @@ -458,7 +460,7 @@ class ImportMediaAuthenticatedViewModel @Inject constructor(
@Stable
data class ImportMediaAuthenticatedState(
val avatarAsset: ImageAsset.UserAvatarAsset? = null,
val importedAssets: List<ImportedMediaAsset> = emptyList(),
val importedAssets: PersistentList<ImportedMediaAsset> = persistentListOf(),
val importedText: String? = null,
val isImporting: Boolean = false,
val shareableConversationListState: ShareableConversationListState = ShareableConversationListState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.wire.android.ui.sharing

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.LocalOverscrollConfiguration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -30,20 +29,17 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
Expand Down Expand Up @@ -88,6 +84,7 @@ import com.wire.android.util.ui.LinkText
import com.wire.android.util.ui.LinkTextData
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.util.isPositiveNotNull
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
Expand Down Expand Up @@ -358,30 +355,16 @@ private fun ImportMediaContent(
onConversationClicked: (conversationId: ConversationId) -> Unit,
searchBarState: SearchBarState
) {
val importedItemsList: List<ImportedMediaAsset> = state.importedAssets
val importedItemsList: PersistentList<ImportedMediaAsset> = state.importedAssets
val itemsToImport = importedItemsList.size
val pagerState = rememberPagerState(pageCount = { itemsToImport })
val isMultipleImport = itemsToImport > 1

val isMultipleImport = itemsToImport != 1

Column(
modifier = Modifier
.padding(internalPadding)
.fillMaxSize()
) {
val horizontalPadding = dimensions().spacing8x
val screenWidth = LocalConfiguration.current.screenWidthDp.dp
val itemWidth =
if (isMultipleImport) dimensions().importedMediaAssetSize + horizontalPadding.times(2)
else screenWidth - (horizontalPadding * 2)
val contentPadding = if (isMultipleImport) {
PaddingValues(
start = horizontalPadding,
end = (screenWidth - itemWidth + horizontalPadding)
)
} else {
val totalPadding = screenWidth - itemWidth
PaddingValues(start = totalPadding / 2, end = totalPadding / 2)
}
val lazyListState = rememberLazyListState()
if (state.isImporting) {
Box(
Expand All @@ -396,16 +379,25 @@ private fun ImportMediaContent(
size = dimensions().spacing24x
)
}
} else if (!isMultipleImport) {
Box(modifier = Modifier.padding(horizontal = dimensions().spacing16x)) {
ImportedMediaItemView(
item = importedItemsList.first(),
isMultipleImport = false
)
}
} else {
CompositionLocalProvider(LocalOverscrollConfiguration provides null) {
HorizontalPager(
state = pagerState,
contentPadding = contentPadding,
pageSpacing = dimensions().spacing8x
) { page ->
LazyRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(dimensions().spacing8x),
contentPadding = PaddingValues(start = dimensions().spacing16x, end = dimensions().spacing16x)
) {
items(
count = importedItemsList.size,
) { index ->
ImportedMediaItemView(
importedItemsList[page],
isMultipleImport
item = importedItemsList[index],
isMultipleImport = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.wire.android.ui.sharing

import com.wire.android.model.ImageAsset
import com.wire.android.ui.home.conversations.model.AssetBundle
import com.wire.android.util.ui.WireSessionImageLoader

sealed class ImportedMediaAsset(
open val assetBundle: AssetBundle,
Expand All @@ -35,8 +34,7 @@ sealed class ImportedMediaAsset(
val height: Int,
override val assetBundle: AssetBundle,
override val assetSizeExceeded: Int?,
val wireSessionImageLoader: WireSessionImageLoader
) : ImportedMediaAsset(assetBundle, assetSizeExceeded) {
val localImageAsset = ImageAsset.LocalImageAsset(wireSessionImageLoader, assetBundle.dataPath, assetBundle.key)
val localImageAsset = ImageAsset.Local(assetBundle.dataPath, assetBundle.key)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ fun ImportedImageView(item: ImportedMediaAsset.Image, isMultipleImport: Boolean)
transferStatus = AssetTransferStatus.NOT_DOWNLOADED,
onImageClick = Clickable(enabled = false),
shouldFillMaxWidth = !isMultipleImport,
isImportedMediaAsset = true
)
}

Expand Down
Loading

0 comments on commit 7141291

Please sign in to comment.