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
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
Expand Down Expand Up @@ -181,19 +180,14 @@ fun HistoryScreen() {
) {
items(historyItems, key = { it.id }) { item ->
val dismissState = rememberSwipeToDismissBoxState(
confirmValueChange = { value ->
if (value == SwipeToDismissBoxValue.EndToStart) {
historyViewModel.deleteItem(item.id)
true
} else {
false
}
},
positionalThreshold = { totalDistance -> totalDistance * 0.5f }
positionalThreshold = { totalDistance -> totalDistance * 0.75f }
)

SwipeToDismissBox(
state = dismissState,
onDismiss = {
historyViewModel.deleteItem(item.id)
},
backgroundContent = {
Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.LoadingIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -55,7 +56,10 @@ fun ProductDetailSheet(
isLoading: Boolean,
onDismiss: () -> Unit
) {
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val sheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)

ModalBottomSheet(
onDismissRequest = onDismiss,
Expand Down Expand Up @@ -159,15 +163,19 @@ private fun ProductContent(product: ProductInfo) {
ProductCategory.FOOD, ProductCategory.PET_FOOD -> {
product.foodData?.let { FoodContentSection(it) }
}

ProductCategory.BOOK -> {
product.bookData?.let { BookContentSection(it) }
}

ProductCategory.MEDICINE -> {
product.medicineData?.let { MedicineContentSection(it) }
}

ProductCategory.COSMETICS -> {
product.cosmeticsData?.let { CosmeticsContentSection(it) }
}

ProductCategory.GENERIC -> {
product.description?.let {
Text(it, style = MaterialTheme.typography.bodyMedium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import androidx.compose.material3.LinearWavyProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -38,8 +38,11 @@
modifier: Modifier = Modifier,
adAvailable: Boolean = false,
onWatchAd: (() -> Unit)? = null,
sheetState: SheetState = rememberModalBottomSheetState()
) {
val sheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)
val targetProgress = 1f - (remainingSeconds.toFloat() / RATE_LIMIT_SECONDS)
val animatedProgress by animateFloatAsState(
targetValue = targetProgress,
Expand Down Expand Up @@ -73,8 +76,8 @@

Text(
text = "Scanly's AI runs on the developer's free-tier keys — shared " +
"across Gemini, Mistral OCR, OpenRouter and Hugging Face — " +
"so scans pause for a moment when they get busy.",
"across Gemini, Mistral OCR, OpenRouter and Hugging Face — " +

Check warning

Code scanning / detekt

Unexpected indentation (24) (should be 20) Warning

Unexpected indentation (24) (should be 20)
"so scans pause for a moment when they get busy.",

Check warning

Code scanning / detekt

Unexpected indentation (24) (should be 20) Warning

Unexpected indentation (24) (should be 20)
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
Expand All @@ -84,8 +87,8 @@

Text(
text = "Add your own key for any provider in Settings → AI Providers to " +
"remove this limit entirely. Even a free tier works — it just runs " +
"on your quota instead of the shared one.",
"remove this limit entirely. Even a free tier works — it just runs " +

Check warning

Code scanning / detekt

Unexpected indentation (24) (should be 20) Warning

Unexpected indentation (24) (should be 20)
"on your quota instead of the shared one.",

Check warning

Code scanning / detekt

Unexpected indentation (24) (should be 20) Warning

Unexpected indentation (24) (should be 20)
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
Expand Down Expand Up @@ -95,8 +96,14 @@ fun BarcodeScannerScreen(
var showActionsSheet by remember { mutableStateOf(false) }
var textToShow by remember { mutableStateOf<String?>(null) }
var isProcessingGallery by remember { mutableStateOf(false) }
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val textSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val sheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)
val textSheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)

var showProductSheet by remember { mutableStateOf(false) }
var lookupResult by remember { mutableStateOf<LookupResult?>(null) }
Expand Down Expand Up @@ -218,7 +225,12 @@ fun BarcodeScannerScreen(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(Icons.Rounded.PhotoLibrary, null, tint = Color.White, modifier = Modifier.size(18.dp))
Icon(
Icons.Rounded.PhotoLibrary,
null,
tint = Color.White,
modifier = Modifier.size(18.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text(
text = if (isProcessingGallery) "Scanning..." else "Upload from gallery",
Expand Down Expand Up @@ -269,9 +281,11 @@ fun BarcodeScannerScreen(
showActionsSheet = false
textToShow = action.text
}

is ScanAction.LookupProduct -> {
lookupProduct(action.barcode)
}

else -> {
showActionsSheet = false
ActionExecutor.execute(context, action)
Expand All @@ -290,7 +304,8 @@ fun BarcodeScannerScreen(
TextDetailSheet(
text = text,
onCopy = {
val clipboard = context.getSystemService(android.content.ClipboardManager::class.java)
val clipboard =
context.getSystemService(android.content.ClipboardManager::class.java)
clipboard.setPrimaryClip(ClipData.newPlainText("Barcode Content", text))
Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show()
},
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/com/skeler/scanely/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetValue
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -55,7 +56,6 @@ import com.skeler.scanely.ui.components.rememberMultiGalleryPicker
import com.skeler.scanely.ui.viewmodel.AiScanViewModel
import com.skeler.scanely.ui.viewmodel.OcrViewModel
import com.skeler.scanely.ui.viewmodel.UnifiedScanViewModel
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -70,7 +70,10 @@ fun HomeScreen() {

val snackbarHostState = remember { SnackbarHostState() }
var showAiBottomSheet by remember { mutableStateOf(false) }
val aiSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
val aiSheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)
var pendingAiMode by remember { mutableStateOf<AiMode?>(null) }
var pendingAiProvider by remember { mutableStateOf(AiProvider.DEFAULT) }

Expand Down Expand Up @@ -107,7 +110,8 @@ fun HomeScreen() {
uri,
android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
)
} catch (_: Exception) { }
} catch (_: Exception) {
}
if (scanViewModel.triggerAiWithRateLimit(provider) {
scanViewModel.onNewScanSelected()
aiViewModel.processMultipleFiles(listOf(uri), mode, provider)
Expand Down Expand Up @@ -137,7 +141,8 @@ fun HomeScreen() {
uri,
android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
)
} catch (_: Exception) { }
} catch (_: Exception) {
}
aiViewModel.clearResult()
ocrViewModel.clearResult()
scanViewModel.onNewScanSelected()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetValue
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.material3.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -504,7 +505,11 @@ private fun ExportBar(enabled: Boolean, onClick: () -> Unit) {
.height(60.dp),
shape = CircleShape
) {
Icon(Icons.Rounded.IosShare, contentDescription = null, modifier = Modifier.size(20.dp))
Icon(
Icons.Rounded.IosShare,
contentDescription = null,
modifier = Modifier.size(20.dp)
)
Spacer(Modifier.size(10.dp))
Text(
"Save or share",
Expand Down Expand Up @@ -532,9 +537,14 @@ private fun ExportSheet(
) {
val pageLabel = "$pageCount page${if (pageCount > 1) "s" else ""}"

val sheetState = rememberBottomSheetState(
initialValue = SheetValue.Hidden,
enabledValues = setOf(SheetValue.Hidden, SheetValue.Expanded)
)

ModalBottomSheet(
onDismissRequest = onDismiss,
sheetState = rememberModalBottomSheetState()
sheetState = sheetState
) {
Column(
modifier = Modifier
Expand Down
Loading