Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.linroid.ketch.app.platform

actual val isMobilePlatform: Boolean = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.linroid.ketch.app.platform

/**
* True on phone/tablet form factors (Android, iOS), false on desktop/web.
* Drives UI choices that should diverge by form factor (e.g. ModalBottomSheet
* vs AlertDialog).
*/
expect val isMobilePlatform: Boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.linroid.ketch.app.ui.common

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.ProvideTextStyle
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.linroid.ketch.app.platform.isMobilePlatform

/**
* A modal surface that adapts to the current platform: a [ModalBottomSheet] on
* phone/tablet form factors and an [AlertDialog] on desktop and web. Lets
* feature code declare a modal without branching on platform.
*
* On mobile, the bottom-sheet anchor avoids the dialog re-centering that makes
* `AlertDialog` jump when its content height changes with the soft keyboard up
* (see issue #135).
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AdaptiveModal(
onDismissRequest: () -> Unit,
confirmButton: @Composable () -> Unit,
modifier: Modifier = Modifier,
dismissButton: (@Composable () -> Unit)? = null,
title: (@Composable () -> Unit)? = null,
contentSpacing: Dp = 12.dp,
content: @Composable ColumnScope.() -> Unit,
) {
if (isMobilePlatform) {
val sheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = true,
)
ModalBottomSheet(
onDismissRequest = onDismissRequest,
sheetState = sheetState,
modifier = modifier,
) {
Column(
modifier = Modifier
.padding(horizontal = 24.dp)
.padding(bottom = 16.dp),
verticalArrangement = Arrangement.spacedBy(contentSpacing),
) {
if (title != null) {
ProvideTextStyle(MaterialTheme.typography.headlineSmall) {
title()
}
}
content()
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 4.dp),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically,
) {
if (dismissButton != null) {
dismissButton()
Spacer(Modifier.width(8.dp))
}
confirmButton()
}
}
}
} else {
AlertDialog(
onDismissRequest = onDismissRequest,
title = title,
text = {
Column(
verticalArrangement = Arrangement.spacedBy(contentSpacing),
content = content,
)
},
confirmButton = confirmButton,
dismissButton = dismissButton,
modifier = modifier,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.linroid.ketch.app.ui.common

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LowPriority
Expand Down Expand Up @@ -50,15 +51,17 @@ fun PriorityIcon(
}
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun PrioritySelector(
value: DownloadPriority,
onValueChange: (DownloadPriority) -> Unit,
modifier: Modifier = Modifier,
) {
Row(
FlowRow(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
DownloadPriority.entries.forEach { priority ->
FilterChip(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.linroid.ketch.app.ui.common

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Schedule
Expand Down Expand Up @@ -75,15 +76,17 @@ fun ScheduleIcon(
}
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun ScheduleSelector(
value: DownloadSchedule,
onValueChange: (DownloadSchedule) -> Unit,
modifier: Modifier = Modifier,
) {
Row(
FlowRow(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
scheduleOptions.forEach { option ->
FilterChip(
Expand All @@ -101,16 +104,18 @@ fun ScheduleSelector(
}
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun SchedulePanel(
task: DownloadTask,
scope: CoroutineScope,
onScheduled: () -> Unit,
modifier: Modifier = Modifier,
) {
Row(
FlowRow(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
scheduleOptions.forEach { option ->
FilterChip(
Expand Down
Loading
Loading