Skip to content

Commit a778474

Browse files
authored
Merge pull request #6 from testica/release/1.0.1
Release/1.0.1
2 parents 2f49b5c + 9abf341 commit a778474

5 files changed

Lines changed: 14 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# CHANGELOG
22

3+
## [1.0.1] - 2019-03-26
4+
### Fixes
5+
- Prevent timer execution crash from custom TextWatcher
6+
37
## [1.0.0] - 2019-03-20
48
- Add first stable version

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Include into the build.gradle file:
1919

2020
```groovy
2121
dependencies {
22-
implementation 'me.testica:codeeditor:1.0.0'
22+
implementation 'me.testica:codeeditor:1.0.1'
2323
}
2424
```
2525
## Usage

codeeditor/src/main/java/me/testica/codeeditor/EditorText.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EditorText(context: Context, attrs: AttributeSet): EditText(context, attrs
5050
// TODO: getColor is deprecated
5151
setBackgroundColor(resources.getColor(android.R.color.transparent))
5252

53-
delayedTextChanged { applySyntaxHighlight() }
53+
addTextChangedListener(afterTextChanged { applySyntaxHighlight() })
5454
}
5555

5656
/**

codeeditor/src/main/java/me/testica/codeeditor/Util.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.text.Editable
55
import android.text.TextWatcher
66
import android.text.style.ForegroundColorSpan
7-
import java.util.*
87

98

109
/**
@@ -15,26 +14,16 @@ fun Int.toDp(context: Context): Int {
1514
}
1615

1716
/**
18-
* Extension TextChangedListener but with delay (1 second)
19-
* @param predicate editable emitted after text changed
17+
* Return TextWatcher object with listener on afterTextChanged
18+
* @param predicate void
2019
*/
21-
fun EditorText.delayedTextChanged(predicate: ((Editable?) -> Unit)) {
22-
val ms: Long = 1000
23-
var timer : Timer? = null
20+
fun afterTextChanged(predicate: (() -> Unit)): TextWatcher {
2421

25-
this.addTextChangedListener(object : TextWatcher {
22+
return object : TextWatcher {
2623
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
2724
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
28-
override fun afterTextChanged(s: Editable?) {
29-
if (timer != null) timer!!.cancel()
30-
timer = Timer()
31-
timer!!.schedule(object : TimerTask() {
32-
override fun run() {
33-
predicate.invoke(s)
34-
}
35-
}, ms)
36-
}
37-
})
25+
override fun afterTextChanged(s: Editable?) { predicate.invoke() }
26+
}
3827
}
3928

4029
/**

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ _desc = Code editor android library (custom syntax highlighting, number lines, e
2323
_website = https://github.com/testica/codeeditor
2424

2525
# Project variables
26-
_versionCode = 1
27-
_versionName = 1.0.0
26+
_versionCode = 2
27+
_versionName = 1.0.1
2828
_minSdkVersion = 15
2929
_targetSdkVersion = 28
3030

0 commit comments

Comments
 (0)