(Hopefully) fix crash due to accessing viewModel in fragment not attached to activity
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
02363d9940
commit
a88eeb79e4
1 changed files with 9 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.wbrawner.simplemarkdown.view.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import android.os.Bundle
|
||||
|
@ -57,12 +58,16 @@ class PreviewFragment : Fragment(), CoroutineScope {
|
|||
}
|
||||
}
|
||||
style = String.format(FORMAT_CSS, css ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
updateWebContent(viewModel.markdownUpdates.value ?: "")
|
||||
viewModel.markdownUpdates.observe(viewLifecycleOwner, Observer {
|
||||
updateWebContent(it)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateWebContent(markdown: String) {
|
||||
markdownPreview?.post {
|
||||
|
|
Loading…
Reference in a new issue