Skip to content

Commit

Permalink
[AND-12] Improve media storage permission handling. (#5518)
Browse files Browse the repository at this point in the history
* [AND-12] Improve media storage permission handling.

* [AND-12] Update CHANGELOG.md.

---------

Co-authored-by: PetarVelikov <[email protected]>
  • Loading branch information
VelikovPetar and PetarVelikov authored Dec 13, 2024
1 parent cc87ee6 commit 8041197
Show file tree
Hide file tree
Showing 12 changed files with 753 additions and 88 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
- Fix keyboard not closing when opening the attachments picker from `MessagesScreen`. [#5506](https://github.com/GetStream/stream-chat-android/pull/5506)

### ⬆️ Improved
- Add support for partial media access in `AttachmentsPickerImagesTabFactory` and `AttachmentsPickerFilesTabFactory` for Android 14+. [#5518](https://github.com/GetStream/stream-chat-android/pull/5518)

### ✅ Added
- The `StreamAttachmentFactories.defaultFactories()` method now accepts a `skipTypes` parameter to skip specific factory types. [#5494](https://github.com/GetStream/stream-chat-android/pull/5494)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ public final class io/getstream/chat/android/compose/ui/components/attachments/f
}

public final class io/getstream/chat/android/compose/ui/components/attachments/images/ImagesPickerKt {
public static final fun ImagesPicker (Ljava/util/List;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V
public static final fun ImagesPicker (Ljava/util/List;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function3;ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
}

public final class io/getstream/chat/android/compose/ui/components/audio/ComposableSingletons$PlaybackTimerKt {
Expand Down Expand Up @@ -1635,6 +1635,13 @@ public final class io/getstream/chat/android/compose/ui/messages/attachments/fac
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
}

public final class io/getstream/chat/android/compose/ui/messages/attachments/factory/ComposableSingletons$NoStorageAccessContentKt {
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/messages/attachments/factory/ComposableSingletons$NoStorageAccessContentKt;
public static field lambda-1 Lkotlin/jvm/functions/Function3;
public fun <init> ()V
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
}

public final class io/getstream/chat/android/compose/ui/messages/attachments/poll/ComposableSingletons$PollCreationDiscardDialogKt {
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/messages/attachments/poll/ComposableSingletons$PollCreationDiscardDialogKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
Expand Down
2 changes: 2 additions & 0 deletions stream-chat-android-compose/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- Needed to properly handle media re-selection on android 14+, otherwise we run the app in compatibility mode -->
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />

<application>
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
Expand All @@ -43,11 +45,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import coil.decode.VideoFrameDecoder
import coil.request.ImageRequest
Expand All @@ -71,6 +75,10 @@ private const val DefaultNumberOfPicturesPerRow = 3
* @param images The images the user can pick, to be rendered in a list.
* @param onImageSelected Handler when the user clicks on any image item.
* @param modifier Modifier for styling.
* @param itemContent Composable rendering an image/video item in the picker.
* @param showAddMore Flag indicating the the "Add more" item should be shown at the beginning of the picker.
* @param onAddMoreClick Action to be invoked when the user clicks on the "Add more" item.
* @param addMoreContent Composable rendering the "Add more" item.
*/
@Composable
public fun ImagesPicker(
Expand All @@ -83,12 +91,20 @@ public fun ImagesPicker(
onImageSelected = onImageSelected,
)
},
showAddMore: Boolean = false,
onAddMoreClick: () -> Unit = {},
addMoreContent: @Composable () -> Unit = {
DefaultAddMoreItem(onAddMoreClick)
},
) {
LazyVerticalGrid(
modifier = modifier,
columns = GridCells.Fixed(DefaultNumberOfPicturesPerRow),
contentPadding = PaddingValues(1.dp),
) {
if (showAddMore) {
item { addMoreContent() }
}
items(images) { imageItem -> itemContent(imageItem) }
}
}
Expand Down Expand Up @@ -210,6 +226,46 @@ private fun BoxScope.VideoThumbnailOverlay(
}
}

/**
* Default 'pick more' tile to be shown if the user can pick more images.
*
* @param onPickMoreClick Action invoked when the user clicks on the 'pick more' tile.
*/
@Composable
internal fun DefaultAddMoreItem(onPickMoreClick: () -> Unit) {
Column(
modifier = Modifier
.height(125.dp)
.padding(2.dp)
.clip(RoundedCornerShape(8.dp))
.border(
width = 1.dp,
color = ChatTheme.colors.borders,
shape = RoundedCornerShape(8.dp),
)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = ripple(),
onClick = onPickMoreClick,
)
.testTag("Stream_AttachmentPickerPickMore"),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Icon(
painter = painterResource(id = R.drawable.stream_compose_ic_add),
contentDescription = null,
tint = ChatTheme.colors.textLowEmphasis,
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.stream_ui_message_composer_permissions_visual_media_add_more),
style = ChatTheme.typography.body,
color = ChatTheme.colors.textLowEmphasis,
)
}
}

/**
* The time code of the frame to extract from a video.
*/
Expand Down
Loading

0 comments on commit 8041197

Please sign in to comment.