Added ability to include literal string in manual steps.

This commit is contained in:
Erik C. Thauvin 2017-03-02 20:32:49 -08:00
parent 24d2042454
commit 0d8dae2326
7 changed files with 81 additions and 59 deletions

View file

@ -157,9 +157,10 @@ DTMF represent the dialing sequence for the programming steps. A comma (`,`) sho
The following markers will be substituted by their actual values upon dialing.
| Marker | Description |
|:-----------|:------------------------------------------------------------------------------|
|:--------------|:------------------------------------------------------------------------------------------|
|`[MASTER]` | Substituted with the Master Code |
|`[FIELD:X]` | Substituted with the field's value, where X is the field number in the array. |
|`'Some text'` | Displays the enclosed text as a manual step. The 'nodial' [option](#options) must be set. |
#### Validation

View file

@ -74,6 +74,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
companion object {
val PAUSE = ','
val QUOTE = "'"
}
inline fun ViewManager.textInputEditText(theme: Int = 0, init: TextInputEditText.() -> Unit) = ankoView(::TextInputEditText, theme, init)
@ -424,7 +425,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
R.string.validate_missing_opts_prop,
i + 1,
"dtmf"))
} else if (fields.isEmpty()) { // fields missing
} else if (!nodial && fields.isEmpty()) { // fields missing
errors.append(getString(
R.string.validate_missing_opts_prop,
i + 1,
@ -442,7 +443,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
}
if (!Dtmf.validate(mock,
"${MainActivity.PAUSE}${params.ack}${params.alt}$blank")) {
"${MainActivity.PAUSE}${params.ack}${params.alt}$blank", nodial)) {
errors.append(getString(
R.string.validate_invalid_opts_prop,
i + 1,

View file

@ -91,6 +91,14 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
lparams(width = matchParent, height = wrapContent)
// fields
if (option.fields.isEmpty()) {
// no configurations
autofitTextView {
text = getString(R.string.no_conf_req)
typeface = Typeface.create(Typeface.DEFAULT, Typeface.ITALIC)
}.lparams(width = matchParent, height = matchParent)
} else {
val it = option.fields.iterator()
while (it.hasNext()) {
val field = it.next()
@ -151,6 +159,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
}
}
}
}
}.lparams(width = matchParent, height = matchParent)
// dialpad FAB
@ -165,7 +174,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
onClick {
if (validateFields(params.type, fields, option)) {
val dtmf = Dtmf.build(params.type, params.master, params.ack, option, fields)
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) {
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}", option.nodial)) {
val begin = if (params.begin.isNotBlank()) {
"${params.begin}${MainActivity.PAUSE}"
} else {
@ -179,7 +188,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
}
startActivity<StepsActivity>(
StepsActivity.EXTRA_STEPS to "$begin$dtmf$end".split(MainActivity.PAUSE))
StepsActivity.EXTRA_STEPS to "$begin${dtmf.replace(MainActivity.QUOTE, empty)}$end".split(MainActivity.PAUSE))
} else {
Snackbar.make(this@coordinatorLayout,
getString(R.string.error_invalid_dtmf, dtmf),
@ -212,7 +221,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
onClick {
if (validateFields(params.type, fields, option)) {
val dtmf = Dtmf.build(params.type, params.master, params.ack, option, fields)
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) {
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}", option.nodial)) {
ProgrammingActivityPermissionsDispatcher.callWithCheck(
this@ProgrammingActivity, params.phone, dtmf)
} else {

View file

@ -173,12 +173,16 @@ class Dtmf {
return option.dtmf.replaceAll(replace.toTypedArray())
}
fun validate(dtmf: String, extra: String): Boolean {
dtmf.forEach {
fun validate(dtmf: String, extra: String, nodial: Boolean): Boolean {
dtmf.split(MainActivity.PAUSE).forEach {
if (!(nodial && it.endsWith(MainActivity.QUOTE) && it.startsWith(MainActivity.QUOTE))) {
it.forEach {
if (!(it.isDigit() || it == ',' || extra.contains(it))) {
return false
}
}
}
}
return true
}

View file

@ -535,6 +535,12 @@
],
"dtmf": "*41[MASTER],[FIELD:1]*,[FIELD:2]*,[FIELD:3]*"
},
{
"title": "Delete Name",
"fields": [],
"nodial": true,
"dtmf": "*65[MASTER],'NEXT=* or ERASE=0'"
},
{
"title": "Add Name",
"fields": [

View file

@ -21,6 +21,7 @@
<string name="error_required">Required</string>
<string name="hint_master_code">Master Code</string>
<string name="hint_phone_number">Phone Number</string>
<string name="no_conf_req">No configuration required.</string>
<string name="programming_heading">PROGRAMMING</string>
<string name="title_template_step">Step <xliff:g id="step_number">%1$d</xliff:g> of <xliff:g id="steps_count">%2$d</xliff:g></string>
<string name="validate_dtmf_nopause">Missing pause between steps</string>

View file

@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-rc1'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong