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/bash | |
ktlint_version="0.40.0" | |
######################################################################## | |
# A wrapper for ktlint which automatically downloads and runs ktlint. | |
# ktlint executables will be installed under `build/ktlint`. | |
# | |
# Usage | |
# | |
# Download and run ktlint, passing arguments: |
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.nhaarman.android2sandbox; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.os.Handler; | |
public class MainActivity extends Activity { | |
static int i = 0; |
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
class SelectPictureScreen( | |
private val listener: Events | |
) : Screen<SelectPictureContainer> { | |
override fun attach(c: SelectPictureContainer) { | |
c.setOnPictureClickListener { listener.onPictureSelected(it.id) } | |
} | |
interface Events { | |
fun onPictureSelected(id: Long) |
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
interface SimpleContainer { | |
var text: String | |
} | |
class SimpleScreen( | |
val name: String | |
) : Screen<SimpleContainer> { | |
override fun attach(v: SimpleContainer) { | |
v.text = "Hello, $name!" |
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
interface Screen<V : Container> { | |
fun onStart() {} | |
fun attach(v: V) {} | |
fun detach(v: V) {} | |
fun onStop() {} | |
fun onDestroy() {} | |
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
data class Device( | |
val name: String | |
) | |
interface DeviceScanner { | |
/** Emits a Device opon each new discovery event */ | |
fun devices() : Observable<Device> | |
} | |
class BluetoothDeviceScanner( |
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
fun <T, R> Observable<Command<T>>.undoRedo(initialValue: R, accumulator: (R, T) -> R): Observable<R> { | |
return this | |
.scan(UndoRedoStack.create<T>()) { stack, command -> | |
when (command) { | |
is Command.Do -> stack.push(command.action) | |
is Command.Undo -> stack.undo() | |
is Command.Redo -> stack.redo() | |
} | |
} | |
.map { stack -> |
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
sealed class Distance : Comparable<Distance> { | |
data class DistanceMeters(val value: Float) : Distance() | |
data class DistanceFeet(val value: Float) : Distance() | |
fun toMeters() = when (this) { | |
is DistanceMeters -> this | |
is DistanceFeet -> DistanceMeters(value * .3048f) | |
} | |
fun toFeet() = when (this) { |
NewerOlder