From a2bf59bcb8fefecf33222673dbec9de8b452b2fd Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Wed, 2 Aug 2023 08:01:30 +0530 Subject: [PATCH 1/4] refactor: delete confirmation dialog --- .../videopicker/composables/MediaContent.kt | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt index c8006ee89..ee4c7d3cf 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import dev.anilbeesetti.nextplayer.core.model.Directory import dev.anilbeesetti.nextplayer.core.model.Video @@ -157,12 +158,13 @@ fun VideosListFromState( deleteAction?.let { DeleteConfirmationDialog( + subText = "The following files will be deleted permanently", onCancel = { deleteAction = null }, onConfirm = { onDeleteVideoClick(it.uriString) deleteAction = null }, - deleteItems = listOf(it.nameWithExtension) + fileNames = listOf(it.nameWithExtension) ) } } @@ -220,39 +222,62 @@ fun FoldersListFromState( deleteAction?.let { DeleteConfirmationDialog( + subText = "The following files will be deleted permanently", onCancel = { deleteAction = null }, onConfirm = { onDeleteFolderClick(it.path) deleteAction = null }, - deleteItems = listOf(it.name) + fileNames = listOf(it.name) ) } } @Composable fun DeleteConfirmationDialog( + subText: String, onConfirm: () -> Unit, onCancel: () -> Unit, - deleteItems: List + fileNames: List, + modifier: Modifier = Modifier ) { NextDialog( onDismissRequest = onCancel, - title = { Text(text = stringResource(R.string.delete_file), modifier = Modifier.fillMaxWidth()) }, + title = { Text(text = stringResource(R.string.delete), modifier = Modifier.fillMaxWidth()) }, confirmButton = { DoneButton(onClick = onConfirm) }, dismissButton = { CancelButton(onClick = onCancel) }, + modifier = modifier, content = { - deleteItems.map { - Text( - text = it, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) + Text( + text = subText, + style = MaterialTheme.typography.titleSmall + ) + Spacer(modifier = Modifier.height(20.dp)) + LazyColumn { + items(fileNames) { + Text( + text = it, + overflow = TextOverflow.Ellipsis, + style = MaterialTheme.typography.bodyLarge + ) + } } } ) } + +@Preview +@Composable +fun DeleteDialogPreview() { + DeleteConfirmationDialog( + subText = "The following files will be deleted permanently", + onConfirm = { /*TODO*/ }, + onCancel = { /*TODO*/ }, + fileNames = listOf("Harry potter 1","Harry potter 2","Harry potter 3","Harry potter 4") + ) +} + @OptIn(ExperimentalMaterial3Api::class) @Composable fun OptionsBottomSheet( From 85cb796529738534472eae233e5500656de2ffce Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Wed, 2 Aug 2023 08:53:10 +0530 Subject: [PATCH 2/4] refactor: delete confirmation dialog --- core/ui/src/main/res/values/strings.xml | 3 ++- .../feature/videopicker/composables/MediaContent.kt | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index c2b05705f..92b80b211 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -138,6 +138,7 @@ %1$s seconds Share Delete - Delete the following file + The following file will be deleted permanently Subtitle text encoding + All video files in the following folder will be deleted permanently. \ No newline at end of file diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt index ee4c7d3cf..7e5a024ec 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt @@ -158,7 +158,7 @@ fun VideosListFromState( deleteAction?.let { DeleteConfirmationDialog( - subText = "The following files will be deleted permanently", + subText = stringResource(id = R.string.delete_file), onCancel = { deleteAction = null }, onConfirm = { onDeleteVideoClick(it.uriString) @@ -222,7 +222,7 @@ fun FoldersListFromState( deleteAction?.let { DeleteConfirmationDialog( - subText = "The following files will be deleted permanently", + subText = stringResource(R.string.delete_folder), onCancel = { deleteAction = null }, onConfirm = { onDeleteFolderClick(it.path) From 4bb2de7cc162e0510e26b0a2334286845941ddb4 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Wed, 2 Aug 2023 09:02:55 +0530 Subject: [PATCH 3/4] refactor: video and folder composables --- .../videopicker/composables/FolderItem.kt | 25 ++++----------- .../videopicker/composables/MediaContent.kt | 32 +++++++++++-------- .../videopicker/composables/VideoItem.kt | 19 +++-------- 3 files changed, 30 insertions(+), 46 deletions(-) diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt index 35880d459..76ffbb8d7 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt @@ -1,7 +1,5 @@ package dev.anilbeesetti.nextplayer.feature.videopicker.composables -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.FlowRow @@ -28,13 +26,11 @@ import dev.anilbeesetti.nextplayer.core.ui.designsystem.NextIcons import dev.anilbeesetti.nextplayer.core.ui.preview.DayNightPreview import dev.anilbeesetti.nextplayer.core.ui.theme.NextPlayerTheme -@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class) +@OptIn(ExperimentalLayoutApi::class) @Composable fun FolderItem( directory: Directory, - modifier: Modifier = Modifier, - onClick: () -> Unit, - onLongClick: () -> Unit + modifier: Modifier = Modifier ) { ListItem( leadingContent = { @@ -72,9 +68,9 @@ fun FolderItem( ) { InfoChip( text = "${directory.mediaCount} ${ - stringResource( - id = R.string.video.takeIf { directory.mediaCount == 1 } ?: R.string.videos - ) + stringResource( + id = R.string.video.takeIf { directory.mediaCount == 1 } ?: R.string.videos + ) }", modifier = Modifier.padding(vertical = 5.dp) ) @@ -84,10 +80,7 @@ fun FolderItem( ) } }, - modifier = modifier.combinedClickable( - onClick = onClick, - onLongClick = onLongClick - ) + modifier = modifier ) } @@ -95,11 +88,7 @@ fun FolderItem( @Composable fun FolderItemPreview() { NextPlayerTheme { - FolderItem( - directory = Directory.sample, - onClick = { }, - onLongClick = { } - ) + FolderItem(directory = Directory.sample) } } diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt index 7e5a024ec..f12eef496 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt @@ -2,7 +2,9 @@ package dev.anilbeesetti.nextplayer.feature.videopicker.composables import android.content.Intent import android.net.Uri +import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.clickable +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.PaddingValues @@ -85,7 +87,7 @@ fun NoVideosFound() { ) } -@OptIn(ExperimentalMaterial3Api::class) +@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable fun VideosListFromState( videosState: VideosState, @@ -108,11 +110,13 @@ fun VideosListFromState( items(videosState.data, key = { it.path }) { VideoItem( video = it, - onClick = { onVideoClick(Uri.parse(it.uriString)) }, - onLongClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - showMediaActionsFor = it - } + modifier = Modifier.combinedClickable( + onClick = { onVideoClick(Uri.parse(it.uriString)) }, + onLongClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + showMediaActionsFor = it + } + ), ) } } @@ -169,7 +173,7 @@ fun VideosListFromState( } } -@OptIn(ExperimentalMaterial3Api::class) +@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable fun FoldersListFromState( foldersState: FoldersState, @@ -191,11 +195,13 @@ fun FoldersListFromState( items(foldersState.data, key = { it.path }) { FolderItem( directory = it, - onClick = { onFolderClick(it.path) }, - onLongClick = { - haptic.performHapticFeedback(HapticFeedbackType.LongPress) - showDirectoryActionsFor = it - } + modifier = Modifier.combinedClickable( + onClick = { onFolderClick(it.path) }, + onLongClick = { + haptic.performHapticFeedback(HapticFeedbackType.LongPress) + showDirectoryActionsFor = it + } + ), ) } } @@ -274,7 +280,7 @@ fun DeleteDialogPreview() { subText = "The following files will be deleted permanently", onConfirm = { /*TODO*/ }, onCancel = { /*TODO*/ }, - fileNames = listOf("Harry potter 1","Harry potter 2","Harry potter 3","Harry potter 4") + fileNames = listOf("Harry potter 1", "Harry potter 2", "Harry potter 3", "Harry potter 4") ) } diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt index fd84192f8..97cdc05af 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt @@ -1,8 +1,6 @@ package dev.anilbeesetti.nextplayer.feature.videopicker.composables -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background -import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.ExperimentalLayoutApi @@ -32,13 +30,11 @@ import dev.anilbeesetti.nextplayer.core.ui.preview.DayNightPreview import dev.anilbeesetti.nextplayer.core.ui.preview.DevicePreviews import dev.anilbeesetti.nextplayer.core.ui.theme.NextPlayerTheme -@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class) +@OptIn(ExperimentalLayoutApi::class) @Composable fun VideoItem( video: Video, - modifier: Modifier = Modifier, - onClick: () -> Unit, - onLongClick: () -> Unit + modifier: Modifier = Modifier ) { ListItem( leadingContent = { @@ -103,10 +99,7 @@ fun VideoItem( } } }, - modifier = modifier.combinedClickable( - onClick = onClick, - onLongClick = onLongClick - ) + modifier = modifier ) } @@ -116,11 +109,7 @@ fun VideoItem( fun VideoItemPreview() { NextPlayerTheme { Surface { - VideoItem( - video = Video.sample, - onClick = {}, - onLongClick = {} - ) + VideoItem(video = Video.sample,) } } } From 4d3fe0f4fb55f305f01a07751f2acc6d006f6edc Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Wed, 2 Aug 2023 09:16:08 +0530 Subject: [PATCH 4/4] lint: run KtlintFormat --- .../feature/videopicker/composables/FolderItem.kt | 6 +++--- .../feature/videopicker/composables/MediaContent.kt | 5 ++--- .../nextplayer/feature/videopicker/composables/VideoItem.kt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt index 76ffbb8d7..bc4a00c0b 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/FolderItem.kt @@ -68,9 +68,9 @@ fun FolderItem( ) { InfoChip( text = "${directory.mediaCount} ${ - stringResource( - id = R.string.video.takeIf { directory.mediaCount == 1 } ?: R.string.videos - ) + stringResource( + id = R.string.video.takeIf { directory.mediaCount == 1 } ?: R.string.videos + ) }", modifier = Modifier.padding(vertical = 5.dp) ) diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt index f12eef496..6480c0dc1 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/MediaContent.kt @@ -116,7 +116,7 @@ fun VideosListFromState( haptic.performHapticFeedback(HapticFeedbackType.LongPress) showMediaActionsFor = it } - ), + ) ) } } @@ -201,7 +201,7 @@ fun FoldersListFromState( haptic.performHapticFeedback(HapticFeedbackType.LongPress) showDirectoryActionsFor = it } - ), + ) ) } } @@ -272,7 +272,6 @@ fun DeleteConfirmationDialog( ) } - @Preview @Composable fun DeleteDialogPreview() { diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt index 97cdc05af..5a757caf3 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt @@ -109,7 +109,7 @@ fun VideoItem( fun VideoItemPreview() { NextPlayerTheme { Surface { - VideoItem(video = Video.sample,) + VideoItem(video = Video.sample) } } }