Skip to content

Instantly share code, notes, and snippets.

View motorro's full-sized avatar

Nikolai Kotchetkov motorro

View GitHub Profile
@motorro
motorro / Delegate.kt
Created December 22, 2015 03:13
Lazy delegate with respect to context
object Delegates {
/**
* Lazy read-only property with respect to calling context in initializer
* @param initializer Lazy initializer
*/
public fun <T> contextLazy(initializer: Any?.() -> T): ReadOnlyProperty<Any?, T> = UnsafeContextLazy(initializer)
}
/**
* Lazy read-only property with respect to calling context in initializer
@motorro
motorro / ListenerTest.kt
Created August 10, 2019 18:44
AppUpdateManager concurrent modification crash
@Test
@LooperMode(LooperMode.Mode.PAUSED)
fun crashesWhenUnsubscribing() {
updateManager.setUpdateAvailable(100500)
updateManager.withInfo {
startUpdateFlowForResult(it, AppUpdateType.FLEXIBLE, activity, 100)
assertTrue(isConfirmationDialogVisible)
userAcceptsUpdate()
downloadStarts()
@motorro
motorro / FlexibleUpdateActivity.kt
Last active August 10, 2019 19:22
Activity with AppUpdateWrapper
/**
* Basic activity that runs flexible update
*/
class FlexibleUpdateActivity : AppCompatActivity(), AppUpdateView {
/**
* Update flow
*/
private lateinit var updateWrapper: AppUpdateWrapper
override fun onCreate(savedInstanceState: Bundle?) {
@motorro
motorro / build.gradle
Last active August 12, 2019 08:40
Application variants
android {
flavorDimensions "backend"
productFlavors {
testserver {
dimension "backend"
applicationIdSuffix ".test" // Makes your app have a different package name
}
production {
dimension "backend"
}
@motorro
motorro / build.gradle
Created August 12, 2019 08:57
Release signing in debug config
android {
signingConfigs {
release: {
// Some release config for your app
}
}
buildTypes {
debug {
debuggable true
@motorro
motorro / Error.java
Last active November 18, 2019 12:46
Swagger generator nested ref issue
/*
* Sample API
* API description in Markdown.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
@motorro
motorro / NoRepository.kt
Created November 29, 2019 06:52
Delegating repository or not
/**
* Does:
* - fetches data from couple of endpoints
* - calculates result
* - ???
*/
class NoRepositoryFetchTask(
@Named("backend1") private val backend1: ConnectionAssets,
@Named("backend1") private val backend1Auth: Authentication,
@Named("backend2") private val backend2: ConnectionAssets,
@motorro
motorro / BaseModel.kt
Last active December 25, 2019 05:34
ViewModel initialization
abstract class BaseModel: ViewModel() {
var initialized: Boolean = false
private set
/**
* Called from activity's onCreate or onStart
*/
fun initialize() {
if (!initialized) {
@motorro
motorro / prepopulate-city.json
Last active March 11, 2020 15:45
OpenWeather city data structure
{
"id": 2173910,
"name": "Broken Hill Municipality",
"state": "",
"country": "AU",
"coord": {
"lon": 141.433334,
"lat": -31.950001
}
}
@motorro
motorro / prepopulate-City.kt
Last active March 11, 2020 18:52
City entity definition
/**
* City entity
*/
@Entity(
tableName = "cities",
indices = [
Index(name = "city_name", value = ["name"])
]
)
data class City(