Skip to content

Instantly share code, notes, and snippets.

@madki
madki / CollectionUtils.kt
Created June 23, 2020 20:17
A builder api for kotlin collections
class CollectionBuilder<T, MC: MutableCollection<T>>(private val collection: MC) {
private var finalized = false
fun add(element: T) = collection.add(element)
fun addAll(elements: Collection<T>) = collection.addAll(elements)
fun finalize(): Collection<T> {
if (!finalized) {
return collection
} else {
@madki
madki / AutoIntent.md
Last active February 7, 2016 04:26
Proposal for a annotation processor that generates wrappers for intents

AutoIntent

The problem

Data transfer in android happens a lot via intents. Even in case of single activity pattern (to which square is a strong proponent of) there are still Android's system activities that are needed to be started or passing messages to services. So intents are probably going to stay for a while and if there's a way to make them better it's worth taking a look at.

  • Type-safety One of the advantages Intents offer is the completely decoupling of the calling code and the recieving activity. It has one major caveat that compilers are now clueless whether the passed in values are correct. Any key can be mapped with any of the types that can be put into the intent.

  • Definition There's no standard way to specify intent requirements. Some activities need some additional extras that are required for it to start. In some cases additional flags or action might have to be set. There should be an easier and straight forward way of defining these requirements such that misuse can be av

@madki
madki / bintrayv1java.gradle
Created October 25, 2015 14:19
Upload java library to bintray
apply plugin: 'com.jfrog.bintray'
version = libraryVersion
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
@madki
madki / bintrayv1.gradle
Last active August 29, 2015 14:27
Upload files to bintray
apply plugin: 'com.jfrog.bintray'
version = libraryVersion
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
@madki
madki / installv1.gradle
Created August 22, 2015 23:21
Building library files for maven
apply plugin: 'com.github.dcendents.android-maven'
group = publishedGroupId // Maven Group ID for the artifact
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'