static Observable<PresenterEvent> prepareActivityLogic(
            final RxBleDevice rxBleDevice,
            final UUID characteristicUuid,
            final Observable<Boolean> connectClicks,
            final Observable<Boolean> connectingClicks, // used to disconnect the device even before connection is established
            final Observable<Boolean> disconnectClicks,
            final Observable<Boolean> readClicks,
            final Observable<byte[]> writeClicks,
            final Observable<Boolean> enableNotifyClicks,
            // used to disable notifications before they were enabled (but after enable click)
            final Observable<Boolean> enablingNotifyClicks,
            final Observable<Boolean> disableNotifyClicks,
            final Observable<Boolean> enableIndicateClicks,
            // used to disable indications before they were enabled (but after enable click)
            final Observable<Boolean> enablingIndicateClicks,
            final Observable<Boolean> disableIndicateClicks
    ) {
        return connectClicks.take(1) // subscribe to connectClicks and take one (unsubscribe after)
                .flatMap(clickEvent ->
                                // on click start connecting
                                rxBleDevice.establishConnection(false)
                                        .flatMapSingle(rxBleConnection -> pairWithCharacteristic(characteristicUuid, rxBleConnection))
                                        .flatMap(connectionAndCharacteristic -> {
                                                    BluetoothGattCharacteristic characteristic = connectionAndCharacteristic.second;
                                                    RxBleConnection connection = connectionAndCharacteristic.first;
                                                    final Observable<PresenterEvent> readObservable =
                                                            setupReadingBehaviour(readClicks, characteristic, connection);

                                                    final Observable<PresenterEvent> writeObservable =
                                                            setupWritingBehaviour(writeClicks, characteristic, connection);

                                                    final Observable<PresenterEvent> notifyAndIndicateObservable =
                                                            setupNotificationAndIndicationBehaviour(connection, characteristic,
                                                                    enableNotifyClicks, enablingNotifyClicks, disableNotifyClicks,
                                                                    enableIndicateClicks, enablingIndicateClicks, disableIndicateClicks
                                                            );


                                                    // merge all events from reads, writes, notifications and indications
                                                    return Observable.merge(
                                                            readObservable,
                                                            writeObservable,
                                                            notifyAndIndicateObservable
                                                    )
                                                            // start by informing the Activity that connection is established
                                                            .startWith(new InfoEvent("Hey, connection has been established!"));
                                                }
                                        )
                                        // convenience transformer to close the connection
                                        .compose(takeUntil(connectingClicks, disconnectClicks))
                                        // in case of a connection error inform the activity
                                        .onErrorReturn(throwable -> new InfoEvent("Connection error: " + throwable))
                        // TODO: [PU] 27.02.2018 Darek, do you have any ideas on how to do it better to keep your example's ideas?
                )
                .compose(repeatAfterCompleted());

    }
Presenter class for {@link AdvancedCharacteristicOperationExampleActivity}. Prepares the logic for the activity using passed
{@link Observable}s. Contains only static methods to show a purely reactive (stateless) approach.
<p>
The contract of the class is that it subscribes to the passed Observables only if a specific functionality is possible to use.
sample/src/main/java/com/polidea/rxandroidble2/sample/example4_characteristic/advanced/Presenter.java