Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiple image preview [WPB-8801] #3004

Merged
merged 20 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions app/src/main/kotlin/com/wire/android/navigation/Extras.kt

This file was deleted.

18 changes: 18 additions & 0 deletions app/src/main/kotlin/com/wire/android/navigation/NavigationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import com.wire.android.ui.NavGraphs
import com.wire.android.ui.destinations.Destination
import com.wire.android.util.CustomTabsHelper
import com.wire.kalium.logger.obfuscateId
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json

@SuppressLint("RestrictedApi")
internal fun NavController.navigateToItem(command: NavigationCommand) {
Expand All @@ -44,6 +46,7 @@ internal fun NavController.navigateToItem(command: NavigationCommand) {
fun lastNestedGraph() = lastDestination()?.takeIf { it.navGraph() != navGraph }?.navGraph()
fun firstDestinationWithRoute(route: String) =
currentBackStack.value.firstOrNull { it.destination.route?.getBaseRoute() == route.getBaseRoute() }

fun lastDestinationFromOtherGraph(graph: NavGraphSpec) = currentBackStack.value.lastOrNull { it.navGraph() != graph }

appLogger.d("[$TAG] -> command: ${command.destination.route.obfuscateId()}")
Expand Down Expand Up @@ -115,4 +118,19 @@ fun Direction.handleNavigation(context: Context, handleOtherDirection: (Directio
else -> handleOtherDirection(this)
}

object ArgsSerializer {
@OptIn(ExperimentalSerializationApi::class)
private val instance: Json by lazy {
Json {
encodeDefaults = true
explicitNulls = false
// to enable the serialization of maps with complex keys
// e.g. Map<QualifiedIDEntity, PersistenceSession>
allowStructuredMapKeys = true
}
}

operator fun invoke() = instance
}

private const val TAG = "NavigationUtils"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.wire.android.ui.common.imagepreview

import android.net.Uri
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.wire.android.ui.userprofile.avatarpicker.ImageSource
Expand All @@ -30,7 +31,7 @@ import com.wire.android.util.permission.rememberTakePictureFlow

class AvatarPickerFlow(
private val takePictureFlow: UseCameraRequestFlow,
private val openGalleryFlow: UseStorageRequestFlow
private val openGalleryFlow: UseStorageRequestFlow<Uri?>
) {
fun launch(imageSource: ImageSource) {
when (imageSource) {
Expand All @@ -56,7 +57,8 @@ fun rememberPickPictureState(
)

val openGalleryFlow = rememberOpenGalleryFlow(
onGalleryItemPicked = { pickedPictureUri -> onImageSelected(pickedPictureUri) },
contract = ActivityResultContracts.GetContent(),
onGalleryItemPicked = { pickedPictureUri -> pickedPictureUri?.let { onImageSelected(it) } },
onPermissionDenied = { /* Nothing to do */ },
onPermissionPermanentlyDenied = onPermissionPermanentlyDenied
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,65 @@ import com.wire.kalium.logic.data.asset.AttachmentType

@Composable
fun AssetTooLargeDialog(dialogState: AssetTooLargeDialogState, hideDialog: () -> Unit) {
if (dialogState is AssetTooLargeDialogState.Visible) {
WireDialog(
title = getTitle(dialogState),
text = getLabel(dialogState),
buttonsHorizontalAlignment = false,
onDismiss = hideDialog,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
type = WireDialogButtonType.Primary,
onClick = hideDialog
when (dialogState) {
is AssetTooLargeDialogState.Visible -> {
WireDialog(
title = getTitle(dialogState),
text = getLabel(dialogState),
buttonsHorizontalAlignment = false,
onDismiss = hideDialog,
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
type = WireDialogButtonType.Primary,
onClick = hideDialog
)
)
)
}

AssetTooLargeDialogState.Hidden -> {}
}
}

@Composable
private fun getTitle(dialogState: AssetTooLargeDialogState.Visible) = when (dialogState.assetType) {
AttachmentType.IMAGE -> stringResource(R.string.title_image_could_not_be_sent)
AttachmentType.VIDEO -> stringResource(R.string.title_video_could_not_be_sent)
AttachmentType.AUDIO, // TODO
AttachmentType.GENERIC_FILE -> stringResource(R.string.title_file_could_not_be_sent)
private fun getTitle(dialogState: AssetTooLargeDialogState) = when (dialogState) {
AssetTooLargeDialogState.Hidden -> ""
is AssetTooLargeDialogState.Visible ->
if (dialogState.multipleAssets) {
stringResource(id = R.string.title_assets_could_not_be_sent)
} else {
when (dialogState.assetType) {
AttachmentType.IMAGE -> stringResource(R.string.title_image_could_not_be_sent)
AttachmentType.VIDEO -> stringResource(R.string.title_video_could_not_be_sent)
AttachmentType.AUDIO, // TODO
AttachmentType.GENERIC_FILE -> stringResource(R.string.title_file_could_not_be_sent)
}
}
}

@Composable
private fun getLabel(dialogState: AssetTooLargeDialogState.Visible) = when (dialogState.assetType) {
AttachmentType.IMAGE -> stringResource(R.string.label_shared_image_too_large, dialogState.maxLimitInMB)
AttachmentType.VIDEO -> stringResource(R.string.label_shared_video_too_large, dialogState.maxLimitInMB)
AttachmentType.AUDIO, // TODO
AttachmentType.GENERIC_FILE -> stringResource(R.string.label_shared_file_too_large, dialogState.maxLimitInMB)
}.let {
if (dialogState.savedToDevice) it + "\n" + stringResource(R.string.label_file_saved_to_device)
else it
private fun getLabel(dialogState: AssetTooLargeDialogState) = when (dialogState) {
AssetTooLargeDialogState.Hidden -> ""
is AssetTooLargeDialogState.Visible -> when (dialogState.assetType) {
AttachmentType.IMAGE -> stringResource(R.string.label_shared_image_too_large, dialogState.maxLimitInMB)
AttachmentType.VIDEO -> stringResource(R.string.label_shared_video_too_large, dialogState.maxLimitInMB)
AttachmentType.AUDIO, // TODO
AttachmentType.GENERIC_FILE -> stringResource(R.string.label_shared_file_too_large, dialogState.maxLimitInMB)
}.let {
var label = it
if (dialogState.multipleAssets) label = label + "\n" + stringResource(R.string.label_shared_multiple_assets_error)
if (dialogState.savedToDevice) label = label + "\n" + stringResource(R.string.label_file_saved_to_device)
label
}
}

@Preview
@Composable
fun PreviewAssetTooLargeDialog() {
AssetTooLargeDialog(AssetTooLargeDialogState.Visible(AttachmentType.VIDEO, 100, true)) {}
}

@Preview
@Composable
fun PreviewMultipleAssetTooLargeDialog() {
AssetTooLargeDialog(AssetTooLargeDialogState.Visible(AttachmentType.VIDEO, 100, false, true)) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
*/
package com.wire.android.ui.home.conversations

import com.wire.android.ui.home.conversations.model.AssetBundle
import com.wire.kalium.logic.data.id.ConversationId
import kotlinx.serialization.Serializable

@Serializable
data class ConversationNavArgs(
val conversationId: ConversationId,
val searchedMessageId: String? = null
val searchedMessageId: String? = null,
val pendingBundles: ArrayList<AssetBundle>? = null
)
Loading
Loading