Skip to content

Instantly share code, notes, and snippets.

cardView.setOnClickListener {
val intent = Intent(this, DetailActivity::class.java)
val pairImage = Pair<View, String>(imageView, resources.getString(R.string.transition_image))
val pairTitle = Pair<View, String>(tv_title, resources.getString(R.string.transition_title))
val pairDesc = Pair<View, String>(tv_desc, resources.getString(R.string.transition_body))
val pairBack = Pair<View, String>(cardView, resources.getString(R.string.transition_container))
val activityOptions = ActivityOptions.makeSceneTransitionAnimation(this, pairImage, pairTitle, pairDesc, pairBack)
startActivity(intent, activityOptions.toBundle())
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<!-- Customize your theme here. -->
...
<item name="android:windowActivityTransitions">true</item>
...
<!-- Optional enter/exit transitions -->
<item name="android:windowEnterTransition">@transition/explode</item>
<item name="android:windowExitTransition">@transition/explode</item>
fun Route.customer(customerRepo: CustomerRepo) {
route("/customer") {
// http://127.0.0.1:8080/customer
get {
call.respond(HttpStatusCode.OK, customerRepo.customerList)
}
// http://127.0.0.1:8080/customer/1
get("/{customerId}") {
fun Route.customer(customerRepo: CustomerRepo) {
route("/customer") {
get("/{customerId}") {
val customerId = call.parameters["customerId"]?.toInt()
}
}
}
fun main() {
val server = embeddedServer(Netty, port = 8080) {
routing {
helloWorld()
}
}
server.start(wait = true)
}
fun Route.helloWorld() {
fun main() {
val server = embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("Hello World!", ContentType.Text.Plain)
}
}
}
server.start(wait = true)
}
vb.spinner.onItemSelectedListener = object :
AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>,
view: View, position: Int, id: Long
) {
vm.selectedBreedLiveData.value = position
}
override fun onNothingSelected(parent: AdapterView<*>) {
val selectedBreedLiveData = MutableLiveData<Int>()
fun fetchBreedDetails(): LiveData<String> {
return Transformations.switchMap(selectedBreedLiveData)
{
makeDetailsApiCall(it + 1)
}
}
private fun makeDetailsApiCall(id: Int): LiveData<String> {
vm.fetchDogBreedList().observe(viewLifecycleOwner, Observer {
it?.let {
val aa = ArrayAdapter<Any>(requireContext(), android.R.layout.simple_spinner_item, it)
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
vb.spinner.adapter = aa
}
})
fun fetchDogBreedList(): LiveData<List<String>> {
val dogBreedLiveData = fetchDetailsRepo.fetchBreedList()
return Transformations.map(dogBreedLiveData) {
when (it.status) {
Resource.Status.SUCCESS -> {
// Returns a list of 'name' string
it.data?.map { it.name }
}
Resource.Status.ERROR -> {
// Handle Error