suhas
08/24/2021, 8:13 AMTower Guidev2
08/24/2021, 11:22 AMApollo3
for my Android GraphQL client callsThe Monster
08/24/2021, 11:01 PMbinding.button.setOnClickListener( View.OnClickListener {
})
binding.button.setOnClickListener {
}
Hey guys I am confused why I was able to skip the parenthesis on the 2nd example. The method takes a functional interface, but not a function, so how am I allowed to use the passing trailing lambda syntax here?nilTheDev
08/25/2021, 6:52 AMLiveData
of type MutableLiveData<MutableList<User>>
.
I have an issue.
If I update the value
by another MutableList<User>
the changes are emitted to the observers.
However, if I simply add other elements to the MutableList<User>
, that is already initialised in the LiveData
, the changes are not emitted.
Here is what I am doing...
//other codes
private val _users: MutableLiveData<MutableList<User>> = MutableLiveData<MutableList<User>>()
init {
_users.value = mutableListOf<User>()
}
val uiScope = CoroutineScope(Dispatchers.Main + Job())
fun loadUsers(){
uiScope.launch{
// this works perfectly
_users.value = fetchUsers() as MutableList<User>
// this doesn't work... no idea why
_users.value.addAll(fetchUsers())
}
}
suspend fun fetchUsers(): List<User>{
return withContext(<http://Dispatchers.IO|Dispatchers.IO>){
//fetch users asynchronously
}
}
This is just an emulation of the actual program. That actual code is not that trivial.Nikolay Puliaev
08/25/2021, 8:59 AMharis mehmood
08/25/2021, 11:09 AM"data": [
{
"player_id": 2497,
"firstname": "Jay-Alistaire Frederick",
"lastname": "Simpson",
"birthday": "1988-12-01",
"age": 32,
"weight": 85,
"height": 180,
},
{
"player_id": 2570,
"firstname": "Simranjit",
"lastname": "Singh Thandi",
"birthday": "1999-10-11",
"age": 21,
"weight": null,
"height": null,
}]
Hi i want to replace value of "weight" to 0 if its null from backend. How to do it in Data Class ? Any solutionTravis Griggs
08/25/2021, 8:26 PMoverride fun compareTo(other: ValveSpan): Int {
val fields = listOf(ValveSpan::begin, ValveSpan::end, ValveSpan::userTitle)
val comparisons = fields.asSequence().map { field -> field(this).compareTo(field(other)) }
return comparisons.firstOrNull { n -> n != 0 } ?: 0
}
Basically an arbitrary number of accessors, work through them lazily until i get to a non zero return and return that. But the compiler complains because:
Type mismatch.
Required: {Duration & String}
Found: {Comparable{Duration & String}> & Serializable}
my begin and end accessors do indeed return Durations and the userTitle does indeed return a String. I'm not entirely clear on what the compiler is not happy about here though. it seems like its figuring it out kind of, but not all the way. or there's some stupid syntax error that will only finally embarssingly occur to me finally after pressing send...Travis Griggs
08/25/2021, 10:57 PMval beginEdges: Set<Duration>
get() = emptySet<Duration>() + spans.asSequence().map({ span -> span.begin })
setOf() takes varargs, but I'm not aware of a pythonesque ability to ** an iterable argument to varargs...Caio Costa
08/26/2021, 3:53 AMprivate val _errorStateFlow = MutableStateFlow<State<Error>>(InitialError)
internal val errorStateFlow: StateFlow<State<Error>>
get() = _errorStateFlow
Since it is an Error StateFlow, everytime it posts something, i show a SnackBar on the screen but i just want to do this one time for each time the error occurs. Any thoughts on it? Appreciate ya 👍Matthew Laser
08/26/2021, 2:33 PMDuration
API always been experimental? I swear I used it years ago and it wasn't. Am I making this up? 😛maxmello
08/26/2021, 3:14 PMJason Inbody
08/26/2021, 5:15 PMorg.kivy.android.PythonActivty
. Do I have to keep that naming convention for my main activity when I upload to google play? Or can that be changed between versions?Andy Gibel
08/26/2021, 7:52 PMTravis Griggs
08/26/2021, 9:03 PMenum ValveRunInterval {
case future(start:Date, plan:Plan)
case active(interval:DateInterval, plan:Plan)
...
}
I could use a little abstract/two subclass triad to express this. Not sure what the rules are when combining data classes and inheritance. Is there a better/different way?Slackbot
08/27/2021, 7:28 AMHovhannes
08/27/2021, 12:52 PMWilliam Reed
08/27/2021, 1:52 PMdata class
that the bundle is expected to conform to. is there any out of the box way to do this?
i’m sure it could be done with a code gen library, just not sure if it’s been done beforeSlackbot
08/27/2021, 9:21 PMhfhbd
08/28/2021, 7:56 PMViewModelProvider.Factory
not a fun interface
? This would allow you to pass a lambda instead.Lilly
08/28/2021, 10:02 PMBluetooth permissions
docs and there is stated:
<manifest ... >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- If your app targets Android 9 or lower, you can declare
ACCESS_COARSE_LOCATION instead. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
</manifest>
I'm wondering:
When I follow this advice I end up declaring both permission FINE and COARSE, while I can restrict the use of COARSE:
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="28" />
But can I configure FINE_LOCATION so that it's only declared when API is >28? I mean isn't it a problem when I have both permission declared although I only need one of them at the same time?
Same goes for the new permission BLUETOOTH_CONNECT/SCAN that is only needed on API level 31.
I'm also wondering why FINE_LOCATION is stucked out on the New Bluetooth permissions in Android 12 page. Isn't it better to declare FINE_LOCATION like the other legacy
permissions:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30" />
This permission is still needed on API level 29 or lower.Slackbot
08/30/2021, 3:59 AMJohnjake Talledo
08/30/2021, 5:31 AMbase-persistence
only unit test folder
and ui test
are the defaults so I created a root folder or directory but everytime I create a sub folder it creates another new directory. Eg: In com.metromart.runner_persistence
I want to create a sub directory called base but instead it creates another folder, com.metromart.runner_persistence.base
.Slackbot
08/30/2021, 8:40 AMVivek Modi
08/30/2021, 5:01 PMbinding
in onDestroyView
when implementing Android View Binding in a Fragment?Klaas Kabini
08/30/2021, 6:39 PMLiveData.observeForever
. Does anyone has an idea as to what might be causing that?Стоян Тинчев
08/30/2021, 6:39 PMJacob
08/31/2021, 3:58 AMpartap
08/31/2021, 2:20 PMDavid Alford
08/31/2021, 4:42 PM<activity
android:name=".MyTargetActivity"
android:screenOrientation="portrait">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="my.host.com"
android:scheme="https" />
<data
android:host="my.host.com"
android:scheme="http" />
</intent-filter>
</activity>
I've created the intent from the URL:
val url: HttpUrl = HttpUrl.Builder()
.scheme("https")
.host("<http://my.host.com|my.host.com>")
.addPathSegment("invite")
.addQueryParameter("voucher", voucherContents)
.build()
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url.toString())
type = "text/plain"
toUri(0)
}
val shareIntent = Intent.createChooser(sendIntent, url.host)
startActivity(context, shareIntent, null)
This pops up a chooser window where I can select an app or copy to clipboard. I choose the latter and then open up an app such as Slack or Sheets or something and paste it in. When I click the URL link I just pasted, it opens MyTargetActivity successfully, but it's in the app that opened it rather than a new application. How do I get it to launch as a standalone application? (I've also written the server part and gotten that working. I can rummage that up if needed.)Milan Vadhel
09/01/2021, 5:48 AM@SmallTest
@RunWith(MockitoJUnitRunner::class)
@ExperimentalCoroutinesApi
class CharacterViewModelTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
@get:Rule
val testCoroutineRule = TestCoroutineRule()
@Mock
lateinit var characterUseCase: CharacterUsecase
@Mock
lateinit var characterRepository: CharacterRepository
@Mock
lateinit var characterLiveData: Observer<UiState<ArrayList<CharacterItem>>>
private val characterViewModel: CharacterViewModel by lazy {
CharacterViewModel(characterUseCase)
}
@Test
fun test_characterApiCallSuccess() {
stubCharacterApiSuccess()
characterViewModel.charactersLiveEvent.observeForever(characterLiveData)
characterViewModel.getCharacters(1)
verify(characterLiveData).onChanged(UiState.Loading()) // Test Loading Response
verify(
characterLiveData
).onChanged(UiState.Success(characterApiResponse())) // Test Success Response
characterViewModel.charactersLiveEvent.removeObserver(characterLiveData)
}
private fun stubCharacterApiSuccess() {
testCoroutineRule.runBlockingTest {
doReturn(characterApiResponse())
.`when`(characterRepository)
.getCharacters(1)
}
}
}
I am getting below error..
Wanted but not invoked:
characterLiveData.onChanged(
Success(data=[CharacterItem(name=Rick Sanchez, image=<https://rickandmortyapi.com/api/character/avatar/1.jpeg>, status=Alive, gender=Male, species=Human)])
);
-> at com.example.databindingsample.CharacterViewModelTest.test_characterApiCallSuccess(CharacterViewModelTest.kt:55)
Actually, there were zero interactions with this mock.
I can't figure out what this error is saying. Is there any thing i am doing wrong. Any one have any idea about it?Milan Vadhel
09/01/2021, 5:48 AM@SmallTest
@RunWith(MockitoJUnitRunner::class)
@ExperimentalCoroutinesApi
class CharacterViewModelTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
@get:Rule
val testCoroutineRule = TestCoroutineRule()
@Mock
lateinit var characterUseCase: CharacterUsecase
@Mock
lateinit var characterRepository: CharacterRepository
@Mock
lateinit var characterLiveData: Observer<UiState<ArrayList<CharacterItem>>>
private val characterViewModel: CharacterViewModel by lazy {
CharacterViewModel(characterUseCase)
}
@Test
fun test_characterApiCallSuccess() {
stubCharacterApiSuccess()
characterViewModel.charactersLiveEvent.observeForever(characterLiveData)
characterViewModel.getCharacters(1)
verify(characterLiveData).onChanged(UiState.Loading()) // Test Loading Response
verify(
characterLiveData
).onChanged(UiState.Success(characterApiResponse())) // Test Success Response
characterViewModel.charactersLiveEvent.removeObserver(characterLiveData)
}
private fun stubCharacterApiSuccess() {
testCoroutineRule.runBlockingTest {
doReturn(characterApiResponse())
.`when`(characterRepository)
.getCharacters(1)
}
}
}
I am getting below error..
Wanted but not invoked:
characterLiveData.onChanged(
Success(data=[CharacterItem(name=Rick Sanchez, image=<https://rickandmortyapi.com/api/character/avatar/1.jpeg>, status=Alive, gender=Male, species=Human)])
);
-> at com.example.databindingsample.CharacterViewModelTest.test_characterApiCallSuccess(CharacterViewModelTest.kt:55)
Actually, there were zero interactions with this mock.
I can't figure out what this error is saying. Is there any thing i am doing wrong. Any one have any idea about it?Klaas Kabini
09/01/2021, 6:21 AMfun <T> LiveData<T>.attachDisposableObserver(time: Long = 2, timeUnit: TimeUnit = TimeUnit.SECONDS, afterObserve: ()-> Unit) {
val latch = CountDownLatch(1)
val observer = object : Observer<T> {
override fun onChanged(t: T?) {
latch.countDown()
this@gattachDisposableObserver.removeObserver(this)
}
}
this.observeForever(observer)
try{
// Don't wait indefinitely if the LiveData is not set.
if (!latch.await(time, timeUnit)) {
throw TimeoutException("LiveData value was never set.")
}
} finally{
this.removeObserver(observer)
}
afterObserve.invoke()
}