Ch8n
05/23/2021, 7:37 PM2021-05-24 00:41:39.235 22590-22590/com.example.myapp D/******* on stop >>>>: ON-STOP
2021-05-24 00:41:39.237 22590-22590/com.example.myapp D/******* on cleared view-model>>>>: ON-CLEARED
2021-05-24 00:41:39.238 22590-22590/com.example.myapp D/******* on destroy >>>>: ON-DESTROY
Jason
05/24/2021, 7:11 AMSam
05/24/2021, 8:24 AMdp
to px
Solution 1:
fun Int.dpToPx(context: Context): Int {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), context.resources.displayMetrics).toInt()
}
Solution 2:
fun Int.dpToPx() = (Resources.getSystem().displayMetrics.density * this + 0.5f)
so Which once is correct for multiple screen? Thanks.Clément Jean
05/24/2021, 10:08 AMui_components
(android library)
/**
* Display a vertical list of [OutlinedTextField]
*/
@Composable
fun Form(fields: List<FormField>) {
LazyColumn(content = {
items(fields) { item ->
OutlinedTextField(
value = item.mutableState.value,
onValueChange = { item.mutableState.value = it },
label = { Text(text = stringResource(id = item.label)) },
isError = item.isError(item.mutableState.value)
)
}
})
}
However, when I compile the logs show me the following error:
e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'items' into
local final fun androidx.compose.foundation.lazy.LazyListScope.<anonymous>(): kotlin.Unit defined in com.xxx.xxx.ui_components.Form
{
items(fields) { item ->
OutlinedTextField(
value = item.mutableState.value,
onValueChange = { item.mutableState.value = it },
label = { Text(text = stringResource(id = item.label)) },
isError = item.isError(item.mutableState.value)
)
}
}
Am I doing something wrong here? Because individually the module compile (so no dependency missing, I guess) and without the dependency to ui_components
the app compiles.
Would be great if you can explain me, thanks in advance! 🙏solidogen
05/24/2021, 12:03 PMDavid Alford
05/24/2021, 10:16 PMval UByteArray.utf8:String
get() {
val index = this.indexOf(0u)
val cleaned = if (index == -1) {
{ this }()
}
else {
{ this.sliceArray(0 until index) }()
}
return cleaned.toByteArray().toString(Charsets.UTF_8)
}
Error Message:
com.android.tools.r8.errors.b: Field name '$this_<get-utf8>' cannot be represented in dex format.
Rishabh Deep Singh
05/25/2021, 5:41 AMfun throttledClick(
targetView: View,
completionMethod: () -> Unit,
throttleWindow: Long = DOUBLE_CLICK_THROTTLE_WINDOW
) {
RxView.clicks(targetView)
.throttleFirst(throttleWindow, MILLISECONDS)
.subscribe {
completionMethod.invoke()
}
}
Eugen Martynov
05/25/2021, 8:55 AMBarry Fawthrop
05/25/2021, 4:39 PMSlackbot
05/25/2021, 6:47 PMSlackbot
05/25/2021, 6:47 PMSlackbot
05/25/2021, 6:47 PMTash
05/25/2021, 11:45 PMsuspend
functions or collecting Flows
via lifecycleOwner
-> scope?Klaas Kabini
05/26/2021, 12:12 PMVitaliy Zarubin
05/26/2021, 12:39 PMInk
05/26/2021, 1:34 PMif (errorMessage != null) {
if (model.iconEnd == null) {
model.iconEnd = InputField.Icon.ERROR
} else {
if (model.iconEnd != InputField.Icon.ERROR)
model.icon = InputField.Icon.ERROR
}
} else {
if (model.iconEnd == InputField.Icon.ERROR) {
model.iconEnd = null
}
if (model.icon == InputField.Icon.ERROR) {
model.icon = null
}
}
Is it possible to simpligy that code?Ahmed Mourad
05/26/2021, 4:19 PMPagingSource
and implementing it in the presentation layer is far from ideal.Zun
05/26/2021, 4:40 PMRupesh Singh
05/26/2021, 6:03 PMSam
05/27/2021, 2:32 AM*Modular Android* App *Architecture*
, so I would like to discuss these two solutions:
• Problems:
◦ Target : Module A
send Event to show Dialog
on the screens and exclude a some screens.
◦ Features divided into separate modules.
◦ Example Requirement: Class SocketService in Module A
get events from server in Application class , we use ActivityLifecycleCallbacks to get Current Activity
, We do not display dialog on Search Screens, Map Screen, … etc ( 2 cases : several screens or large screens should not show dialog)
• Solution 1:
◦ Create an Interface DoNotShowDialog
in Common Module
◦ You will implement this interface to prevent to display Dialog
in each modules/Activity class
• Solution 2:
▪︎ Module A
use activity.javaClass.simpleName to compare with array of strings
▪︎ Example :
arrayListOf("SearchActivity", "MapActivity").contains(this.javaClass.simpleName)
Which solution will you choose?
Thanks.PhongBM
05/27/2021, 4:09 AMChristian Dräger
05/27/2021, 6:25 AMandroid.os.NetworkOnMainThreadException
i already figured out this is because i just call an http client (which is blocking) in the main activity (main/ui thread) as you can see on the screenshot.
what do i need to do to make my http call with my client of choice work?
stackoverflow was saying something about AsyncTasks but the answers has been very old and looked pretty different from my jetpack compose code 😄
I found solutions like: https://stackoverflow.com/a/13136668/10562333 that would just deactivate the restriction but that feels wrong to me.
From what I understood so far I would need to do the call in a background thread instead of the main thread. Can I do this by wrapping my call in a coroutine and if so how? What would be the state of the art way to tackle this problem? (bearbeitet)Remon Shehata
05/27/2021, 3:45 PMval obj : Object = Object()
and val obj: Object get() = Object()
?Sudhir Singh Khanger
05/27/2021, 4:06 PM@RunWith(AndroidJUnit4::class)
class SomeDaoTest {
private lateinit var database: AppDatabase
private lateinit var someDao: SomeDao
@get:Rule
var instantTaskExecutorRule = InstantTaskExecutorRule()
@Before
fun createDb() = runBlocking {
val context = InstrumentationRegistry.getInstrumentation().targetContext
database = Room
.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
// needed to run @Transaction block
.setTransactionExecutor(Executors.newSingleThreadExecutor())
.build()
someDao = database.someDao()
someDao.insertAll(dummy1, dummy2)
}
@After
fun closeDb() {
database.close()
}
@Test
fun testDeleteAll() = runBlocking {
val someData = someDao.getData().getOrAwaitValue()
someDao.deleteAll()
assertEquals(0, someData.size)
}
Any help on how I should do it or how to troubleshoot it would be nice.Jesus Cruz Victoria
05/27/2021, 4:20 PMKevin Bowie
05/28/2021, 2:09 AMAman Kapoor
05/28/2021, 3:30 AMSergio C.
05/28/2021, 9:02 AMVivek Modi
05/28/2021, 10:23 AMval list = mutableListOf(
"1. Log in Google account\n",
"2. Scroll to the page\n",
"3. Tap disconnect from account to logout"
)
val content = StringBuilder()
list.forEach{ string->
content.append(string.replaceFirst(" " , "\t"))
}
System.out.print("string >> $content")
list_string.text = content
As you see it fine in logsAtchay Varma
05/28/2021, 1:18 PMAtchay Varma
05/28/2021, 1:18 PMZun
05/28/2021, 1:30 PMAtchay Varma
05/28/2021, 1:33 PMZun
05/28/2021, 1:34 PMAtchay Varma
05/28/2021, 1:35 PMZun
05/28/2021, 1:39 PMAtchay Varma
05/28/2021, 1:40 PM