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

Refactor: Show permanently deleted message on delete confirmation dialog #481

Merged
merged 4 commits into from
Aug 2, 2023
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
3 changes: 2 additions & 1 deletion core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<string name="seconds">%1$s seconds</string>
<string name="share">Share</string>
<string name="delete">Delete</string>
<string name="delete_file">Delete the following file</string>
<string name="delete_file">The following file will be deleted permanently</string>
<string name="subtitle_text_encoding">Subtitle text encoding</string>
<string name="delete_folder">All video files in the following folder will be deleted permanently.</string>
</resources>
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -84,22 +80,15 @@ fun FolderItem(
)
}
},
modifier = modifier.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
)
modifier = modifier
)
}

@DayNightPreview
@Composable
fun FolderItemPreview() {
NextPlayerTheme {
FolderItem(
directory = Directory.sample,
onClick = { },
onLongClick = { }
)
FolderItem(directory = Directory.sample)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,6 +41,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
Expand Down Expand Up @@ -84,7 +87,7 @@ fun NoVideosFound() {
)
}

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun VideosListFromState(
videosState: VideosState,
Expand All @@ -107,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
}
)
)
}
}
Expand Down Expand Up @@ -157,17 +162,18 @@ fun VideosListFromState(

deleteAction?.let {
DeleteConfirmationDialog(
subText = stringResource(id = R.string.delete_file),
onCancel = { deleteAction = null },
onConfirm = {
onDeleteVideoClick(it.uriString)
deleteAction = null
},
deleteItems = listOf(it.nameWithExtension)
fileNames = listOf(it.nameWithExtension)
)
}
}

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun FoldersListFromState(
foldersState: FoldersState,
Expand All @@ -189,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
}
)
)
}
}
Expand All @@ -220,39 +228,61 @@ fun FoldersListFromState(

deleteAction?.let {
DeleteConfirmationDialog(
subText = stringResource(R.string.delete_folder),
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<String>
fileNames: List<String>,
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -103,10 +99,7 @@ fun VideoItem(
}
}
},
modifier = modifier.combinedClickable(
onClick = onClick,
onLongClick = onLongClick
)
modifier = modifier
)
}

Expand All @@ -116,11 +109,7 @@ fun VideoItem(
fun VideoItemPreview() {
NextPlayerTheme {
Surface {
VideoItem(
video = Video.sample,
onClick = {},
onLongClick = {}
)
VideoItem(video = Video.sample)
}
}
}