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 ; | |
import javax.annotation.Nonnull; | |
import javax.annotation.Nullable; | |
public class Maybe<T> { | |
private static final Maybe EMPTY = new Maybe(); | |
private final T element; | |
private Maybe() { |
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 open class MutableListWrapper<T>(private val source: MutableList<T>) : AbstractMutableList<T>() { | |
override val size get() = source.size | |
override fun add(index: Int, element: T) = source.add(index, element) | |
override fun get(index: Int) = source[index] | |
override fun removeAt(index: Int) = source.removeAt(index) | |
override fun set(index: Int, element: T) = source.set(index, element) |
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 android.app.Activity | |
import androidx.annotation.IdRes | |
import androidx.fragment.app.Fragment | |
import android.view.View | |
import androidx.lifecycle.Lifecycle | |
import androidx.lifecycle.LifecycleEventObserver | |
import kotlin.properties.ReadOnlyProperty | |
import kotlin.reflect.KProperty | |
fun <V : View> Activity.view(@IdRes viewId: Int) = lazy<V>(LazyThreadSafetyMode.NONE) { findViewById(viewId) } |
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 ... | |
private val identityMap: (String) -> String = { it } | |
sealed class LocalizedString | |
data class ResourceString( | |
val id: Int, | |
val quantity: Int? = null, | |
val args: List<Any> = emptyList(), |
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 %your.logger.package% | |
private const val MAX_TAG_LENGTH = 23 | |
private const val INLINE_CALL_STACK_INDEX = 2 | |
private val ANONYMOUS_CLASS = Pattern.compile("(\\$\\d+)+$") | |
inline fun log(message: () -> Any?) { | |
Log.d(inlineTag, message().toString()) | |
} |
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 * | |
import android.app.Activity | |
import androidx.fragment.app.Fragment | |
import kotlin.properties.ReadOnlyProperty | |
inline fun <reified T> argNamed() = | |
ReadOnlyProperty<Activity, T> { thisRef, prop -> | |
val data = thisRef.intent.extras?.get(prop.name) | |
data as T |
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 * | |
import android.util.* | |
import androidx.core.os.bundleOf | |
import androidx.savedstate.SavedStateRegistryOwner | |
import kotlin.properties.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
inline fun <reified T : Any?> SavedStateRegistryOwner.savedState(initValue: T) = | |
object : ReadWriteProperty<SavedStateRegistryOwner, T> { |
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.ReadWriteProperty | |
import kotlin.reflect.KProperty | |
fun <T> threadLocal(init: () -> T) = object : ReadWriteProperty<Any?, T> { | |
private val internal = object : ThreadLocal<T>() { | |
override fun initialValue() = init() | |
} | |
override fun getValue(thisRef: Any?, property: KProperty<*>): T = internal.get()!! |