This file contains 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
... | |
sealed class Section | |
object Home : Section() | |
object Settings : Section() | |
... | |
private fun changeSection(section: Section) { | |
if (currentSection == section) { |
This file contains 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.app.ext | |
import android.graphics.Color | |
import android.os.Build | |
import android.support.v7.app.AppCompatActivity | |
import android.view.View | |
/*** | |
* | |
* Extension for `AppCompatActivity` to setup fullscreen window mode with specific status and |
This file contains 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
interface MyInterface { | |
fun methodA() | |
fun methodB() | |
} | |
class MyInterfaceImp: MyInterface { | |
override fun methodA() { | |
println("A") | |
} | |
override fun methodB() { |
This file contains 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 cz.vodamiro.example | |
data class SafeValue<out T>(val value: T?, val failed: Boolean = false) |
This file contains 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
class InitOrderDemo(name: String) { | |
val firstProperty = "First property: $name".also(::println) | |
init { | |
println("First initializer block that prints ${name}") | |
} | |
val secondProperty = "Second property: ${name.length}".also(::println) | |
init { |
This file contains 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
// Example of data class (saved more than 10 lines in comparison to Java) | |
data class User(val name: String, val surname: String, val age: Int) | |
// Example of custom getters and setters on a property | |
class MrUser { | |
var name: String = "" | |
get() { | |
return "Mr. $field" // Get name with "Mr." prefix | |
} | |
set(newValue) { |
This file contains 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
sealed class UIState | |
object LoadingState : UIState() // Data is being loaded | |
class DataState(val data: Data) : UIState() // Data loaded successfully | |
class ErrorState(val error: Throwable) : UIState() // In case of failure |
This file contains 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
fun handleStateChange(newState: UIState) { | |
when (newState) { | |
is LoadingState -> println("Loading ...") | |
is DataState -> println("Got data: ${newState.data}") | |
is ErrorState -> println("Error: ${newState.error.message}") | |
} | |
} |
This file contains 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
fun View.makeInvisible() { | |
this.visibility = View.INVISIBLE | |
} | |
val button: Button = //... | |
button.makeInvisible() |
This file contains 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
fun answerToEverything() = 42 |
OlderNewer