Brian Dilley
04/06/2021, 12:26 AMdestination.filterKeys { key ->
key in (list1 + list2 + list3)
}
Brian Dilley
04/06/2021, 12:27 AMLilly
04/06/2021, 12:33 AMwhen
:
destination.filterKeys { key ->
when (key) {
in list1, list2, list3 -> true
else -> false
}
}
I'm fine with this, if no one else has a more convenient solutionSlackbot
04/06/2021, 4:37 AMSaket Poddar
04/06/2021, 3:29 PMlateinit var sampleString: String
, will it be initialised with null or will remain uninitialised ?Susheel
04/06/2021, 4:41 PMLilly
04/07/2021, 2:01 AMinterfaces
and sealed classes
and noticed that both can be used to achieve the same. For example:
Profile.kt
interface Profile
AProfile.kt
class AProfile : Profile { }
BProfile.kt
class BProfile : Profile { }
With sealed class:
Profile.kt
sealed class Profile
class AProfile : Profile()
class BProfile : Profile()
Now I'm wondering what are the reasons to prefer one over the other?rkeazor
04/07/2021, 3:47 PMVyshas
04/08/2021, 7:17 AMJavier
04/08/2021, 12:31 PMvar onTextChanged: ((text: String) -> Unit)? = null
but when I do onTextChanged = { ... }
, there is an inference issue where it detects the String
as Any
. How can I solve this problem?Geert
04/08/2021, 2:10 PMTiago Nunes
04/08/2021, 4:35 PMprivate val refreshJob = filterFlow
.onEach { prev, new ->
if(prev.x != new.x) {
updateX()
}
}
.launchIn(viewModelScope)
I know I can separate the filterFlow in multiple flows, which is probably the better way of solving my use case, but I'm still curiousBradleycorn
04/08/2021, 9:48 PMNavigation Component
and a ViewModel scoped to a nav graph ... I'm removing a few places in my app where I was using onActivityCreated
in some fragments, since that callback is deprecated. I've been able to move most everything related to view work into onViewCreated
, but I have a problem there because I need to do a few things with a nav graph scoped ViewModel. The problem is that when the containing activity is recreated (due to a configuration change, or process death, etc) the onViewCreated
gets called before the containing Activity's onCreate
is finished (in fact, it gets called as soon as the activity's onCreate
is called). As a result, the Nav Graph has not been setup yet, and so it can't properly create the ViewModel that is scoped to the graph, and the app crashes.
What's the path forward here? Per the deprecation notice in the docs for onActivityCreated
, in the fragment's onAttach
we should register a LifecycleObserver on the activity, observe for on_create
and do work there. But that dooesn't work for me either. One of the things I need to do with the ViewModel is observe a LiveData, and the viewLifecycleOwner
is not yet available (it's not available until the Fragment's onCreate
) ...
the problem I'm running into is that after a configuration change, the Activity's onCreate and the Frgment's onViewCreated are executed in parallel, as illustrated by @ppvi in this article: https://medium.com/androiddevelopers/the-android-lifecycle-cheat-sheet-part-iii-fragments-afc87d4f37fd#4e7a . As outlined there, the benefit of onActivityCreated is that it is guaranteed to be called AFTER the Activity's onCreate
is finished.Mohan Babu Malairaj
04/09/2021, 3:33 AMHazem Muhammad
04/09/2021, 7:58 AMubu
04/09/2021, 12:25 PMclass SomeWidget : ConstraintLayout {
constructor(
context: Context
) : this(context, null) {
}
constructor(
context: Context,
attrs: AttributeSet?
) : this(context, attrs, 0) {
}
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr) {
inflate()
}
fun addSubviews() {
val views = mutableListOf<View>()
repeat(2) { count ->
views.add(
TextView(context).apply {
text = "Test $count"
setBackgroundResource(R.drawable.rectangle_debug)
}
)
}
views.forEach {
addView(it)
}
flow.apply {
//setWrapMode(Flow.WRAP_CHAIN)
}
flow.referencedIds = views.map { it.id }.toIntArray()
post { requestLayout() }
}
private fun inflate() {
LayoutInflater.from(context).inflate(R.layout.widget_featured_relation, this)
}
}
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:app="<http://schemas.android.com/apk/res-auto>">
<androidx.constraintlayout.helper.widget.Flow
android:id="@+id/flow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</merge>
I am totally missing something. Could someone explain to me why this custom view is rendered this way:Umar Ata
04/09/2021, 6:35 PMoverride fun onDestroyView() {
super.onDestroyView()
_binding = null
}
Does the garbage collection type thing not works with viewbindig ?
Or I am on wrong track
Please adviseFlorian
04/10/2021, 4:04 PMfun getHumanReadableName(context: Context) =
context.getString(
when (this) {
POMODORO -> R.string.pomodoro
SHORT_BREAK -> R.string.short_break
LONG_BREAK -> R.string.long_break
}
)
Mjahangiry75
04/11/2021, 8:57 AMMuhammed Dag
04/11/2021, 12:47 PMSlackbot
04/12/2021, 8:07 AMAndré Thiele
04/12/2021, 8:13 AMAndroid75
04/14/2021, 3:03 AMopen class BaseViewModel<State : Any, Event : Any> : ViewModel() {
private val stateLiveData: MutableLiveData<State> = MutableLiveData()
and now with StateFlow:
open class BaseFlowViewModel<State : Any, Event : Any> : ViewModel() {
private val _uiState = MutableStateFlow<State>()
val uiState: StateFlow<State> = _uiState
MutableStateFlow<State>() wants a parameter... what can i put as paramter?Nikhil
04/14/2021, 4:45 AMListAdapter
and RecyclerView.Adapter
?Slackbot
04/14/2021, 8:03 AMmissguru
04/14/2021, 10:53 AMalex.tavella
04/14/2021, 9:25 PMelye
04/15/2021, 12:52 PMIfvwm
04/16/2021, 5:51 AMjd07
04/16/2021, 6:41 AMjd07
04/16/2021, 6:41 AMPavel Sidyakin
04/16/2021, 7:07 AMArsalImam
04/16/2021, 6:03 PMenighma
04/16/2021, 6:49 PMjd07
04/20/2021, 11:37 AM