Fix crash when mremoving headers, resolves #48

This commit is contained in:
Aidan Follestad 2019-04-18 17:36:49 -07:00
parent a6670e2bea
commit 82c1a17c68
3 changed files with 21 additions and 11 deletions

View file

@ -8,7 +8,7 @@ android:
- build-tools-28.0.3
- android-24
- android-28
- sys-img-arm64-v8a-android-24
- sys-img-armeabi-v7a-android-24
licenses:
- '.+'
@ -21,7 +21,7 @@ env:
# Emulator Management: Create, Start and Wait
before_script:
- android list target
- echo no | android create avd --force -n test -t android-24 --abi default/arm64-v8a
- echo no | android create avd --force -n test -t android-24 --abi default/armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

View file

@ -55,8 +55,7 @@ abstract class DarkModeSwitchActivity : AppCompatActivity() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
return UNKNOWN
}
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return when (currentNightMode) {
return when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> return ENABLED
Configuration.UI_MODE_NIGHT_NO -> return DISABLED
else -> UNKNOWN

View file

@ -56,9 +56,22 @@ class HeaderStackLayout(
override fun onClick(v: View) {
val index = v.tag as Int
list.removeViewAt(index)
headers.removeAt(index)
postLiveData()
check(index >= 0 || index < list.childCount) {
"Index $index is out of bounds in the header stack (size ${list.childCount})."
}
list.post {
list.removeViewAt(index)
headers.removeAt(index)
invalidateTags()
postLiveData()
}
}
private fun invalidateTags() {
for (i in 0 until list.childCount) {
val entry = list.getChildAt(i) as HeaderItemLayout
entry.btnRemove.tag = i
}
}
private fun addEntry(forHeader: Header) {
@ -67,9 +80,7 @@ class HeaderStackLayout(
val li = LayoutInflater.from(context)
val entry = li.inflate(R.layout.header_stack_item, list, false) as HeaderItemLayout
list.addView(entry)
entry.run {
list.addView(entry.apply {
inputKey.setText(forHeader.key)
inputKey.post { entry.inputKey.requestFocus() }
attachHeader(forHeader, this@HeaderStackLayout)
@ -77,6 +88,6 @@ class HeaderStackLayout(
btnRemove.tag = headers.size - 1
btnRemove.setOnClickListener(this@HeaderStackLayout)
}
})
}
}