Skip to content

Instantly share code, notes, and snippets.

View yenerm's full-sized avatar

Murat Yener yenerm

  • Google
  • San Francisco
View GitHub Profile
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String by FormatDelegate(name)
var lastname: String by FormatDelegate(lastname)
var updateCount = 0
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class FormatDelegate : ReadWriteProperty<Any?, String> {
private var formattedString: String = ""
override fun getValue(
thisRef: Any?,
property: KProperty<*>
): String {
/*
* 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
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, var lastname: String) {
var name: String = name
set(value) {
field = value.toLowerCase().capitalize()
updateCount++
}
var updateCount = 0
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String = name
set(value) {
field = value.toLowerCase().capitalize()
updateCount++
}
var lastname: String = lastname
@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)
}
@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 {
@yenerm
yenerm / Person.kt
Last active November 9, 2020 21:15
lazy() sample
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
val fullname: String by lazy() {
name + lastname
}
//...
}
@yenerm
yenerm / Person$Lazy.java
Last active November 9, 2020 21:15
decompiled lazy()
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
@NotNull
private final Lazy fullname$delegate;
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
this.fullname$delegate = LazyKt.lazy((Function0)(new Function0() {
@NotNull
public final String invoke() {
return name + lastname;
}
}));