Skip to content

Instantly share code, notes, and snippets.

Avatar

Tom Seifert Syex

  • NRW, Germany
View GitHub Profile
View BasicEmitter.kt
class Emitter {
fun defaultStateObservable(): Observable<Data>
fun specialStateObservable(): Observable<Data>
}
View BasicEmitter2.kt
class Emitter(private val stateObservable: Observable<State>) {
init {
stateObservable.subscribe { stateChanged(it) }
}
private fun stateChanged(state: State) {
}
View BasicEmitter.kt
class Emitter {
fun defaultStateObservable(): Observable<Data>
fun specialStateObservable(): Observable<Data>
}
View BasicEmitter3.kt
class Emitter(private val stateObservable: Observable<State>) {
private val subject = BehaviorSubject.create<Data>()
init {
stateObservable.subscribe { stateChanged(it) }
}
private fun stateChanged(state: State) {
when (state) {
View Repository.kt
interface SampleRepository {
fun getData(): Observable<Data>
}
View BasicEmitter5.kt
class SampleRepositoryImpl(private val emitter: Emitter) : SampleRepository {
override fun getData(): Observable<Data> = emitter.stateObservable()
}
View BasicEmitter4.kt
class Emitter(private val stateObservable: Observable<State>) {
private val subject = BehaviorSubject.create<Data>()
private var subscriberCount = AtomicInteger()
private val onSubscribeConsumer: (() -> Unit) = {
if (subscriberCount.getAndIncrement() == 0) subscribeToObservable()
}
private val onDisposeConsumer: (() -> Unit) = {
if (subscriberCount.decrementAndGet() == 0) unsubscribeFromObservable()
}
View TextRecognition.kt
fun recognizeText() {
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.image)
val visionImage = FirebaseVisionImage.fromBitmap(bitmap)
val detector = FirebaseVision.getInstance().visionTextDetector
detector.detectInImage(visionImage)
.addOnSuccessListener {
for (block in it.blocks) {
val boundingBox = block.boundingBox
val cornerPoints = block.cornerPoints
View FileProvider.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
View FileProvider.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="images"
path="." />
</paths>
You can’t perform that action at this time.