Skip to content

Commit

Permalink
Optimize code and update dependency versions (#108)
Browse files Browse the repository at this point in the history
* Optimize code and update dependency versions

* Reformat code and fixed failing tests
  • Loading branch information
ellykits authored Dec 6, 2020
1 parent ca3ddba commit 9e1ba65
Show file tree
Hide file tree
Showing 44 changed files with 200 additions and 274 deletions.
11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
/captures
.externalNativeBuild
.idea/
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
*.ipr
*.iws
.idea/
.classpath
.project
bin/
Expand Down
9 changes: 4 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: "com.vanniktech.android.junit.jacoco"

buildscript {

ext.kotlin_version = '1.4.0'
ext.mockKVersion = '1.9.3'
ext.kotlin_version = '1.4.20'
ext.mockk_version = '1.10.2'
ext.room_version = "1.1.1"

repositories {
Expand All @@ -14,11 +14,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.vanniktech:gradle-android-junit-jacoco-plugin:0.15.0"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
24 changes: 13 additions & 11 deletions neat-form-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jacoco {
def properties = new Properties()
properties.load(new FileInputStream(rootProject.file("local.properties")))

version = "1.1.3"
version = "1.1.4"

android {
compileSdkVersion 29
Expand Down Expand Up @@ -70,33 +70,35 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "androidx.core:core-ktx:1.3.1"
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.appcompat:appcompat:1.2.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

api("com.nerdstone:neat-android-stepper:1.0.6") {
transitive = true
exclude group: 'androidx.appcompat', module: 'appcompat'
exclude group: 'androidx.constraintlayout', module: 'constraintlayout'
}
api 'androidx.recyclerview:recyclerview:1.1.0'
api 'com.google.android.material:material:1.3.0-alpha02'
api 'com.google.android.material:material:1.2.1'
api 'com.jakewharton.timber:timber:4.7.1'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
api 'org.jeasy:easy-rules-core:3.3.0'
api 'org.jeasy:easy-rules-mvel:3.3.0'
api 'com.google.code.gson:gson:2.8.6'
api 'com.github.chivorns:smartmaterialspinner:1.2.1'

testImplementation 'junit:junit:4.13'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation "org.robolectric:shadows-multidex:4.3.1"
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation "org.robolectric:shadows-multidex:4.4"
debugImplementation 'androidx.fragment:fragment-testing:1.2.5'

testImplementation 'androidx.test:core:1.3.0'
testImplementation "io.mockk:mockk:$mockKVersion"
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down Expand Up @@ -152,7 +154,7 @@ publishing {

pom {
name = 'Neat Form'
description = 'Build basic android UI using JSON standard. Generate repetitive views with different configurations in easy steps.'
description = 'Build basic Android UI using JSON schema. Generate repetitive views with different configurations in easy steps.'
url = 'https://github.com/ellykits/neat-form'
licenses {
license {
Expand Down
4 changes: 2 additions & 2 deletions neat-form-core/src/main/assets/sample/sample_one_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"name": "dob",
"type": "datetime_picker",
"properties": {
"hint": "Enter birth date",
"hint": "Start date",
"type": "date_picker",
"display_format": "dd/MM/yyyy"
},
Expand All @@ -233,7 +233,7 @@
"name": "time",
"type": "datetime_picker",
"properties": {
"hint": "Enter time you clocked in",
"hint": "Start time",
"type": "time_picker",
"display_format": "hh:m a"
},
Expand Down
4 changes: 2 additions & 2 deletions neat-form-core/src/main/assets/sample/sample_two_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"name": "dob",
"type": "datetime_picker",
"properties": {
"hint": "Enter birth date",
"hint": "Start date",
"type": "date_picker",
"display_format": "dd/MM/yyyy"
},
Expand All @@ -224,7 +224,7 @@
"name": "time",
"type": "datetime_picker",
"properties": {
"hint": "Enter time you clocked in",
"hint": "Start time",
"type": "time_picker",
"display_format": "hh:m a"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlin.reflect.KClass
*/
interface FormBuilder {

var formString: String?
var formString: String

val context: Context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.nerdstone.neatformcore.domain.view.NFormView
* widgets. For instances [acceptedAttributes] is a set of supported view attributes and [resourcesMap]
* is used to store styles that can be applied uniformly to this type of widget
*
*/
*/
interface ViewBuilder {

val nFormView: NFormView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class NFormViewProperty : Serializable {
@SerializedName(value = "subjects", alternate = ["binding_fields"])
var subjects: String? = null

@SerializedName(value = "dependent_calculations", alternate = ["calculation_fields", "calculations"])
@SerializedName(
value = "dependent_calculations",
alternate = ["calculation_fields", "calculations"]
)
var calculations: List<String>? = null

constructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.nerdstone.neatformcore.form.common
import com.nerdstone.neatandroidstepper.core.domain.StepperActions
import com.nerdstone.neatformcore.domain.builders.FormBuilder

interface FormActions: StepperActions {
interface FormActions : StepperActions {
var formBuilder: FormBuilder
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FormErrorDialog(context: Context) : AlertDialog(context, R.style.ErrorDial
super.onCreate(savedInstanceState)
setContentView(R.layout.form_error_dialog)
setCanceledOnTouchOutside(false)
dialogView = window!!.decorView.findViewById<View>(android.R.id.content)
dialogView = window!!.decorView.findViewById(android.R.id.content)
findViewById<Button>(R.id.error_dialog_button).setOnClickListener {
this.dismiss()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class JsonFormBuilder() : FormBuilder {
var form: NForm? = null
var fileSource: String? = null
var formDataJson: String? = null
override var formString: String? = null
override lateinit var formString: String

constructor(context: Context, fileSource: String) : this() {
this.context = context
Expand All @@ -91,9 +91,9 @@ class JsonFormBuilder() : FormBuilder {
defaultContextProvider = DefaultDispatcherProvider()
}

internal fun parseJsonForm(): NForm? {
return when {
formString.isNotNull() -> parseJson<NForm>(formString)
internal fun parseJsonForm() {
form = when {
this::formString.isInitialized && formString.isNotNull() -> parseJson<NForm>(formString)
fileSource.isNotNull() -> parseJson<NForm>(
AssetFile.readAssetFileAsString(context, fileSource!!)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.nerdstone.neatformcore.rules.RulesFactory
import com.nerdstone.neatformcore.rules.RulesFactory.RulesFileType
import com.nerdstone.neatformcore.utils.CustomExceptions
import com.nerdstone.neatformcore.utils.SingleRunner
import com.nerdstone.neatformcore.utils.isNotNull
import com.nerdstone.neatformcore.utils.updateFieldValues
import com.nerdstone.neatformcore.views.containers.VerticalRootView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

class JsonFormEmbedded(
private val jsonFormBuilder: JsonFormBuilder, private val mainLayout: ViewGroup
Expand All @@ -26,34 +24,21 @@ class JsonFormEmbedded(
fun buildForm(viewList: List<View>? = null): JsonFormEmbedded {
jsonFormBuilder.registerViews()
val context = jsonFormBuilder.context
launch(jsonFormBuilder.defaultContextProvider.main()) {
try {
if (jsonFormBuilder.form == null) {
jsonFormBuilder.form =
withContext(jsonFormBuilder.defaultContextProvider.default()) {
singleRunner.afterPrevious {
jsonFormBuilder.parseJsonForm()
}
}
val defaultContextProvider = jsonFormBuilder.defaultContextProvider
launch(defaultContextProvider.main() + CustomExceptions.coroutineExceptionHandler) {
if (jsonFormBuilder.form == null) {
singleRunner.afterPrevious(defaultContextProvider.default()) {
jsonFormBuilder.parseJsonForm()
}
}

val rulesAsync = withContext(jsonFormBuilder.defaultContextProvider.io()) {
singleRunner.afterPrevious {
jsonFormBuilder.registerFormRulesFromFile(
context,
RulesFactory.RulesFileType.YAML
)
}
}
if (rulesAsync) {
withContext(jsonFormBuilder.defaultContextProvider.main()) {
createFormViews(context, viewList ?: arrayListOf())
}
}
} catch (throwable: Throwable) {
Timber.e(throwable)
val readRules = singleRunner.afterPrevious(defaultContextProvider.io()) {
jsonFormBuilder.registerFormRulesFromFile(context, RulesFileType.YAML)
}

if (readRules) createFormViews(context, viewList ?: arrayListOf())
}

jsonFormBuilder.preFillForm()
return this
}
Expand All @@ -62,13 +47,12 @@ class JsonFormEmbedded(
if (jsonFormBuilder.form.isNotNull() && mainLayout.isNotNull()) {
val formViews = ScrollView(context)
jsonFormBuilder.form!!.steps.withIndex().forEach { (index, formContent) ->
val rootView =
VerticalRootView(context).apply { formBuilder = jsonFormBuilder }
val rootView = VerticalRootView(context).apply { formBuilder = jsonFormBuilder }
formViews.addView(rootView.initRootView(jsonFormBuilder) as View)
jsonFormBuilder.addViewsToVerticalRootView(views, index, formContent, rootView)
}
mainLayout.addView(formViews)
jsonFormBuilder.dataViewModel.details.observe(context as LifecycleOwner, Observer {
jsonFormBuilder.dataViewModel.details.observe(context as LifecycleOwner, {
context.updateFieldValues(it, jsonFormBuilder.readOnlyFields)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import com.nerdstone.neatandroidstepper.core.model.StepModel
import com.nerdstone.neatandroidstepper.core.stepper.Step
import com.nerdstone.neatandroidstepper.core.stepper.StepVerificationState
import com.nerdstone.neatandroidstepper.core.stepper.StepperPagerAdapter
import com.nerdstone.neatandroidstepper.core.widget.NeatStepperLayout
import com.nerdstone.neatformcore.form.common.FormActions
import com.nerdstone.neatformcore.rules.RulesFactory
import com.nerdstone.neatformcore.rules.RulesFactory.RulesFileType
import com.nerdstone.neatformcore.utils.CustomExceptions
import com.nerdstone.neatformcore.utils.SingleRunner
import com.nerdstone.neatformcore.utils.isNotNull
import com.nerdstone.neatformcore.utils.updateFieldValues
Expand All @@ -23,8 +23,6 @@ import com.nerdstone.neatformcore.views.containers.VerticalRootView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

class JsonFormStepper(
private val jsonFormBuilder: JsonFormBuilder, private val neatStepperLayout: NeatStepperLayout
Expand All @@ -35,34 +33,22 @@ class JsonFormStepper(
fun buildForm(viewList: List<View>? = null): JsonFormStepper {
jsonFormBuilder.registerViews()
val defaultContextProvider = jsonFormBuilder.defaultContextProvider
launch(defaultContextProvider.main()) {
try {
if (jsonFormBuilder.form == null) {
jsonFormBuilder.form = withContext(defaultContextProvider.default()) {
singleRunner.afterPrevious {
jsonFormBuilder.parseJsonForm()
}
}
}

val rulesAsync = withContext(defaultContextProvider.io()) {
singleRunner.afterPrevious {
jsonFormBuilder.registerFormRulesFromFile(
jsonFormBuilder.context,
RulesFactory.RulesFileType.YAML
)
}
}
if (rulesAsync) {
withContext(defaultContextProvider.main()) {
createFormViews(jsonFormBuilder.context, viewList ?: arrayListOf())
}
launch(defaultContextProvider.main() + CustomExceptions.coroutineExceptionHandler) {
if (jsonFormBuilder.form == null) {
singleRunner.afterPrevious(defaultContextProvider.default()) {
jsonFormBuilder.parseJsonForm()
}
}

} catch (throwable: Throwable) {
Timber.e(throwable)
val readRules = singleRunner.afterPrevious(defaultContextProvider.io()) {
jsonFormBuilder.registerFormRulesFromFile(
jsonFormBuilder.context, RulesFileType.YAML
)
}

if (readRules) createFormViews(jsonFormBuilder.context, viewList ?: arrayListOf())
}

jsonFormBuilder.preFillForm()
return this
}
Expand Down Expand Up @@ -153,7 +139,7 @@ class StepFragment : Step {
super.onActivityCreated(savedInstanceState)
dataViewModel = (activity as FormActions).formBuilder.dataViewModel
with(dataViewModel) {
details.observe(viewLifecycleOwner, Observer {
details.observe(viewLifecycleOwner, {
(activity as Context).updateFieldValues(it, mutableSetOf())
})
}
Expand Down
Loading

0 comments on commit 9e1ba65

Please sign in to comment.