Ali
03/31/2022, 3:32 PMlam bui
04/01/2022, 7:48 AMprivate fun getListMedia(): List<EverfitMedia> {
return mediaAttachmentListNew.filterIsInstance<EverfitMedia>()
}
Hello everyone, I’m using filterIsInstance, it’s not working, pls help me, many thanks.Galou Minisini
04/01/2022, 12:55 PMHelpView
. The view is a custom view that extends FrameLayout
and LifecycleOwner
.
The view is sometimes being hidden, sometimes being shown. So it goes through the states onAttachedToWindow
and onDetachedFromWindow
where I set my life cycle state:
override fun onAttachedToWindow() {
super.onAttachedToWindow()
lifecycleRegistry.currentState = Lifecycle.State.RESUMED
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
}
From my init
in the view I am collection the uiState
, a StateFlow emited by my ViewModel.
viewModel.uiState.collectIn(this) { uiState ->
loaderManager.dismiss()
errorNetwork.isVisible = uiState is HelpViewModel.UiState.Error
when (uiState) {
is HelpViewModel.UiState.Loaded -> showContent(<http://uiState.help|uiState.help>)
HelpViewModel.UiState.Loading -> loaderManager.show(R.string.help_loading)
else -> return@collectIn
}
}
The collectIn
function is an extension function:
inline fun <T> Flow<T>.collectIn(
owner: LifecycleOwner,
crossinline onCollect: suspend (T) -> Unit
) = owner.lifecycleScope.launch { owner.repeatOnLifecycle(Lifecycle.State.STARTED) { collect { onCollect(it) } } }
My view is receiving correctly the new states at first but once it's hidden it stops collection the new uiState. My viewModel still emits some new state but the view seems to have stop subscribing to it or is not receiving it for some reason. Any idea why?Tolga ÇAĞLAYAN
04/02/2022, 10:13 AMAsad Mukhtar
04/02/2022, 8:24 PMScott Peterson
04/04/2022, 1:56 AMKevin
04/04/2022, 8:43 AMactivity_main.xml
in form of <com.test_project.library.buttons.TestButton/>
, it did works perfectly, but i found out that i cannot override the text value because the android:text
doesn't appear from suggestion.
is this because the effect from inflating the views? or there is something that missing from the custom views class that i didn't declare it first so i cannot put text value in activity_main.xml
?ildar.i [Android]
04/04/2022, 12:16 PMprivate var currentSearch: Job? = null
private val debounceDelayMs = 500L
private val _searchPagingFlow = MutableSharedFlow<PagingData<TaskModel>>()
override val searchPagingFlow: Flow<PagingData<TaskModel>> = _searchPagingFlow
override fun searchByText(text: String) {
currentSearch?.cancel()
currentSearch = ioThenMain({
delay(debounceDelayMs)
repository.searchTasks(text)
}) { pagingFlow ->
pagingFlow.collect {
_searchPagingFlow.emit(it)
}
}
}
but this approach won’t save current search items, because I’m using SharedFlow. What can I do here to make it work properly?lam bui
04/05/2022, 4:53 AMlawlorslaw
04/05/2022, 6:00 AMlocal.onErrorResumeNext { remote }
with coroutines?Tower Guidev2
04/05/2022, 2:29 PMRak
04/05/2022, 8:50 PMRahul Ray
04/06/2022, 12:41 PMalthaf
04/07/2022, 6:03 AMprivate fun getAmountLength(currency: CharSequence?, amount: CharSequence?): Int {
return when {
!currency.isNullOrEmpty() && !amount.isNullOrEmpty() -> currency.length + amount.length + 1
!amount.isNullOrEmpty() && currency.isNullOrEmpty() -> amount.length
amount.isNullOrEmpty() && !currency.isNullOrEmpty() -> currency.length
else -> 0
}
}
althaf
04/07/2022, 7:21 AMspannableAmount = SpannableString(buildString {
currency?.takeIf { it.isNotEmpty() }?.let { currency ->
currencyLength1 = currency.length
append("$currency")
}
amount?.takeIf { it.isNotEmpty() }?.let { amount ->
amountLength1 = currencyLength1 + amount.length
append(" $amount")
}
ratePercent?.takeIf { it.isNotEmpty() }?.let { rate ->
rateLength1 = amountLength1 + rate.length
append(" $ratePercent")
}
})
Mohammad Jahidul Islam
04/07/2022, 1:47 PMSam Stone
04/08/2022, 3:58 AMClassCastException: LinkedHashMap can't be cast to X
When using by lazy{X}
? I think this is the second time, though haven't had it in a while. Code:
class MyFragment : Fragment() {
private val foo by lazy { MyDialogFragment(params) }
fun myFun() {
foo.show()
}
}
Chethan
04/08/2022, 11:28 AMpaul vickers
04/09/2022, 12:34 PMtseisel
04/10/2022, 9:06 AMJean Patricio
04/11/2022, 1:52 PMBarry Fawthrop
04/11/2022, 2:36 PMGalou Minisini
04/11/2022, 11:40 PMjava.lang.IllegalArgumentException · parameter must be a descendant of this view
ViewGroup.java:7024 android.view.ViewGroup.offsetRectBetweenParentAndChild
ViewGroup.java:6946 android.view.ViewGroup.offsetDescendantRectToMyCoords
NestedScrollView.java:1445 androidx.core.widget.NestedScrollView.isWithinDeltaOfScreen
NestedScrollView.java:1999 androidx.core.widget.NestedScrollView.onSizeChanged
View.java:23959 android.view.View.sizeChange
View.java:23892 android.view.View.setFrame
View.java:23751 android.view.View.layout
ViewGroup.java:7277 android.view.ViewGroup.layout
LinearLayout.java:1829 android.widget.LinearLayout.setChildFrame
LinearLayout.java:1673 android.widget.LinearLayout.layoutVertical
LinearLayout.java:1582 android.widget.LinearLayout.onLayout
View.java:23754 android.view.View.layout
ViewGroup.java:7277 android.view.ViewGroup.layout
I have never been able to reproduce it so I have no idea where it is coming from. It always happen from the same screen. The screen is mostly composed of several fields that the user has to fill up. Most of those fields are EditText
but the users don't fill them directly. When they press on an EditText, a new activity is opened with a list os several items they can choose from once the select an item that new activity is closed, the user is sent back the form activity and the EditText is automatically filled in with the name of the item selected.
The error seems to often happen after selecting a couple of items this way. that's what I can see from the logs but I haven't find a way to reproduce it. It is only happening to some users and not all the time. Mostly happening on Samsung devices but I recently say some reports from pixel devices.
Any idea what could go wrong or how I could get more info to try to reproduce it?Adriano Celentano
04/12/2022, 9:39 AMAhmet Hasim Delibas
04/12/2022, 6:33 PMGalou Minisini
04/12/2022, 8:12 PMAndroid75
04/13/2022, 4:32 AMLukasz Kalnik
04/13/2022, 12:51 PMviewModelScope
to collect an endless Flow in my viewModel
. In my unit test I want to "destroy" the ViewModel in order for viewModelScope
to cancel the Flow collection. I'm calling viewModel.onCleared()
but it doesn't cancel the `viewModelScope`'s children jobs.
How can I make sure all coroutines started inside viewModelScope
are canceled before my test ends, so runTest
doesn't hang waiting for the coroutines to finish?Kyaw Linn Thant
04/13/2022, 2:29 PMLokesh Mudgal
04/14/2022, 10:00 AMLokesh Mudgal
04/14/2022, 10:00 AMgildor
04/14/2022, 10:03 AM