Fix crash on TransactionFormViewModel creation

This commit is contained in:
William Brawner 2020-09-10 17:43:37 -07:00
parent 48d6eb6b00
commit 2bce5cf601
2 changed files with 4 additions and 1 deletions

View file

@ -47,6 +47,7 @@ class TransactionFormActivity : AppCompatActivity(), CoroutineScope {
setTitle(R.string.title_add_transaction)
edit_transaction_type_expense.isChecked = true
(application as AllowanceApplication).appComponent.inject(viewModel)
viewModel.init()
launch {
val accounts = viewModel.getAccounts().toTypedArray()
setCategories()

View file

@ -20,10 +20,12 @@ class TransactionFormViewModel : ViewModel() {
@Inject
lateinit var userRepository: UserRepository
var currentUserId: Long? = null
private set
init {
//TODO: Find a better way to handle this
fun init() {
userRepository.currentUser.observeForever {
currentUserId = it?.id
}