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

View File

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