Skip to content

Commit

Permalink
fix(converter): Update output after conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed May 2, 2024
1 parent 1af4e97 commit c606328
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ class UnitsRepositoryImpl @Inject constructor(
val conversion = unitFrom.convert(unitTo, value)

ConverterResult.NumberBase(conversion)
} catch (e: Exception) {
} catch (error: Exception) {
Log.e("UnitsRepositoryImpl", "Failed to convert number base $unitFromId -> $unitToId: $error")
error.printStackTrace()
ConverterResult.Error.ConversionError
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.myzel394.numberhub.core.base.OutputFormat
import app.myzel394.numberhub.core.base.Token
import app.myzel394.numberhub.core.ui.common.textfield.getTextField
import app.myzel394.numberhub.data.common.combine
import app.myzel394.numberhub.data.common.stateIn
Expand Down Expand Up @@ -175,11 +176,13 @@ internal class ConverterViewModel @Inject constructor(
fun convertNumberBase() {
conversionJob?.cancel()
conversionJob = viewModelScope.launch {
unitsRepo.convertNumberBase(
val result = unitsRepo.convertNumberBase(
unitFromId = unitFromId.value ?: return@launch,
unitToId = unitToId.value ?: return@launch,
value = input1.value.text,
value = input1.value.text.ifEmpty { Token.Digit._0 }
)

output.update { result }
}
}

Expand Down

0 comments on commit c606328

Please sign in to comment.