Shivam Dhuria
03/18/2022, 9:05 PMdebounce
on a flow from within a Composable. I get this warning
Flow operator functions should not be invoked within composition . I am not using Viewmodels so can’t run the flow operator in the VM. Ideally I’d just want to call debounce
on the fullNameFlow
and trigger some changes in the composable. What’s the best way to go forward?
//This is inside a Composable
val fullNameFlow = MutableStateFlow("")
fullNameFlow.debounce(3000).mapLatest {
Log.i(TAG,it)
//Change Composable State
}
FormTextField(
onValueChange = {
fullNameFlow.value = it
}
)
Conrad Kramer
03/21/2022, 12:56 AM@Preview
?Android75
03/21/2022, 7:02 AMcustomScope.launch{
action1()
action2()
i’d like launch in parallel and when 2 methods end your action i have to invoke a methodNicolai
03/21/2022, 10:06 AMabstract class OnboardingBaseViewModel(
private val postNotificationSchemeUseCase: PostNotificationSchemeUseCase,
private val putUserPropertyUseCase: PutUserPropertyUseCase
) : ViewModel() {
// Data that needs to be shared
val _customOptionItems = MutableLiveData<List<CustomOptionItem>>()
val customOptionItems = _customOptionItems
}
Upon my init function in VM1 I want to access the data already set from VM2 however it's null.
VM2 is created like this:
@HiltViewModel
class RemindersTimeViewModel @Inject constructor(
postNotificationSchemeUseCase: PostNotificationSchemeUseCase,
putUserPropertyUseCase: PutUserPropertyUseCase
) : OnboardingBaseViewModel(postNotificationSchemeUseCase, putUserPropertyUseCase)
{
init{
// this is null - but why?
val data = customOptionsItems.value
}
}
I inject the viewmodels into the fragments with Hilt like so:
private val viewModel: RemindersViewModel by activityViewModels()
Slackbot
03/21/2022, 12:31 PMViktor Vostrikov
03/21/2022, 2:51 PMandodeki
03/21/2022, 10:11 PMcomposable(route = Screen.GetQuote.route) { navBackStackEntry ->
val factory = HiltViewModelFactory(LocalContext.current, navBackStackEntry)
val viewModel: GetQuoteListViewModel = viewModel("GetQuoteListViewModel", factory)
// val viewModel: GetQuoteListViewModel = viewModel()
GetQuoteScreen(
state = viewModel.state.value,
onClickHome = {
navController.navigate("${Screen.Home.route}")
},
)
}
Chethan
03/22/2022, 4:22 AMdisplayCardList.filter { it.targetGrades?.contains(userGrade) == true }.run {
return this.toMutableList().also {
it.add(
AmbientCardInfo(
id = System.currentTimeMillis().toString(),
cardType = CardType.GREETING.value,
targetGrades = String.EMPTY
)
)
}
}
V/S
return displayCardList
.filter { it.targetGrades?.contains(userGrade) == true }
.toMutableList()
.also {
it.add(
AmbientCardInfo(
id = System.currentTimeMillis().toString(),
cardType = CardType.GREETING.value,
targetGrades = String.EMPTY
)
)
}
azabost
03/22/2022, 8:07 AMbuildSrc
directory so I’m skipping that part. In the end, what I’m calling (or at least I should be calling) is simply:
android {
val javaVersion: JavaVersion = JavaVersion.VERSION_11
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}
Nevertheless, I’m still seeing a lot of build warnings:
'compileJava' task (current target is 11) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
Does anyone have any idea if I’m doing something wrong?the great warrior
03/22/2022, 8:56 PMfun checkNewItemAdded(item: PlaceItem) {
viewModelScope.launch {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
val newItemAdded = async { getPlaceItem(item.id) }
val placeItem = newItemAdded.await()
placeItem?.let {
if (!it.isChecked) {
it.isChecked = true
val checkNewItem = async { update(it) }
checkNewItem.await()
val getAllPlaces = async { getPlaces() }
val places = getAllPlaces.await()
val runningTasks = places.map { place ->
async {
val singlePlaceItem = getPlaceItem(place.id)
place to singlePlaceItem
}
}
val responses = runningTasks.awaitAll()
responses.forEach { (place, response) ->
if (response != placeItem) {
places.find { it.id == place.id }?.isChecked = false
update(place)
}
}
}
}
}
}
}
Ryli Davis
03/22/2022, 11:23 PMpackage com.example.animod
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.apollographql.apollo3.api.Optional
import com.example.aniMod.CharacterQuery
import com.example.animod.databinding.FragmentFirstBinding
/**
* A simple [Fragment] subclass as the default destination in the navigation.
*/
class FirstFragment : Fragment() {
var _binding: FragmentFirstBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentFirstBinding.inflate(inflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
lifecycleScope.launchWhenResumed {
val response = apolloClient.query(CharacterQuery(search = Optional.Present<String>(""))).execute()
Log.d("Anime Character Picture", "Success ${response.data}")
}
}
}
And this is my PictureQuery.kt file
query Character($search: String) {
person: Character(search: $search) {
image {
large
}
}
}
I appreciate any help . Thank youVivek Modi
03/23/2022, 11:34 AM@Retention(AnnotationRetention.BINARY)
What is Retention
, AnnotationRetention
and BINARY
?Aaron Waller
03/24/2022, 11:36 AMdead.fish
03/25/2022, 8:10 AMTaskRunner
setup, but Coroutines
for cleanup handling), which made some tests fail and overall made me feel I was doing something wrong (don’t want to import so many LOC in my tree).brian
03/25/2022, 2:29 PMTariyel Islami
03/25/2022, 5:45 PMobject Transformer {
private var transformerMap = mutableMapOf<String, Any>()
fun put(key: String, t: Any) {
transformerMap[key] = t
}
fun pull(key: String): Any {
return transformerMap[key]!!
}
}
The logic is simple,
When you use the navigate function you have to put the parameters which you want to send
Where you use the Composable function, you need to pull it and give it as a parameter.
It is perfectly working. I am wondering that is this wrong way ?the great warrior
03/25/2022, 9:03 PMAaron Waller
03/26/2022, 11:40 AMTariyel Islami
03/27/2022, 10:08 AMspierce7
03/27/2022, 6:02 PMAaron Waller
03/28/2022, 4:16 AMRitwik Raj Srivastava
03/28/2022, 6:12 AMfun Any?.toJSONString(): String {
return this?.let {
try {
val gson = GsonBuilder().setPrettyPrinting().create()
gson.toJson(this)
} catch (e: Exception) {
"{}"
}
} ?: "{}"
}
And I have another Extension function that takes in Generic T and I want to parse/manipulate the result. For example being
fun <T : Any> Response<MyResponse<T>>.toStr(): String {
return T.toJSONString()
}
I am getting this error
Type parameter 'T' cannot have or inherit a companion object, so it cannot be on the left hand side of dot
Please help me out. If anyone can explain the error itself. It will be great. I do not have indepth Kotlin know-hows.androidexpertmanish
03/28/2022, 7:10 AMiamraghavawasthi
03/29/2022, 6:01 AM"2021-12-02T16:54:08.931Z"
I am using the pattern "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
in Simple Date Format. I am getting unparseble date errorOmar Qadour
03/29/2022, 3:24 PMalthaf
03/30/2022, 7:40 AMprivate fun List<PaymentTaxDiscountDetail.PaymentTaxDiscount>.getTotalTaxDiscount(): Double {
var vatPlusDiscountTotal = sumByDouble {
if (!it.taxType.startsWith(TaxType.WHT.name)) it.whtAmount else 0.0
}
val whtTotal = sumByDouble {
if (it.taxType.startsWith(TaxType.WHT.name)) it.whtAmount else 0.0
}
return vatPlusDiscountTotal - whtTotal
}
Ali
03/30/2022, 9:30 AMViewStub
and OnInflateListener
to listen once the original layout is inflated.
This is my ViewStub
layout `fragment_navigation_viewstub`:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewStub
android:id="@+id/fragmentNavigationViewStub"
android:layout="@layout/fragment_navigation"
android:layout_width="match_parent"
android:inflatedId="@+id/items_list"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
and this is my original layout `fragment_navigation`:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="<http://schemas.android.com/apk/res/android>"
android:id="@+id/items_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and my listeneer inside the fragment:
private val binding by viewBinding { FragmentNavigationViewstubBinding.inflate(it) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.fragmentNavigationViewStub.setOnInflateListener { _, view ->
fragmentNavigation = FragmentNavigationBinding.bind(view)
}
}
But I got this exception and looks like setOnInflateListener
is not called
kotlin.UninitializedPropertyAccessException: lateinit property fragmentNavigation has not been initialized
Ahmed Shehata
03/30/2022, 4:06 PMBreaker ACT
03/30/2022, 4:17 PMviewModelScope.launch
work like a charm until I’m navigate to other screen => viewModel go to onClear() => Then I’m navigate back and try to call viewModelScope.launch
but it didn’t anything. Any idea for this ?PontiacGTX
03/31/2022, 2:10 PMPontiacGTX
03/31/2022, 2:10 PMfun loadImages(){
recyclerView!!.setHasFixedSize(true)
recyclerView!!.layoutManager = GridLayoutManager(this.activity,4)
try {
this.imageList = ImageGallery.GetImagesList(this.context as Context )
}
catch (ex:Exception)
{
println(ex.message)
}
try { galleryAdapter = GalleryAdapter(this.context as Context,imageList,
object : IPhotoInterface {
override fun onPhotoClick(stringPath: String):Unit {
//process picture on click
imageIntent = android.content.Intent(context,SecondaryActivity::class.java)
imageIntent.putExtra("image_file",File(stringPath))
try{
startActivity(imageIntent)
}catch(except:Exception)
{
println(except.message)
}
}
})
recyclerView?.adapter = galleryAdapter
galleryNumberText?.text = "${imageList.size} images"
}
catch(ex:Exception)
{
println(ex.message)
}
}