dewildte
04/03/2020, 3:51 PMapp:gone_baseline="some_other_view_than_this_one"
Ellen Spertus
04/03/2020, 10:39 PMViewModel
class with a constructor that takes parameters? I found this advice, but there’s a comment saying it’s deprecated. https://www.albertgao.xyz/2018/04/13/how-to-add-additional-parameters-to-viewmodel-via-kotlin/Souhail Marghabi
04/04/2020, 8:32 AM// RecyclerViewListItem.kt
val encryptedImageEndpoint = "API_URL"
val glideUrl = GlideUrl(encryptedImageEndpoint) { mapOf(Pair("Authorization", "Bearer $testToken")) }
Glide.with(this.containerView).load(glideUrl).signature(ObjectKey(imageID))
.transition(DrawableTransitionOptions.withCrossFade()).thumbnail(0.25f)
.apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).skipMemoryCache(true).override(selfReference.snapshotImage.width, selfReference.snapshotImage.height)
.placeholder(R.drawable.empty_result)
).into(this.itemView.snapshotImage)
//before loading to imageVIiew I need the following to be done with the API Call response: val decryptedByteArray = CryptoCbc.decryptAesCBC(byteArrayFromResponse, sharedSecret)
henrikhorbovyi
04/04/2020, 7:04 PMJ6ey
04/05/2020, 7:40 AMFile file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "la.pdf");
Uri pdfUri = FileProvider.getUriForFile(this, getPackageName() + ".provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW, pdfUri)
.setDataAndType(pdfUri, "application/pdf")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
file.exists()
shows that the file exists. I am able to locate and open the file in the Download folder, but just not by code. Any idea?Remy Benza
04/05/2020, 3:05 PMam414
04/05/2020, 5:08 PMSlackbot
04/05/2020, 7:30 PMAlexander Suraphel
04/05/2020, 8:18 PMrkeazor
04/05/2020, 10:07 PMSlackbot
04/05/2020, 11:29 PMEllen Spertus
04/06/2020, 8:46 PMUnresolved reference: Callback
error in the expression ContactDatabase.Callback
.
Why? As shown, ContactDatabase
extends RoomDatabase
, and RoomDatabase.Callback
is defined.
@Database(entities = arrayOf(ContactEntity::class), version = 1)
abstract class ContactDatabase : RoomDatabase() {
abstract fun contactDao(): ContactDao
lateinit var callback: RoomDatabase.Callback
private class ContactDatabaseCallback(
private val scope: CoroutineScope
) : ContactDatabase.Callback() { <-- Error on this line
Deepti M
04/06/2020, 9:40 PMvinay
04/07/2020, 6:01 AMitnoles
04/07/2020, 8:02 PMandroidExtensions {
features = ["parcelize"]
}
still generating synthetic properties in Kotlin 1.3.71?J6ey
04/08/2020, 9:15 AMSrSouza
04/08/2020, 2:48 PMLucas Jesus
04/08/2020, 9:19 PMMichael Pohl
04/09/2020, 6:01 PMabstract class ViewModelFragment<VM : BaseViewModel>(@LayoutRes val layout: Int, private val viewModelClass: KClass<VM>) :
BaseFragment() {
open lateinit var viewModel: VM
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
viewModel = getViewModel(viewModelClass)
return inflater.inflate(layout, container, false)
}
}
The idea was to remove as much boilerplate noise in the fragment classes as possible. This project also used Koin
for DI, this class uses Koin's
getViewModel()
to set the viewModel.
What I don’t like about this approach is that subclasses of this have a constructor that looks like this:
class AudioPlayerFragment : ViewModelFragment<AudioPlayerViewModel>(R.layout.fragment_audio_player, AudioPlayerViewModel::class)
As you can see, for this to work, you need a type annotation and still have to hand in the KClass type, which is just ugly.
So I’m wondering if there is any way to get this to just look like this:
class MyFragment<MyViewModel> : ViewModelFragment(myLayout) {}
I understand that there is a limitation as to what Kotlin can do with generics and that I’m basically looking for what `reified`functions can do, but on a class, and that that’s no new question. I was hoping to find a solution like this here: https://stackoverflow.com/a/48398303/8746644
But I can’t figure out a way that would work with Fragments and sub classes . I could also see writing a custom getViewModel
function to deal with the type, but I don’t know how. Does anybody have a suggestion how I could achieve what I want in a reasonable way?Joan Colmenero
04/10/2020, 9:01 AMAnaniya
04/10/2020, 3:55 PMAnaniya
04/10/2020, 5:34 PMmiqbaldc
04/12/2020, 11:18 PMeason
04/13/2020, 7:47 AMreified T::class.java.simpleName return first capital word ex Float
Float::class.java:simpleName return float
is this normal or did i do something wrong?zak.taccardi
04/13/2020, 6:18 PMCoroutineDispatcher
for LifecycleCoroutineScope
in production?
Seems it’s hardcoded to Dispatchers.Main.immediate
and SupervisorJob
which is something I desire flexibility around
https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescopeSantiago Oroz17
04/13/2020, 10:23 PMEllen Spertus
04/13/2020, 10:46 PMRoomDatabase
. I can’t access the database (or even the repository) directly from the fragment’s onStart()
method, since database access is not allowed on the UI thread. What’s the right way for onStart()
to initiate a database query on the IO
thread and then a callback on the UI thread?Mutlu Celep
04/14/2020, 2:20 AMja.son
04/14/2020, 7:51 AMOrhan Tozan
04/14/2020, 1:17 PMinit {}
called? I know that LiveData's only get initialized after observing them, but what about the init block? On Activity onCreate?