Recreate adapter when text color changes so it updates correctly

This commit is contained in:
Paul Akhamiogu 2021-09-10 22:29:33 +01:00
parent b98d9c9e42
commit eee6565d72
1 changed files with 10 additions and 8 deletions

View File

@ -45,31 +45,33 @@ class TimerFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
view = (inflater.inflate(R.layout.fragment_timer, container, false) as ViewGroup).apply {
timerAdapter = TimerAdapter(requireActivity() as SimpleActivity, timers_list, ::refreshTimers, ::openEditTimer)
storeStateVariables()
timers_list.adapter = timerAdapter
timers_list.itemAnimator = DisabledItemChangeAnimator()
timer_add.setOnClickListener {
activity?.run {
hideKeyboard()
openEditTimer(createNewTimer())
}
}
refreshTimers()
}
initAdapter()
refreshTimers()
return view
}
private fun initAdapter() {
timerAdapter = TimerAdapter(requireActivity() as SimpleActivity, view.timers_list, ::refreshTimers, ::openEditTimer)
view.timers_list.adapter = timerAdapter
}
override fun onResume() {
super.onResume()
requireContext().updateTextColors(timer_fragment)
val configTextColor = requireContext().config.textColor
if (storedTextColor != configTextColor) {
(view.timers_list.adapter as TimerAdapter).updateTextColor(configTextColor)
initAdapter()
timerAdapter.updateTextColor(configTextColor)
refreshTimers()
}
}