Skip to content

Instantly share code, notes, and snippets.

View Kvest's full-sized avatar

Roman Bielokon Kvest

  • Prague, Czech Republic
View GitHub Profile
@Kvest
Kvest / ViewModelAssistedInject.kt
Created April 5, 2024 19:50
ViewModel AssistedInject example
class SomeDetailsViewModel @AssistedInject constructor(
@Assisted private val code: String,
@Assisted private val type: SomeType,
private val someRepository: SomeRepository,
) : ViewModel() {
@AssistedFactory
interface SomeDetailsViewModelAssistedFactory {
fun create(code: String, type: SomeType): SomeDetailsViewModel
}
}
setContent {
val animationDurationMs = 500
val messageDisplayDurationMs = 1000L
var currentMessageNum by remember { mutableStateOf(0) }
//----------This part of the code can be easily moved to the presentation layer and exposed as flow---------
// And then the currentMessageNum will look like: val currentMessageNum by state.messages.collectAsStateWithLifecycle()
var messageCounter by remember { mutableStateOf(0) }
val messagesQueue = remember { Channel<Int>(capacity = Channel.UNLIMITED) }
@AndroidEntryPoint
class SomeFragment : Fragment(R.layout.fragment_some) {
companion object {
fun newInstance(someId: String): SomeFragment {
val instance = SomeFragment()
instance.arguments = bundleOf(
SomeViewModel.KEY_SOME_ID to someId
)
return instance
/**
* Copyright (C) 2018 Fernando Cejas Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
class TService : Service() {
companion object {
fun start(context: Context, id: Int) {
val intent = Intent(context, TService::class.java)
intent.putExtra("id", id)
context.startService(intent)
}
}
inline fun <reified T : ViewModel> AppCompatActivity.getViewModel(): T {
return ViewModelProviders.of(this)[T::class.java]
}
inline fun <reified T : ViewModel> AppCompatActivity.withViewModel(body: T.() -> Unit): T {
val vm = getViewModel<T>()
vm.body()
return vm
}
import java.util.*
import kotlin.math.pow
import kotlin.math.sqrt
private const val START = 'S'
private const val END = 'X'
private const val OBSTACLE = 'B'
private const val PATH = '*'
private const val STRAIGHT_STEP = 1f
private const val DIAGONAL_STEP = 1.5f
@Kvest
Kvest / HOF
Last active July 17, 2018 20:33
fun test(action:() -> Unit) {
println("start test")
action()
println("end test")
}
@Kvest
Kvest / avd_bundle.xml
Created October 27, 2016 06:19 — forked from nickbutcher/avd_bundle.xml
An example of the Android xml bundle format for creating an AnimatedVectorDrawable. See https://plus.google.com/+NickButcher/posts/A8KKxnJdg4r
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
public class RingViewTransition extends Transition {
...
private void captureValues(RingView view, TransitionValues transitionValues) {
Bundle extraData = (Bundle)transitionValues.view.getTag(R.id.tag_transition_extra_properties);
if (extraData != null) {
transitionValues.values.put(PROPNAME_COLOR,
extraData.getInt(PROPNAME_COLOR, view.getColor()));
transitionValues.values.put(PROPNAME_INNER_RADIUS,
extraData.getFloat(PROPNAME_INNER_RADIUS, view.getInnerCircleRadius()));
transitionValues.values.put(PROPNAME_OUTER_RADIUS,