Pretty much what it says on the tin, I was making the changes seen on pg. 222 when for some reason the app stops working as intended. It will open when I start running it, but the moment I click on a crime the app crashed. I tried looking through logcat but cannot find the problem spot, instead taking me to CrimeDao even though it was working fine until I got the changes in pg.222.
My code:
class CrimeDetailFragment : Fragment() {
private val args: CrimeDetailFragmentArgs by navArgs()
private lateinit var binding: FragmentCrimeDetailBinding
private val crimeDetailViewModel: CrimeDetailViewModel by viewModels{
CrimeDetailViewModelFactory(args.crimeId)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding =
FragmentCrimeDetailBinding.inflate(layoutInflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.apply {
crimeTitle.doOnTextChanged{
text,_,_,_->
}
crimeDate.apply {
isEnabled = false
}
crimeSolved.setOnCheckedChangeListener{
_, isChecked ->
}
}
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){
crimeDetailViewModel.crime.collect{ crime -> crime?.let { updateUi(it) }}
}
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun updateUi(crime: Crime){
binding.apply {
if (crimeTitle.text.toString() != crime.title){
crimeTitle.setText(crime.title)
}
crimeDate.text = crime.date.toString()
crimeSolved.isChecked = crime.isSolved
}
}
}