Skip to content

Instantly share code, notes, and snippets.

View piotrmadry's full-sized avatar

Piotr Mądry piotrmadry

View GitHub Profile
firebaseTestLab {
keyFile = file("developer-account.json")
googleProjectId = "mgm-resorts-app"
devices {
instrumentedTest {
deviceIds = ["Nexus5X"]
androidApiLevels = [23]
isUseOrchestrator = true
numShards = 4
environmentVariables = ["clearPackageData=true"]
fun <T> Single<T>.toEither(): Single<Either<DefaultError, T>> = this
.map<Either<DefaultError, T>> { Either.right(it) }
.onErrorReturn { Either.left(it.toDefaultError()) }
inline fun <reified T : Activity> Context.open() = startActivity(Intent(this, T::class.java))
inline fun <reified T : Activity> Context.openForResult(code: Int) = startActivityForResult(Intent(this, T::class.java), code)
inline fun <reified T : Fragment> newInstance(): T = T::class.java.newInstance()
Usage:
open<LoginActivity>()
openForResult<LoginActivity>(INTENT_CODE)
presenter.onStart(object : BookPresenter.View {
override var pages: String by book_fragment_pages.textViewDelegate()
})
fun TextView.textViewDelegate() : ReadWriteProperty<Any, String> = object : ReadWriteProperty<Any, String> {
override fun getValue(thisRef: Any, property: KProperty<*>): String = text.toString()
override fun setValue(thisRef: Any, property: KProperty<*>, value: String) {
text = value
}
}
startActivityForResult(fileHelper.photoPickIntent(isFrontCameraAvailable(context)),
when (type) {
UploadType.Document -> AttachmentsCode.GALLERY_OR_CAMERA_RESULTS_DOCUMENT
UploadType.Proof -> AttachmentsCode.GALLERY_OR_CAMERA_RESULTS_PROOF
UploadType.Selfie -> AttachmentsCode.CAMERA_RESULTS_SELFIE
})
sealed class UnlockState {
object Activating : UnlockState()
object Activated : UnlockState()
object Opened : UnlockState()
}
sealed class UploadType {
object Document : UploadType()
object Selfie : UploadType()
object Proof : UploadType()
}
sealed class BiometricsErrors : DefaultError {
data class UnknownError(val errorCode: Int, val reason: String) : BiometricsErrors()
object NotSupportedError : BiometricsErrors()
object NoFingerprintsEnrolledError : BiometricsErrors()
object AuthFailedError : BiometricsErrors()
}
val codes = arrayOf(1, 2, 3, 4, 5)
val generalCodes = asList(-5, -4, -3, -2, -1, 0, *codes)