Skip to content

Instantly share code, notes, and snippets.

View yenerm's full-sized avatar

Murat Yener yenerm

  • Instacart
  • Monterey
View GitHub Profile
@yenerm
yenerm / CustomPlugin.kt
Created November 21, 2021 09:38
CustomPlugin.kt
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
class CustomPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register("hello"){ task->
task.doLast {
println("Hello " + project.parent?.name)
}
/*
* Copyright 2021 The Android 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
@yenerm
yenerm / DummyWorker.kt
Created May 7, 2021 23:28
DummyWorker to test Background Task Inspector
package com.example.background.workers
import android.content.Context
import android.os.SystemClock.sleep
import androidx.work.Worker
import androidx.work.WorkerParameters
class DummyWorker (ctx: Context, params: WorkerParameters) : Worker(ctx, params) {
override fun doWork(): Result {
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> {
private var value: T? = null
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
}
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public final class Person$$special$$inlined$vetoable$1 extends ObservableProperty {
protected boolean beforeChange(@NotNull KProperty property, Object oldValue, Object newValue) {
Intrinsics.checkParameterIsNotNull(property, "property");
String newValue = (String)newValue;
String var10001 = (String)oldValue;
int var7 = false;
@yenerm
yenerm / Person.kt
Last active November 9, 2020 21:14
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
var address: String by Delegates.vetoable("") {
property, oldValue, newValue ->
newValue.length > 14
}
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
val oldValue = this.value
if (!beforeChange(property, oldValue, value)) {
return
}
this.value = value
afterChange(property, oldValue, value)
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
protected void afterChange(@NotNull KProperty property, Object oldValue, Object newValue) {
// update all existing shipments
}
@yenerm
yenerm / Person.kt
Last active November 9, 2020 21:14
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person {
var address: String by Delegates.observable("not entered yet!") {
property, oldValue, newValue ->
// update all existing shipments
}
}
@yenerm
yenerm / Lazy.kt
Last active November 9, 2020 21:14
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
override val value: T
get() {
val _v1 = _value
if (_v1 !== UNINITIALIZED_VALUE) {
@Suppress("UNCHECKED_CAST")
return _v1 as T
}