Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun initAppUpdateFlow() { | |
| logcat { "check app update" } | |
| val appUpdateManager = AppUpdateManagerFactory.create(this) | |
| lifecycleScope.launch { | |
| try { | |
| appUpdateManager.requestUpdateFlow().collect(::onAppUpdateResult) | |
| } catch (e: InstallException) { | |
| logcat(LogPriority.ERROR) { "Failed to request app update flow\n${e.asLog()}" } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.ByteArrayInputStream | |
| import java.io.ByteArrayOutputStream | |
| import java.util.zip.GZIPInputStream | |
| import java.util.zip.GZIPOutputStream | |
| /** | |
| * Compress a string using GZIP. | |
| * | |
| * @return an UTF-8 encoded byte array. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Copyright 2019 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 | |
| * | |
| * https://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.filipkowicz.headeritemdecorator | |
| /* | |
| solution based on - based on Sevastyan answer on StackOverflow | |
| changes: | |
| - take to account views offsets | |
| - transformed to Kotlin | |
| - now works on viewHolders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.CompletableDeferred | |
| import kotlinx.coroutines.CoroutineScope | |
| import kotlinx.coroutines.Dispatchers | |
| import kotlinx.coroutines.InternalCoroutinesApi | |
| import kotlinx.coroutines.SupervisorJob | |
| import kotlinx.coroutines.cancel | |
| import kotlinx.coroutines.channels.Channel | |
| import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED | |
| import kotlinx.coroutines.launch | |
| import kotlinx.coroutines.suspendCancellableCoroutine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlin.properties.ReadOnlyProperty | |
| import kotlin.properties.ReadWriteProperty | |
| import kotlin.reflect.KProperty | |
| private typealias GetValue<This, R> = (thisRef: This, property: KProperty<*>) -> R | |
| private typealias SetValue<This, R> = (thisRef: This, property: KProperty<*>, value: R) -> Unit | |
| inline fun <This, R> property( | |
| crossinline getValue: GetValue<This, R> | |
| ) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/zsh | |
| # Buttery powered state | |
| adb shell dumpsys battery | grep powered | |
| # Unplug battery | |
| adb shell dumpsys battery unplug | |
| # Reset battery | |
| adb shell dumpsys battery reset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object EventBus { | |
| val bus: BroadcastChannel<Any> = BroadcastChannel() | |
| fun send(o: Any) { | |
| launch { | |
| bus.send(o) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Used as a wrapper for data that is exposed via a LiveData that represents an event. | |
| */ | |
| open class Event<out T>(private val content: T) { | |
| var hasBeenHandled = false | |
| private set // Allow external read but not write | |
| /** | |
| * Returns the content and prevents its use again. |
NewerOlder