Skip to content

Commit

Permalink
🚀 disable empty string search, scanner validation fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fikrihandy committed Dec 15, 2023
1 parent 02af8fd commit 5e3ca8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCmR6EH3XkpW8VYFpVGhlxImlBv4yrNEuE" />
android:value="YOUR_API" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ fun HomeScreen(
getRecommendation = { viewModel.getAllRecommendation() },
imageVisible = !landscape,
onSearch = {
viewModel.getAllProducts(keyword = it)
title = "Hasil pencarian: \"$it\""
searchKeyword = it
if (it.isNotEmpty()) {
viewModel.getAllProducts(keyword = it)
title = "Hasil pencarian: \"$it\""
searchKeyword = it
}
},
onClickScanner = { navController.navigate(Screen.App.Scanner.route) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package academy.bangkit.trackmate.view.app.scanner
import academy.bangkit.trackmate.R
import academy.bangkit.trackmate.navigation.Screen
import academy.bangkit.trackmate.view.showToast
import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -30,13 +31,21 @@ fun ScannerScreen(navController: NavController) {

LaunchedEffect(qrCodeToString) {
if (qrCodeToString != null) {

// TODO: sebelum navigasi ke detail screen lakukan validasi

navController.navigate(Screen.App.Detail.createRoute(qrCodeToString as String)) {
popUpTo(Screen.App.Scanner.route) {
inclusive = true
try {
val webUrl = qrCodeToString as String
val prefix = "web-app-five-beta.vercel.app/product/"
if (webUrl.startsWith(prefix)) {
val productId = webUrl.removePrefix(prefix)
navController.navigate(Screen.App.Detail.createRoute(productId)) {
popUpTo(Screen.App.Scanner.route) {
inclusive = true
}
}
} else {
scannerError(context, navController)
}
} catch (e: Exception) {
scannerError(context, navController)
}
} else {
val options = GmsBarcodeScannerOptions.Builder()
Expand Down Expand Up @@ -71,4 +80,12 @@ fun ScannerScreen(navController: NavController) {
}
}
}
}

private fun scannerError(
context: Context,
navController: NavController
) {
showToast(context, "QR code tidak diketahui")
navController.navigateUp()
}

0 comments on commit 5e3ca8d

Please sign in to comment.