Kotlin adds null safety into into it's type system as a first class concept. The following would not compile:
val maybe: String = null
In Kotlin every type has a corresponding 'optional' type denoted
with a ?
:
What did I see?
What actually happened?
Authorization
header was a Digest one would break.I recently spent some time refactoring how Collect interacts with the Android MediaPlayer
(PR here). This resulted in my having to touch a fair amount of the stack involed in form entry so I thought it would be good to do a write up of the pain I experienced (within the code) with some suggestions around improvement we could make.
Disclaimer: all the "Next steps" are definitely just my own and first opinion so are very open to discussion.
When Collect renders a Form it uses an ODKView
to represent each question (FormEntryPrompt
) or "group" of questions. This view is hosted inside a FormEntryActivity
. When the user swipes from left to right the ODKView
is removed from the view hierarchy and a new one is made for the new question.
public final class Helpers { | |
private Helpers() { | |
} | |
public static String createMockReference(ReferenceManager referenceManager, String referenceURI) throws InvalidReferenceException { | |
String localURI = UUID.randomUUID().toString(); | |
return createMockReference(referenceManager, referenceURI, localURI); | |
} |
package org.odk.collect.android.instrumented; | |
import android.media.MediaRecorder; | |
import androidx.test.ext.junit.runners.AndroidJUnit4; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import java.io.File; |
import android.app.Activity | |
import android.content.Context | |
import androidx.fragment.app.Fragment | |
import kotlin.reflect.KClass | |
import kotlin.reflect.KProperty | |
class ObjectProvider { | |
private val providers = mutableMapOf<Class<*>, () -> Any?>() | |
private val singletons = mutableMapOf<Class<*>, Any?>() |
class MyApplication : Application() { | |
var dependencies: Dependencies = DefaultDependencies() | |
} | |
interface Dependencies { | |
val thing: Thing | |
} | |
fun Activity.dependencies(): Dependencies { | |
return (this.application as MyApplication).dependencies |