Added ability to include literal string in manual steps.
This commit is contained in:
parent
24d2042454
commit
0d8dae2326
7 changed files with 81 additions and 59 deletions
|
@ -156,10 +156,11 @@ 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. |
|
||||
| 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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -91,63 +91,72 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
|
|||
lparams(width = matchParent, height = wrapContent)
|
||||
|
||||
// fields
|
||||
val it = option.fields.iterator()
|
||||
while (it.hasNext()) {
|
||||
val field = it.next()
|
||||
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)
|
||||
|
||||
textInputLayout {
|
||||
horizontalPadding = dip(40)
|
||||
lparams(width = matchParent)
|
||||
} else {
|
||||
val it = option.fields.iterator()
|
||||
while (it.hasNext()) {
|
||||
val field = it.next()
|
||||
|
||||
val inputFilters: ArrayList<InputFilter> = ArrayList()
|
||||
textInputLayout {
|
||||
horizontalPadding = dip(40)
|
||||
lparams(width = matchParent)
|
||||
|
||||
val editText = textInputEditText() {
|
||||
hint = field!!.hint
|
||||
val inputFilters: ArrayList<InputFilter> = ArrayList()
|
||||
|
||||
if (field.alpha) {
|
||||
if (params.type.isDKS()) {
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
|
||||
inputFilters.add(AlphaFilter(Dtmf.DKS_EXTRAS))
|
||||
} else if (params.type.isLinear()) {
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_WORDS
|
||||
inputFilters.add(AlphaFilter(Dtmf.LINEAR_EXTRAS))
|
||||
val editText = textInputEditText() {
|
||||
hint = field!!.hint
|
||||
|
||||
if (field.alpha) {
|
||||
if (params.type.isDKS()) {
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
|
||||
inputFilters.add(AlphaFilter(Dtmf.DKS_EXTRAS))
|
||||
} else if (params.type.isLinear()) {
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_WORDS
|
||||
inputFilters.add(AlphaFilter(Dtmf.LINEAR_EXTRAS))
|
||||
}
|
||||
} else {
|
||||
inputType = InputType.TYPE_CLASS_PHONE
|
||||
inputFilters.add(NumberFilter(field.digits, if (field.alt) params.alt else empty))
|
||||
if (field.max != -1 && field.min != -1) {
|
||||
inputFilters.add(
|
||||
MinMaxFilter(
|
||||
field.min,
|
||||
field.max,
|
||||
field.size,
|
||||
params.type.isDKS() || field.zeros))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inputType = InputType.TYPE_CLASS_PHONE
|
||||
inputFilters.add(NumberFilter(field.digits, if (field.alt) params.alt else empty))
|
||||
if (field.max != -1 && field.min != -1) {
|
||||
inputFilters.add(
|
||||
MinMaxFilter(
|
||||
field.min,
|
||||
field.max,
|
||||
field.size,
|
||||
params.type.isDKS() || field.zeros))
|
||||
|
||||
if (field.size != -1) {
|
||||
inputFilters.add(InputFilter.LengthFilter(field.size))
|
||||
}
|
||||
}
|
||||
|
||||
if (field.size != -1) {
|
||||
inputFilters.add(InputFilter.LengthFilter(field.size))
|
||||
}
|
||||
if (inputFilters.isNotEmpty()) {
|
||||
filters = inputFilters.toTypedArray()
|
||||
}
|
||||
|
||||
if (inputFilters.isNotEmpty()) {
|
||||
filters = inputFilters.toTypedArray()
|
||||
}
|
||||
|
||||
if (!it.hasNext()) {
|
||||
imeOptions = EditorInfo.IME_ACTION_DONE
|
||||
setOnEditorActionListener { v, id, event ->
|
||||
if (id == EditorInfo.IME_ACTION_DONE) {
|
||||
clearFocus()
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(windowToken, 0)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
if (!it.hasNext()) {
|
||||
imeOptions = EditorInfo.IME_ACTION_DONE
|
||||
setOnEditorActionListener { v, id, event ->
|
||||
if (id == EditorInfo.IME_ACTION_DONE) {
|
||||
clearFocus()
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(windowToken, 0)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fields.add(editText)
|
||||
}
|
||||
fields.add(editText)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
|
|
@ -173,10 +173,14 @@ class Dtmf {
|
|||
return option.dtmf.replaceAll(replace.toTypedArray())
|
||||
}
|
||||
|
||||
fun validate(dtmf: String, extra: String): Boolean {
|
||||
dtmf.forEach {
|
||||
if (!(it.isDigit() || it == ',' || extra.contains(it))) {
|
||||
return false
|
||||
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
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue