Alexander Suraphel
04/14/2022, 1:29 PMThis version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.0
But my root build.gradle
specifies ext.kotlin_version = '1.5.31'
. Am I missing something?Radoslaw Juszczyk
04/15/2022, 8:21 AMSharedFlow
(event is sent while the UI is not collecting).Joshua Akinsola
04/16/2022, 11:02 AMRemon Shehata
04/16/2022, 8:19 PMsealed class LoginResult {
object Success : LoginResult()
object WrongCredentials : LoginResult()
data class InvalidData(val error: ErrorType) : LoginResult()
}
sealed class ErrorType {
object EmptyEmail : ErrorType()
object InvalidEmailFormat : ErrorType()
object EmptyPassword : ErrorType()
}
how can I assert that I got the result of InvalidData
with the error of EmptyEmail
?Hiren Kuvadiya
04/17/2022, 5:42 AMLilly
04/17/2022, 11:56 AMfreeCompilerArgs += listOf()
("creates new list under the hood") and suggests to change it to freeCompilerArgs = freeCompilerArgs + listOf()
, I mean both create a new list?! Or does it warn because it's not obvious that a new list is created at first glance while the latter version is more explicit?Can Korkmaz
04/19/2022, 5:35 AM@Module
@InstallIn(SingletonComponent::class)
object DependencyModule {
@Singleton
@Provides
fun provideMoshi(): Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
@Singleton
@Provides
fun provideRetrofit(moshi: Moshi): BackendApi = Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl(Constants.BASE_URL)
.build()
.create(BackendApi::class.java)
}
Manikandan
04/19/2022, 2:18 PMAhmed Shehata
04/20/2022, 5:20 AM@Composable
fun HandlePagingError(
loadState: CombinedLoadStates, onNoInternet: @Composable () -> Unit = {},
onEmptyView: @Composable () -> Unit = {}
) {
when {
loadState.refresh is LoadState.Loading -> {
CircleLoading(loadingState = true, circleSize = 20.dp)
}
loadState.append is LoadState.NotLoading && loadState.append.endOfPaginationReached -> {
onEmptyView()
}
loadState.append is LoadState.Loading -> {
CircleLoading(loadingState = true, circleSize = 20.dp)
}
loadState.refresh is LoadState.Error -> {
// val e = loadState.append as LoadState.Error
onNoInternet()
}
loadState.append is LoadState.Error -> {
val e = loadState.append as LoadState.Error
val v = loadState.append.endOfPaginationReached
Log.i("HandlePagingError: ", v.toString())
val error = getNetworkErrorFromThrowable(e.error)
val messageError = when (error) {
is Result.NetworkError.Generic -> getErrorType(error.type)
Result.NetworkError.NoInternet -> stringResource(id = R.string.error_no_more_data)
}
TextUi(
modifier = Modifier.fillMaxWidth(),
text = messageError,
textAlign = TextAlign.Center
)
}
}
}Nandu
04/20/2022, 6:17 AMlam bui
04/20/2022, 9:17 AMval caption : String? = null
val caption : String? = ""
should I use option 1 or 2 to initialize a variable?
Colton Idle
04/20/2022, 11:31 PMval docRef = db.collection("cities").document("SF")
docRef.addSnapshotListener { snapshot, e ->
if (e != null) {
Log.w(TAG, "Listen failed.", e)
return@addSnapshotListener
}
if (snapshot != null && snapshot.exists()) {
Log.d(TAG, "Current data: ${snapshot.data}")
} else {
Log.d(TAG, "Current data: null")
}
}
How would you take this callback/listener and convert it into a main safe flowable?kuz
04/21/2022, 6:47 AMlam bui
04/21/2022, 8:11 AMfun main(args: Array<String>) {
val list = mutableListOf(
DemandLabel(
id = "1",
inputType = Constants.DemandLabelInputType.RADIO,
type = Constants.DemandLabelType.DEFAULT,
uniqueCode = "duration",
name = "duration",
items = listOf(
DemandLabelItem(
id = "1ab", name = "5 min"
), DemandLabelItem(
id = "123abc", name = "10 min"
)
)
),
DemandLabel(
id = "2",
inputType = Constants.DemandLabelInputType.RADIO,
type = Constants.DemandLabelType.DEFAULT,
uniqueCode = "level",
name = "level",
items = listOf(
DemandLabelItem(
id = "2ab", name = "Beginner"
), DemandLabelItem(
id = "2bc", name = "All"
)
)
),
DemandLabel(
id = "3",
inputType = Constants.DemandLabelInputType.RADIO,
type = Constants.DemandLabelType.DEFAULT,
uniqueCode = "Label 1",
name = "Label 1",
items = listOf(
DemandLabelItem(
id = "3abc", name = "Adductors"
), DemandLabelItem(
id = "3abcdeft", name = "Calves"
)
)
),
DemandLabel(
id = "4",
inputType = Constants.DemandLabelInputType.CHECKBOX,
type = Constants.DemandLabelType.CUSTOM,
uniqueCode = "Label 2",
name = "Label 2",
items = listOf(
DemandLabelItem(
id = "4abc", name = "Abdominals2"
), DemandLabelItem(
id = "4abcdef", name = "Arms2"
)
)
),
)
val mapOfList = list.associateBy({ it.name }, { it.items })
println(mapOfList)
val changed = list.groupBy (
{ it.name },
{it.items.forEach { it.id }} )
println(changed)
}
Lilly
04/21/2022, 10:29 AMfun someFunction(): Flow<Pair<Int, SomeStateType>>
Would you
1. define a data class and create a new object on every change (this might happen 100x). Disadvantage: object creation on every change, advantage: state is coupled to its function
2. expose 2 observable StateFlows
. Disadvantage: pollutes interface API, advantage: no object creation on every change
Is there any guidance about this or is this an issue of preference?hfhbd
04/21/2022, 2:09 PMDavid Corrado
04/21/2022, 3:16 PMfun <T> Result<T>.toDataState(): DataState<T> {
onFailure {
return DataState.failure()
}.onSuccess {
return DataState.success(it)
}
}
But you can not because onFailure and onSuccess is not exhaustive. How have you done this?Vivek Modi
04/21/2022, 9:04 PMclass AuthorizationInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
// more code
return AuthorizationHeader(chain, accessToken)
}
private fun AuthorizationHeader(chain: Interceptor.Chain, accessToken: String): Response = synchronized(this) {
val api = refreshApiCall() // this api call is not working
return initialResponse
}
}
Nurbanu Kahraman
04/21/2022, 9:20 PMZoltan Demant
04/22/2022, 6:09 AMVivek Modi
04/22/2022, 9:29 AMprivate fun getMonthValue(subscription: VariantDetail, context: Context): String {
return when (subscription.valueInInt) {
0 -> ""
1 -> {
when ((UnitOfMeasurement.fromType(subscription.unitOfMeasurement))) {
MONTH -> context.getString(R.string.singular_month)
DAY -> context.getString(R.string.singular_day)
WEEK -> context.getString(R.string.singular_week)
QUARTERLY,
DOSE,
NONE -> ""
}
}
else -> {
when ((UnitOfMeasurement.fromType(subscription.unitOfMeasurement))) {
MONTH -> {
context.getString(
R.string.month_text,
subscription.value,
context.getString(R.string.plural_month)
)
}
DAY -> {
context.getString(
R.string.month_text,
subscription.value,
context.getString(R.string.plural_day)
)
}
WEEK -> {
context.getString(
R.string.month_text,
subscription.value,
context.getString(R.string.plural_week)
)
}
QUARTERLY,
DOSE,
NONE -> ""
}
}
}
}
Chaiwa Berian
04/22/2022, 11:56 AMqualified this
but I am trying to wrap my brains around this syntax right here:
Observer { loginFormState ->
if (loginFormState == null) {
return@Observer
}
loginButton.isEnabled = loginFormState.isDataValid
loginFormState.usernameError?.let {
usernameEditText.error = getString(it)
}
loginFormState.passwordError?.let {
passwordEditText.error = getString(it)
}
})
I understand the rest of the code except what is happening here:
if (loginFormState == null) {
return@Observer
}
What would be the interpretation of what return@Observer
mean? Semantics?Slackbot
04/24/2022, 9:55 AMwck
04/26/2022, 7:01 AMFunction References of @Composable functions are not currently supported
althaf
04/27/2022, 11:47 AMprivate val onLiveFxRateResult: LiveData<Result<List<FundingAccountWithCcyPair>>> =
Transformations.switchMap(onLiveFxRateRequested) {
it.forEach {
getFundingAccountsWithCcyPairsUseCase.execute(it.accountCountryCode)
}
}
Simon Stahl
04/27/2022, 9:04 PMMutableSharedFlow
as an app wide event bus for a reactive architecture. Does anything speak against it? Does it stay stable if the app is kept open all day long and is repeatedly put into foreground/background?Julia Samól
04/28/2022, 10:50 AMinterface I
@JvmInline
value class A(val instance: I) : I by instance // Error: Value class cannot implement an interface by delegation if expression is not a parameter
and I’m wondering whether value classes lack that feature or I’m the one missing something herealthaf
04/28/2022, 11:31 AMval index = liveFxRates.indexOfFirst { result.data.isCurrencyPairEqual(fxLiveRateGainLoss = it) }
if(index > -1) {
liveFxRates.removeAt(index)
liveFxRates.add(index, liveFxRates[index].copy(buyValue = "-", sellValue = "-"))
}
Pablo
04/28/2022, 3:15 PMlawlorslaw
04/29/2022, 6:26 PMflatmap()
or some functional operator, without having to introduce Kotlin Flows?
viewModelScope.launch {
val api = NetworkService().api
val ordersResponse = api.fetchOrdersCoroutine()
val deliveryItems = mutableListOf<DeliveryItem>()
ordersResponse.orders.forEach { orderId ->
val orderResponse = api.fetchOrderByIdCoroutine(orderId)
deliveryItems.addAll(orderResponse.items)
}
}