mirror of
https://github.com/afollestad/nock-nock.git
synced 2025-08-03 14:48:39 +00:00
Fix a crash
This commit is contained in:
parent
6daebe46eb
commit
19f58ef2e6
3 changed files with 35 additions and 3 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -5,7 +5,7 @@
|
||||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
||||||
</configurations>
|
</configurations>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Designed and developed by Aidan Follestad (@afollestad)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.afollestad.nocknock.viewcomponents.ext
|
||||||
|
|
||||||
|
fun String?.asSafeInt(defaultValue: Int = 0): Int {
|
||||||
|
if (this == null || this.trim().isEmpty()) {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return this.toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String?.asSafeLong(defaultValue: Long = 0): Long {
|
||||||
|
if (this == null || this.trim().isEmpty()) {
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
|
return this.toLong()
|
||||||
|
}
|
|
@ -26,6 +26,8 @@ import androidx.lifecycle.Observer
|
||||||
import com.afollestad.nocknock.utilities.ext.onTextChanged
|
import com.afollestad.nocknock.utilities.ext.onTextChanged
|
||||||
import com.afollestad.nocknock.utilities.ext.setTextAndMaintainSelection
|
import com.afollestad.nocknock.utilities.ext.setTextAndMaintainSelection
|
||||||
import com.afollestad.nocknock.utilities.livedata.distinct
|
import com.afollestad.nocknock.utilities.livedata.distinct
|
||||||
|
import com.afollestad.nocknock.viewcomponents.ext.asSafeInt
|
||||||
|
import com.afollestad.nocknock.viewcomponents.ext.asSafeLong
|
||||||
import com.afollestad.nocknock.viewcomponents.ext.onItemSelected
|
import com.afollestad.nocknock.viewcomponents.ext.onItemSelected
|
||||||
import com.afollestad.nocknock.viewcomponents.ext.showOrHide
|
import com.afollestad.nocknock.viewcomponents.ext.showOrHide
|
||||||
|
|
||||||
|
@ -54,10 +56,10 @@ inline fun <reified T> EditText.attachLiveData(
|
||||||
if (pushOutChanges) {
|
if (pushOutChanges) {
|
||||||
when {
|
when {
|
||||||
T::class == Int::class -> {
|
T::class == Int::class -> {
|
||||||
onTextChanged(debounce) { data.postValue(it.trim().toInt() as T) }
|
onTextChanged(debounce) { data.postValue(it.asSafeInt() as T) }
|
||||||
}
|
}
|
||||||
T::class == Long::class -> {
|
T::class == Long::class -> {
|
||||||
onTextChanged(debounce) { data.postValue(it.trim().toLong() as T) }
|
onTextChanged(debounce) { data.postValue(it.asSafeLong() as T) }
|
||||||
}
|
}
|
||||||
T::class == String::class -> {
|
T::class == String::class -> {
|
||||||
onTextChanged(debounce) { data.postValue(it as T) }
|
onTextChanged(debounce) { data.postValue(it as T) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue