/NoccaVentilator

Ventilator Operating App made for Nocca Robotics. In wake of Covid 19, this my small contribution.

Primary LanguageKotlin

NoccaVentilator

Design

android zeplin

showcase

Code Design

| Backend | <=> | Rx functional API | <=> | Frontend |

Backend is assunmed to be asyncronous therefore not safe to call directly from UI main thread.

Rx functional api will bridge this async bridge with awesome thread management.

How to create these Rx API

It's quite simple you just have to follow following syntax

let someObservable get() = Observable.create<String> {
    let listener = backendCall( { result ->
        it.onNext(result)
    })
    it.setCancellable { listener.release() } // this may/may not be used
}.apply {
    subscribeOn(Schedulers.io())
    observeOn(AndroidSchedulers.mainThread())
}

Since this app backend will implement connection protocal(USB connection), therefore, lifecycle aware backend may be required, hence Single Activity Architecture.

HolderActivity & BaseActivity

HolderActivity extends BaseActivity for better readiblity purposes. For view related code use HolderActivity and for backend related code use BaseActivity. All of HolderActivity life-cycle call is also passed to BaseActivity as well.

onCreate

If you want to initialise 3rd party sdk or establish device backend connection do it here

onDestroy

Release and clean all of resources like realtime listener or socket connection here.

BaseFragment

This is abstract fragment which expect val title to be implemented

val title: get()

which is used as title shown by activity while showing this fragment.

onViewCreated

Here you should subscribe to api observable and pass value to handler and update view using runOnActive handler. e.g.:

someObservable.subscribe { string ->
  runOnActive {
    someView.text = string
  }
}