Slackbot
04/16/2021, 8:47 PMDavid Martin
04/17/2021, 2:42 AMmax.cruz
04/17/2021, 6:11 PMprivate var _binding: ViewBinding? = null
private val binding get() = _binding!!
And I was wondering why this is better than just a lateinit property
(which, in my humble opinion, is more concise)
private lateinit var binding: ViewBinding
Or even if _binding
is going to be mutated to null, it would be better to use the language constructors to check the possibility. Am I missing something?A. Sachdeva
04/18/2021, 3:57 PMResource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them in switch case statements
. i found this article related to this issue : http://tools.android.com/tips/non-constant-fields . i usually use kotlin, but maintain some java projects. as a kotlin user, is it still okay to use when-else
blocks with resource ids? or would that be impacted too ?Colton Idle
04/18/2021, 9:08 PMdewildte
04/18/2021, 10:17 PMAssign responsibility to the class that has the information needed to fulfill it.This slack community has all the information experts. So it is natural for people to assign theirs questions to here. Fighting this behaviour is probably futile and also alienating to its members.
homeless
04/19/2021, 6:43 AMChetan Tuteja
04/19/2021, 7:09 AMHovhannes
04/19/2021, 7:26 AMval compFragment = CompFragment()
compFragment.arguments = bundle
requireFragmentManager().beginTransaction().replace(R.id.comp_item, compFragment)
.commit()
Andrean Firmansyah
04/19/2021, 9:07 AMHovhannes
04/19/2021, 11:06 AMval compFragment = CompFragment()
compFragment.arguments = bundle
requireFragmentManager().beginTransaction().replace(R.id.comp_item, compFragment)
.commit()
okarm
04/19/2021, 11:26 AMFarid Mrz
04/19/2021, 2:37 PMNikhil
04/20/2021, 5:38 AMParcelable
or Serializable
?hsyogesh
04/20/2021, 6:21 AMSivan
04/20/2021, 2:42 PMVaibhav Jaiswal
04/20/2021, 7:41 PMalex.tavella
04/21/2021, 7:11 PM[Flow + LiveData]
Hi, we have been adopting Flow
on our app and there are still some behaviors that we want to achieve that are a bit unclear. So, our presentation architecture basically consists on archictecture component’s ViewModel
producing state in a ViewState
class that has its properties exposed as LiveData
, which are observed by the View
layer. We have a case similar to the following:
internal class HomeViewModel constructor(
observeSessionAddress: GetSessionAddressFlowUseCase,
getHome: GetHomeUseCase,
) : ViewModel {
private val addressStream = observeSessionAddress()
.distinctUntilChanged()
.shareIn(viewModelScope, SharingStarted.Lazily, replay = 1)
private val homeStream = addressStream
.map { getHome(it.lat, it.lon) }
.shareIn(viewModelScope, SharingStarted.Lazily, replay = 1)
val viewState = HomeViewState(
addressStream.asLiveData(),
homeStream.asLiveData()
)
}
internal class HomeFragment : Fragment() {
...
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
...
with (viewModel.viewState) {
address.observe(viewLifecycleOwner, ::updateAddress)
home.observe(viewLifecycleOwner, ::updateHome)
}
}
}
The class GetSessionAddressFlowUseCase
returns a Flow
.
The code works fine, when Fragment is firstly created, it starts observing the address and fetches home content appropriately and also when navigating forward and getting back, we get the previous value without actually triggering getHome
again.
The only problem is: by using shareIn
I just made homeStream
and addressStream
hot flows, and after leaving HomeFragment
by navigating forward (we replace this fragment and keep in the backstack, so only onDestroyView
is called), the hot flow will still be live since HomeViewModel
is still alive and hence if we change address on another screen, the getHome
use case will still trigger. That may seem harmless at first, but if other devs start following this approach, we might trigger a bunch of expensive operations even if that info is not important to the user at that moment. One alternative is to keep these streams as cold, but after navigating back to the Fragment
would trigger getHome
again, which is an expensive operation, so that is out of the question.
Any ideas/suggestions?Shailan Patel
04/22/2021, 12:22 AMSlackbot
04/23/2021, 1:50 PMOrhan Tozan
04/23/2021, 2:33 PMOrhan Tozan
04/23/2021, 2:40 PMescodro
04/23/2021, 5:18 PMapply plugin: 'kotlin'
), do I have to setup anything for ProGuard/R8?
In other all modules, there is minifyEnabled
set to true
, but this setup is inside android
tag.
Thanks a lot in advance! ❤️am414
04/25/2021, 1:20 AMalert("We can't show your position because you generally disabled the location service for your device.") {
yesButton {
}
neutralPressed("Settings") {
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
}
}.show()
Sivan
04/25/2021, 1:17 PMSlackbot
04/25/2021, 3:28 PMcoroutinedispatcher
04/25/2021, 8:02 PMwith
keyword?
with(myFragmentBinding){
viewId.text = stateDataClass.name
viewId2.text = stateDataClass.lastName
viewId3.text = stateDataClass.phoneNumber
}
And I was thinking if there is any nice way of also not repeating the right part. Something like with(Pair(binding, modelClass))
doesn’t look pretty nice to me as it might look a little bit ugly and not intuitive (first.viewId.text = second.name
) which I don’t like. A nested with is also ugly IMO. Any opinions, thoughts?Slackbot
04/26/2021, 1:57 AMAndroid75
04/26/2021, 3:05 AM@GET("v2//news")
suspend fun news() : ApiResult<List<News>, ErrorResponse>
In this way i can't use Flow<ApiResult<List<News>, ErrorResponse>>
so can i use in repo?
fun getNews(): Flow<List<News>> {
return flow {
}
}
Mohan Babu Malairaj
04/26/2021, 6:45 AM