More View <-> LiveData connection fixes

This commit is contained in:
Aidan Follestad 2018-12-07 00:27:00 -08:00
parent 3b1aae66f3
commit 8effe38a1a
4 changed files with 17 additions and 7 deletions

View file

@ -75,6 +75,10 @@ class ViewSiteActivity : AppCompatActivity() {
addObserver(statusUpdateReceiver)
}
// Populate view model with initial data
val model = intent.getSerializableExtra(KEY_SITE) as Site
viewModel.setModel(model)
// Loading
loadingProgress.observe(this, viewModel.onIsLoading())
@ -149,10 +153,6 @@ class ViewSiteActivity : AppCompatActivity() {
doneBtn.setOnClickListener {
viewModel.commit { finish() }
}
// Populate view model with initial data
val model = intent.getSerializableExtra(KEY_SITE) as Site
viewModel.setModel(model)
}
private fun setupUi() {

View file

@ -228,7 +228,7 @@ class ViewSiteViewModelTest {
text.assertValues(TEXT_CHECKS_DISABLED)
viewModel.disabled.value = false
text.assertValues("December 6, 8:35AM")
text.assertValues("December 6, 8:35 AM")
}
@Test fun getCheckIntervalMs() {

View file

@ -23,6 +23,6 @@ fun Long.formatDate(): String {
if (this <= 0) {
return "(None)"
}
val df = SimpleDateFormat("MMMM d, h:mma", Locale.getDefault())
val df = SimpleDateFormat("MMMM d, h:mm a", Locale.getDefault())
return df.format(Date(this))
}

View file

@ -38,7 +38,17 @@ inline fun <reified T> EditText.attachLiveData(
) {
// Initial value
if (T::class == String::class) {
data.value = this.text.trim().toString() as T
if (data.value != null) {
this.setText(data.value as? String)
} else {
data.value = this.text.trim().toString() as T
}
} else if (T::class == Int::class) {
if (data.value != null) {
this.setText(data.value.toString())
} else {
data.value = this.text.trim().toString().toInt() as T
}
}
// Out
if (pushOutChanges) {