Skip to content

Instantly share code, notes, and snippets.

@eoinahern
Created February 5, 2019 17:48
Show Gist options
  • Save eoinahern/95ad39a199b6d700f529fda4886b019d to your computer and use it in GitHub Desktop.
Save eoinahern/95ad39a199b6d700f529fda4886b019d to your computer and use it in GitHub Desktop.
val whatsappRelay: BehaviorRelay<Boolean> = BehaviorRelay.create()
val telegramRelay: BehaviorRelay<Boolean> = BehaviorRelay.create()
val checkTextValid: BehaviorRelay<Boolean> = BehaviorRelay.create()
val openAppIntentRelay: BehaviorRelay<Intent> = BehaviorRelay.create()
val checkShowTextUnderSend: BehaviorRelay<Boolean> = BehaviorRelay.create()
val messageSent: BehaviorRelay<Boolean> = BehaviorRelay.create()
fun checkAppsInstalled() {
val whatsappObs = Observable.just(packageManagerHelper.checkAppInstalledOrNot(whatsappPackage))
val telegramObs = Observable.just(packageManagerHelper.checkAppInstalledOrNot(telegramPackage))
compositeDisposables.add(
Observable.zip(
whatsappObs,
telegramObs,
BiFunction<Boolean, Boolean, Unit> { whatsApp, telegram ->
if (whatsApp) whatsappRelay.accept(whatsApp)
if (telegram) telegramRelay.accept(telegram)
if (whatsApp || telegram) checkShowTextUnderSend.accept(true)
}).execute()
.subscribe()
)
}
fun createOpenAppIntent(packageName: String) {
openAppIntentRelay.accept(packageManagerHelper.createOpenAppIntent(packageName))
}
fun validateText(messageText: String) {
if (messageText.length >= 10) checkTextValid.accept(true) else checkTextValid.accept(false)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment