Skip to content

Commit

Permalink
Code for beta 5 (#26)
Browse files Browse the repository at this point in the history
* Code for beta 5

Co-authored-by: Siddharth Utgikar <siddharth.utgikar@dji.com>
  • Loading branch information
siddutgikar and Siddharth Utgikar authored Dec 22, 2020
1 parent f336fbe commit c78781e
Show file tree
Hide file tree
Showing 430 changed files with 17,449 additions and 10,578 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ before_script:
- chmod +x gradlew

script:
- ./gradlew clean build
- ./gradlew test
- travis_wait 30 ./gradlew clean build
- travis_wait 30 ./gradlew test

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You can also post questions, keep up to date on DJI developer news and contribut

## Future Plans

We are eager to give you a sneak peek, and are very interested in receiving your feedback and suggestions. Please refer to the wiki or the release notes for the full list of elements that the Beta 4 version makes available.
We are eager to give you a sneak peek, and are very interested in receiving your feedback and suggestions. Please refer to the wiki or the release notes for the full list of elements that the Beta 5 version makes available.

Our long-term plan is for this framework to reach feature parity with the current UX SDK 4.x release. The core team is currently working on porting the remaining widgets and other APIs to the new architecture and we will open source them in additional future Beta releases as they are completed. We welcome your feedback on the architecture and your ideas for additional widgets, including those not included in prior UX SDK releases, as well as your contributions and PRs for any ***currently open-sourced features***.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ android {
dependencies {
api project(path: ':android-uxsdk-beta-core')

implementation ('com.dji:dji-sdk:4.13.1', {
implementation ('com.dji:dji-sdk:4.14-trial1', {
/**
* Comment the "library-anti-distortion" if your app needs Anti Distortion for Mavic 2 Pro
* and Mavic 2 Zoom.
Expand All @@ -81,7 +81,7 @@ dependencies {
exclude module: 'library-anti-distortion'
exclude module: 'fly-safe-database'
})
compileOnly ('com.dji:dji-sdk-provided:4.13.1')
compileOnly ('com.dji:dji-sdk-provided:4.14-trial1')

implementation 'androidx.multidex:multidex:2.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
~
-->

<manifest package="dji.ux.beta.intelligentflight" />
<manifest package="dji.ux.beta.accessory" />
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/

package dji.ux.beta.hardwareaccessory.widget.rtk
package dji.ux.beta.accessory.widget.rtk

import android.annotation.SuppressLint
import android.content.Context
Expand All @@ -39,17 +39,17 @@ import dji.thirdparty.io.reactivex.Flowable
import dji.thirdparty.io.reactivex.disposables.Disposable
import dji.thirdparty.io.reactivex.functions.Consumer
import dji.thirdparty.io.reactivex.processors.PublishProcessor
import dji.ux.beta.core.base.ConstraintLayoutWidget
import dji.ux.beta.accessory.R
import dji.ux.beta.accessory.widget.rtk.RTKEnabledWidget.ModelState
import dji.ux.beta.accessory.widget.rtk.RTKEnabledWidget.ModelState.ProductConnected
import dji.ux.beta.accessory.widget.rtk.RTKEnabledWidget.ModelState.RTKEnabledUpdated
import dji.ux.beta.accessory.widget.rtk.RTKEnabledWidget.UIState.SwitchChanged
import dji.ux.beta.core.base.DJISDKModel
import dji.ux.beta.core.base.SchedulerProvider
import dji.ux.beta.core.base.uxsdkkeys.ObservableInMemoryKeyedStore
import dji.ux.beta.core.base.widget.ConstraintLayoutWidget
import dji.ux.beta.core.communication.ObservableInMemoryKeyedStore
import dji.ux.beta.core.extension.*
import dji.ux.beta.core.util.DisplayUtil
import dji.ux.beta.hardwareaccessory.R
import dji.ux.beta.hardwareaccessory.widget.rtk.RTKEnabledWidget.RTKEnabledWidgetState
import dji.ux.beta.hardwareaccessory.widget.rtk.RTKEnabledWidget.RTKEnabledWidgetState.ProductConnected
import dji.ux.beta.hardwareaccessory.widget.rtk.RTKEnabledWidget.RTKEnabledWidgetState.RTKEnabledUpdate
import dji.ux.beta.hardwareaccessory.widget.rtk.RTKEnabledWidget.RTKEnabledWidgetUIState.RTKEnabledSwitchCheckChanged

private const val TAG = "RTKEnabledWidget"

Expand All @@ -60,19 +60,18 @@ open class RTKEnabledWidget @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayoutWidget<RTKEnabledWidgetState>(context, attrs, defStyleAttr), CompoundButton.OnCheckedChangeListener {
) : ConstraintLayoutWidget<ModelState>(context, attrs, defStyleAttr), CompoundButton.OnCheckedChangeListener {

//region Fields
private val rtkTitleTextView: TextView = findViewById(R.id.textview_rtk_title)
private val rtkEnabledSwitch: Switch = findViewById(R.id.switch_rtk_enabled)
private val rtkEnabledDescriptionTextView: TextView = findViewById(R.id.textview_rtk_enabled_description)
private val uiUpdateStateProcessor: PublishProcessor<RTKEnabledWidgetUIState> = PublishProcessor.create()
private val uiUpdateStateProcessor: PublishProcessor<UIState> = PublishProcessor.create()

private val widgetModel by lazy {
RTKEnabledWidgetModel(
DJISDKModel.getInstance(),
ObservableInMemoryKeyedStore.getInstance(),
SchedulerProvider.getInstance())
ObservableInMemoryKeyedStore.getInstance())
}

/**
Expand Down Expand Up @@ -169,7 +168,7 @@ open class RTKEnabledWidget @JvmOverloads constructor(
}
//endregion

//region Constructors
//region Constructor
override fun initView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
inflate(context, R.layout.uxsdk_widget_rtk_enabled, this)
}
Expand Down Expand Up @@ -197,7 +196,7 @@ open class RTKEnabledWidget @JvmOverloads constructor(

override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
addDisposable(widgetModel.canEnableRTK.firstOrError()
.observeOn(SchedulerProvider.getInstance().ui())
.observeOn(SchedulerProvider.ui())
.subscribe(Consumer { canEnableRTK: Boolean ->
if (!canEnableRTK) {
setRTKSwitch(!isChecked)
Expand All @@ -206,29 +205,29 @@ open class RTKEnabledWidget @JvmOverloads constructor(
setRTKEnabled(isChecked)
}
}, logErrorConsumer(TAG, "canEnableRTK: ")))
uiUpdateStateProcessor.onNext(RTKEnabledSwitchCheckChanged(isChecked))
uiUpdateStateProcessor.onNext(SwitchChanged(isChecked))
}

override fun reactToModelChanges() {
addReaction(widgetModel.rtkEnabled
.observeOn(SchedulerProvider.getInstance().ui())
.observeOn(SchedulerProvider.ui())
.subscribe { updateUIForRTKEnabled(it) })
addReaction(widgetModel.productConnection
.observeOn(SchedulerProvider.getInstance().ui())
.observeOn(SchedulerProvider.ui())
.subscribe { widgetStateDataProcessor.onNext(ProductConnected(it)) })
}
//endregion

//region Reaction helpers
private fun updateUIForRTKEnabled(rtkEnabled: Boolean) {
setRTKSwitch(rtkEnabled)
widgetStateDataProcessor.onNext(RTKEnabledUpdate(rtkEnabled))
widgetStateDataProcessor.onNext(RTKEnabledUpdated(rtkEnabled))
}

private fun setRTKEnabled(enabled: Boolean) {
addDisposable(widgetModel.rtkEnabled
.firstOrError()
.observeOn(SchedulerProvider.getInstance().ui())
.observeOn(SchedulerProvider.ui())
.subscribe(Consumer { rtkEnabled: Boolean ->
if (rtkEnabled != enabled) {
addDisposable(toggleRTK(enabled))
Expand All @@ -238,7 +237,7 @@ open class RTKEnabledWidget @JvmOverloads constructor(

private fun toggleRTK(enabled: Boolean): Disposable {
return widgetModel.setRTKEnabled(enabled)
.observeOn(SchedulerProvider.getInstance().ui())
.observeOn(SchedulerProvider.ui())
.subscribe({}
) { throwable: Throwable ->
setRTKSwitch(!enabled)
Expand Down Expand Up @@ -333,42 +332,43 @@ open class RTKEnabledWidget @JvmOverloads constructor(

//region Hooks
/**
* Get the [RTKEnabledWidgetUIState] updates
* Get the [UIState] updates
*/
fun getUIStateUpdates(): Flowable<RTKEnabledWidgetUIState> {
return uiUpdateStateProcessor
fun getUIStateUpdates(): Flowable<UIState> {
return uiUpdateStateProcessor.onBackpressureBuffer()
}

/**
* Widget UI update State
*/
sealed class RTKEnabledWidgetUIState {
sealed class UIState {
/**
* RTK enabled switch check changed update
*/
data class RTKEnabledSwitchCheckChanged(val isChecked: Boolean) : RTKEnabledWidgetUIState()
data class SwitchChanged(val isChecked: Boolean) : UIState()
}

/**
* Get the [RTKEnabledWidgetState] updates
* Get the [ModelState] updates
*/
override fun getWidgetStateUpdate(): Flowable<RTKEnabledWidgetState> {
@SuppressWarnings
override fun getWidgetStateUpdate(): Flowable<ModelState> {
return super.getWidgetStateUpdate()
}

/**
* Class defines the widget state updates
*/
sealed class RTKEnabledWidgetState {
sealed class ModelState {
/**
* Product connection update
*/
data class ProductConnected(val isConnected: Boolean) : RTKEnabledWidgetState()
data class ProductConnected(val isConnected: Boolean) : ModelState()

/**
* RTK enabled update
*/
data class RTKEnabledUpdate(val isRTKEnabled: Boolean) : RTKEnabledWidgetState()
data class RTKEnabledUpdated(val isRTKEnabled: Boolean) : ModelState()
}
//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/

package dji.ux.beta.hardwareaccessory.widget.rtk
package dji.ux.beta.accessory.widget.rtk

import dji.keysdk.DJIKey
import dji.keysdk.FlightControllerKey
import dji.thirdparty.io.reactivex.Completable
import dji.thirdparty.io.reactivex.Flowable
import dji.ux.beta.core.base.DJISDKModel
import dji.ux.beta.core.base.SchedulerProviderInterface
import dji.ux.beta.core.base.WidgetModel
import dji.ux.beta.core.base.uxsdkkeys.ObservableInMemoryKeyedStore
import dji.ux.beta.core.communication.ObservableInMemoryKeyedStore
import dji.ux.beta.core.util.DataProcessor

/**
* Widget Model for the [RTKEnabledWidget] used to define
* the underlying logic and communication
*/
class RTKEnabledWidgetModel(djiSdkModel: DJISDKModel,
keyedStore: ObservableInMemoryKeyedStore,
private val schedulerProvider: SchedulerProviderInterface
class RTKEnabledWidgetModel(
djiSdkModel: DJISDKModel,
keyedStore: ObservableInMemoryKeyedStore
) : WidgetModel(djiSdkModel, keyedStore) {

//region Fields
Expand Down Expand Up @@ -90,7 +89,7 @@ class RTKEnabledWidgetModel(djiSdkModel: DJISDKModel,

//region User interaction
fun setRTKEnabled(enabled: Boolean): Completable {
return djiSdkModel.setValue(isRTKEnabledKey, enabled).subscribeOn(schedulerProvider.io())
return djiSdkModel.setValue(isRTKEnabledKey, enabled)
}
//endregion
}
Expand Down Expand Up @@ -123,15 +122,12 @@ enum class HomePointDataSourceType(@get:JvmName("value") val value: Int) {
UNKNOWN(255);

companion object {
@JvmStatic
val values = values()

@JvmStatic
fun find(value: Int): HomePointDataSourceType {
val values = values()
for (item in values) {
if (item.value == value) {
return item
}
}
return UNKNOWN
return values.find { it.value == value } ?: UNKNOWN
}
}
}
Loading

0 comments on commit c78781e

Please sign in to comment.