pr sample 1

pull/1925/head
ibartishvili 2 months ago
parent b36a3ba564
commit 91fa3d881b

@ -22,8 +22,8 @@ import androidx.compose.ui.tooling.preview.Preview
* Multipreview annotation that represents various device sizes. Add this annotation to a composable * Multipreview annotation that represents various device sizes. Add this annotation to a composable
* to render various devices. * to render various devices.
*/ */
@Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480") @Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480", showBackground = true)
@Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480") @Preview(name = "landscape", device = "spec:shape=Normal,width=640,height=360,unit=dp,dpi=480", showBackground = true)
@Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480") @Preview(name = "foldable", device = "spec:shape=Normal,width=673,height=841,unit=dp,dpi=480", showBackground = true)
@Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480") @Preview(name = "tablet", device = "spec:shape=Normal,width=1280,height=800,unit=dp,dpi=480", showBackground = true)
annotation class DevicePreviews annotation class DevicePreviews

@ -0,0 +1,29 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.feature.foryou
abstract class ValidatorWithErrorType<ParamType : Any, ReturnType : Any, Error : Any> {
fun validate(data: ParamType): ValidatorResult<ReturnType, Error> {
return doValidation(data)
}
protected abstract fun doValidation(data: ParamType): ValidatorResult<ReturnType, Error>
sealed class ValidatorResult<out Success : Any, out Error : Any> {
data class Success<out ReturnType : Any>(val data: ReturnType) : ValidatorResult<ReturnType, Nothing>()
data class Failure<out Error : Any>(val error: Error) : ValidatorResult<Nothing, Error>()
}
}

@ -0,0 +1,67 @@
package com.google.samples.apps.nowinandroid.feature.foryou
import androidx.annotation.StringRes
import java.io.Serializable
import javax.inject.Inject
abstract class AddMobileTopUpTemplateValidator : ValidatorWithErrorType<
AddMobileTopUpTemplateValidator.Params,
AddMobileTopUpTemplateValidator.Params,
AddMobileTopUpTemplateValidator.Error
>() {
data class Params(
val mobileNumber: String?,
val serviceProvider: MTUServiceProviderFace?,
val paymentService: MTUPaymentServiceFace?,
val isAllDataRequired: Boolean? = null
)
data class Error(
@StringRes var emptyMobileNumber: Int? = null,
@StringRes var emptyServiceProvider: Int? = null,
@StringRes var emptyPaymentService: Int? = null,
)
}
class AddMobileTopUpTemplateValidatorImpl @Inject constructor() : AddMobileTopUpTemplateValidator() {
override fun doValidation(data: Params): ValidatorResult<Params, Error> {
var isValid = true
val error = Error()
if (data.mobileNumber.isNullOrEmpty()) {
error.emptyMobileNumber = R.string.feature_foryou_done
isValid = false
}
if (data.serviceProvider == null && data.isAllDataRequired == true) {
error.emptyServiceProvider = R.string.feature_foryou_done
isValid = false
}
if (data.paymentService == null && data.isAllDataRequired == true) {
error.emptyPaymentService = R.string.feature_foryou_done
isValid = false
}
return if (isValid) {
ValidatorResult.Success(data)
} else {
ValidatorResult.Failure(error)
}
}
}
data class MTUServiceProviderFace(
val id: Long,
val name: String,
val shortName: String
) : Serializable
data class MTUPaymentServiceFace(
val id: Long,
val name: String,
val isMobilePackage: Boolean,
val allowedPaymentAmount: Long?,
val packageDescriptions: Map<String, String>?,
val serviceProvider: MTUServiceProviderFace? = null
) : Serializable

@ -549,7 +549,7 @@ private fun SearchTextField(
} }
} }
@Preview @Preview(showBackground = true)
@Composable @Composable
private fun SearchToolbarPreview() { private fun SearchToolbarPreview() {
NiaTheme { NiaTheme {
@ -562,7 +562,7 @@ private fun SearchToolbarPreview() {
} }
} }
@Preview @Preview(showBackground = true)
@Composable @Composable
private fun EmptySearchResultColumnPreview() { private fun EmptySearchResultColumnPreview() {
NiaTheme { NiaTheme {
@ -573,7 +573,7 @@ private fun EmptySearchResultColumnPreview() {
} }
} }
@Preview @Preview(showBackground = true)
@Composable @Composable
private fun RecentSearchesBodyPreview() { private fun RecentSearchesBodyPreview() {
NiaTheme { NiaTheme {
@ -585,7 +585,7 @@ private fun RecentSearchesBodyPreview() {
} }
} }
@Preview @Preview(showBackground = true)
@Composable @Composable
private fun SearchNotReadyBodyPreview() { private fun SearchNotReadyBodyPreview() {
NiaTheme { NiaTheme {

Loading…
Cancel
Save