Tin Tran
09/01/2021, 7:47 AMclass MyViewModel:ViewModel() {
private val job = SupervisorJob()
private val scope = CoroutineScope(<http://Dispatcher.IO|Dispatcher.IO> + job)
fun test() {
viewModelScope.launch {
job1()
job.cancelAndJoin()
scope.launch {
job2()
}
}
}
}
Tower Guidev2
09/01/2021, 9:44 AMLilly
09/01/2021, 1:09 PMval router: Router<Route> = rememberSaveable {
Router(Route.Status).apply { isSingleTop = true } // using apply does not work here
}
As far as I set apply
, android studio complains:
Required: Router<Dashboard.Route>
Found: Router<Dashboard.Route.Status>
Route
is a sealed class, signature of Router
is:
class Router<T : Any>(private val backStack: List<T>) : RouterActions<T>
Sololo
09/01/2021, 1:57 PM/Users/sololo/Library/Android/sdk/build-tools/30.0.2/aapt p -f -M ./app/src/main/AndroidManifest.xml -I /Users/sololo/Library/Android/sdk/platforms/android-29/android.jar -S ./app/src/main/res -J ./app -m
codeslubber
09/01/2021, 2:33 PMSam
09/01/2021, 8:30 PMadjpd
09/02/2021, 12:10 AMCall<String>
. I'd like it to return a Flow<String>
with the least amount of boilerplate possible. How are you all doing it?Slackbot
09/02/2021, 8:35 AMThe Monster
09/03/2021, 3:23 AMclass CatFactsViewModel : ViewModel() {
private val catFacts: MutableLiveData<List<String>> by lazy {
MutableLiveData<List<String>>().also {
loadCatFacts()
}
}
fun getCatFacts(): LiveData<List<String>> {
return catFacts
}
private fun loadCatFacts() {
// Do an asynchronous operation to fetch cat facts.
catFacts.value = listOf("fact 1", "fact 2")
}
}
Hovhannes
09/03/2021, 10:09 AMHovhannes
09/03/2021, 1:34 PMRita Okonkwo
09/03/2021, 2:14 PMadjpd
09/04/2021, 4:41 PMStateFlow
instead of LiveData
. From what I can tell it's main benefits are 1) It's a Kotlin language feature rather than an Android library and 2) you can use intermediate "flow" operations on it rather than use a get()ter method to manipulate the data. That's pretty much it, right?codeslubber
09/04/2021, 10:09 PMAhmed Sellami
09/05/2021, 7:47 PMThe Monster
09/06/2021, 1:31 AMrunBlocking
blocks the current thread, so why is Hello
still printed first? Shouldn't it blocks for 3 secs and prints Hello
at the end?Hovhannes
09/06/2021, 6:39 AMclass RemoteDataSource @Inject constructor() {
companion object {
var string: String?=null
fun setEncr(string: String){
this.string=string
}
fun getEncr():String{
return this.string!!
}
}
private fun getRetrofitClient( context: Context? = null): OkHttpClient {
val authenticator:Authenticator?=null
val encryp= getEncr()
val body = "{\r\n\"Data\":\"${encryp}\"\r\n}"
.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
return OkHttpClient.Builder()
.cache(null)
.addInterceptor { chain ->
chain.proceed(chain.request().newBuilder().also {
it.addHeader("Accept", "application/json")
it.method("POST", body)
}.build())
}.also { client ->
authenticator?.let { client.authenticator(it) }
if (BuildConfig.DEBUG) {
val logging = HttpLoggingInterceptor()
logging.setLevel(HttpLoggingInterceptor.Level.BODY)
client.addInterceptor(logging)
}
}.build()
}
}
in MainActivity
binding.buttonLogin.setOnClickListener {
val clientId = binding.edittxtClientId.text.toString().trim()
encrypted = encrypt(clientId, publicKey)
setStr(encrypted)
viewModel.loginResponse.observe(this, Observer {
when (it) {
is Resource.Success -> {
.....
}
}
Rajput Art Studio
09/06/2021, 1:32 PMSam Marz
09/06/2021, 10:51 PMComposable
function has been called to Recomposition
?Orhan Tozan
09/07/2021, 12:07 PMDaniel Brauer
09/07/2021, 12:13 PMnilTheDev
09/07/2021, 2:23 PMSlackbot
09/07/2021, 7:37 PMSpikey Sanju
09/08/2021, 12:37 AMBigSur
to Monterey
. I'm using M1 Apple Sillicon
Machine. Whenever I try to open android studio it's showing the crash log.
Crash log in Thread ℹ️Shobana Velmurugan
09/08/2021, 5:09 AM<compatible-screens>
<screen android:screenDensity="ldpi" android:screenSize="small" />
<screen android:screenDensity="mdpi" android:screenSize="small" />
<screen android:screenDensity="hdpi" android:screenSize="small" />
<screen android:screenDensity="xhdpi" android:screenSize="small" />
<screen android:screenDensity="420" android:screenSize="small" />
<screen android:screenDensity="480" android:screenSize="small" />
<screen android:screenDensity="560" android:screenSize="small" />
<screen android:screenDensity="640" android:screenSize="small" />
<!--Normal-->
<screen android:screenDensity="ldpi" android:screenSize="normal" />
<screen android:screenDensity="mdpi" android:screenSize="normal" />
<screen android:screenDensity="hdpi" android:screenSize="normal" />
<screen android:screenDensity="xhdpi" android:screenSize="normal" />
<screen android:screenDensity="420" android:screenSize="normal" />
<screen android:screenDensity="480" android:screenSize="normal" />
<screen android:screenDensity="560" android:screenSize="normal" />
<screen android:screenDensity="640" android:screenSize="normal" />
<!--Large-->
<screen android:screenDensity="ldpi" android:screenSize="large" />
<screen android:screenDensity="mdpi" android:screenSize="large" />
<screen android:screenDensity="hdpi" android:screenSize="large" />
<screen android:screenDensity="xhdpi" android:screenSize="large" />
<screen android:screenDensity="420" android:screenSize="large" />
<screen android:screenDensity="480" android:screenSize="large" />
<screen android:screenDensity="560" android:screenSize="large" />
<screen android:screenDensity="640" android:screenSize="large" />
</compatible-screens>
Does anyone help me? with what I did wrong?Atul P Kaushik
09/08/2021, 10:44 AMJohnjake Talledo
09/08/2021, 1:38 PMInstrumentationRegistry.getInstrumentation().targetContext
but its seems to not working. I am guessing its incorrect context
@RunWith(RobolectricTestRunner::class)
@Config(manifest=Config.NONE)
class JobOrderUnitTest {
@get:Rule
var instantTaskExecutorRule= InstantTaskExecutorRule()
@get:Rule
var coroutineRule = MainCoroutineRule()
lateinit var viewModel : JobOrderViewModel
private val context = InstrumentationRegistry.getInstrumentation().targetContext
@Before
fun setUp() {
viewModel = JobOrderViewModel(JobOrderRepository())
}
@Test
fun `fetch data from mock server`() {
}
@ExperimentalCoroutinesApi
@Test
fun `This collect data from repository`() {
coroutineRule.runBlockingTest {
viewModel.fetchJobOrder(context)
viewModel.jobOrder.collect { list ->
assert(list == listOf<Order>())
}
}
}
}
Orhan Tozan
09/08/2021, 2:48 PMappleobject
09/08/2021, 9:40 PMK Merle
09/09/2021, 10:11 AMK Merle
09/09/2021, 10:11 AMViktor Petrovski
09/09/2021, 5:30 PMViewModel
you should use hilt to get an instance of your actual ViewModel
who extends the abstract ViewModel
. You can’t have object from an abstract
class.K Merle
09/10/2021, 5:50 AMval viewModel: Interface = hiltViewModel<InterfaceImpl>()