compose: details: Show error on entering non-digit characters for manual download
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -17,6 +17,8 @@ import androidx.compose.material3.Button
|
|||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.SnackbarHost
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
|
||||||
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
||||||
@@ -25,6 +27,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
@@ -53,6 +56,7 @@ import com.aurora.store.compose.composables.TopAppBarComposable
|
|||||||
import com.aurora.store.compose.preview.AppPreviewProvider
|
import com.aurora.store.compose.preview.AppPreviewProvider
|
||||||
import com.aurora.store.viewmodel.details.AppDetailsViewModel
|
import com.aurora.store.viewmodel.details.AppDetailsViewModel
|
||||||
import kotlinx.coroutines.android.awaitFrame
|
import kotlinx.coroutines.android.awaitFrame
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ManualDownloadScreen(
|
fun ManualDownloadScreen(
|
||||||
@@ -102,6 +106,10 @@ private fun ScreenContent(
|
|||||||
windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo()
|
windowAdaptiveInfo: WindowAdaptiveInfo = currentWindowAdaptiveInfo()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
val snackBarHostState = remember { SnackbarHostState() }
|
||||||
|
val errorMessage = stringResource(R.string.manual_download_version_error)
|
||||||
|
|
||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
var versionCode by remember {
|
var versionCode by remember {
|
||||||
val initText = currentVersionCode.toString()
|
val initText = currentVersionCode.toString()
|
||||||
@@ -120,7 +128,8 @@ private fun ScreenContent(
|
|||||||
navigationIcon = windowAdaptiveInfo.adaptiveNavigationIcon,
|
navigationIcon = windowAdaptiveInfo.adaptiveNavigationIcon,
|
||||||
onNavigateUp = onNavigateUp
|
onNavigateUp = onNavigateUp
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
snackbarHost = { SnackbarHost(hostState = snackBarHostState) }
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -142,7 +151,13 @@ private fun ScreenContent(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.focusRequester(focusRequester),
|
.focusRequester(focusRequester),
|
||||||
value = versionCode,
|
value = versionCode,
|
||||||
onValueChange = { if (it.text.isDigitsOnly()) versionCode = it },
|
onValueChange = {
|
||||||
|
if (it.text.isDigitsOnly()) {
|
||||||
|
versionCode = it
|
||||||
|
} else {
|
||||||
|
coroutineScope.launch { snackBarHostState.showSnackbar(errorMessage) }
|
||||||
|
}
|
||||||
|
},
|
||||||
shape = RoundedCornerShape(10.dp),
|
shape = RoundedCornerShape(10.dp),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
|
|||||||
@@ -394,6 +394,7 @@
|
|||||||
|
|
||||||
<!-- ManualDownloadSheet -->
|
<!-- ManualDownloadSheet -->
|
||||||
<string name="manual_download_hint">Enter version code you wish to download</string>
|
<string name="manual_download_hint">Enter version code you wish to download</string>
|
||||||
|
<string name="manual_download_version_error">Version code can only contain digits</string>
|
||||||
|
|
||||||
<!-- WelcomeFragment -->
|
<!-- WelcomeFragment -->
|
||||||
<string name="faqs_title" translatable="false">FAQs</string>
|
<string name="faqs_title" translatable="false">FAQs</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user