mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
Fix colors updating on resume on main activity tabs
This commit is contained in:
@ -15,6 +15,7 @@ import com.simplemobiletools.clock.extensions.*
|
|||||||
import com.simplemobiletools.clock.helpers.*
|
import com.simplemobiletools.clock.helpers.*
|
||||||
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
|
import com.simplemobiletools.clock.interfaces.ToggleAlarmInterface
|
||||||
import com.simplemobiletools.clock.models.Alarm
|
import com.simplemobiletools.clock.models.Alarm
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
@ -26,12 +27,9 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||||||
private var alarms = ArrayList<Alarm>()
|
private var alarms = ArrayList<Alarm>()
|
||||||
private var currentEditAlarmDialog: EditAlarmDialog? = null
|
private var currentEditAlarmDialog: EditAlarmDialog? = null
|
||||||
|
|
||||||
private var storedTextColor = 0
|
|
||||||
|
|
||||||
private lateinit var binding: FragmentAlarmBinding
|
private lateinit var binding: FragmentAlarmBinding
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
storeStateVariables()
|
|
||||||
binding = FragmentAlarmBinding.inflate(inflater, container, false)
|
binding = FragmentAlarmBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
@ -39,16 +37,6 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setupViews()
|
setupViews()
|
||||||
|
|
||||||
val configTextColor = requireContext().getProperTextColor()
|
|
||||||
if (storedTextColor != configTextColor) {
|
|
||||||
(binding.alarmsList.adapter as AlarmsAdapter).updateTextColor(configTextColor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
storeStateVariables()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showSortingDialog() {
|
fun showSortingDialog() {
|
||||||
@ -57,10 +45,6 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
|
||||||
storedTextColor = requireContext().getProperTextColor()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupViews() {
|
private fun setupViews() {
|
||||||
binding.apply {
|
binding.apply {
|
||||||
requireContext().updateTextColors(alarmFragment)
|
requireContext().updateTextColors(alarmFragment)
|
||||||
@ -108,7 +92,12 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
|||||||
binding.alarmsList.adapter = this
|
binding.alarmsList.adapter = this
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as AlarmsAdapter).updateItems(alarms)
|
(currAdapter as AlarmsAdapter).apply {
|
||||||
|
updatePrimaryColor()
|
||||||
|
updateBackgroundColor(requireContext().getProperBackgroundColor())
|
||||||
|
updateTextColor(requireContext().getProperTextColor())
|
||||||
|
updateItems(alarms)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import com.simplemobiletools.clock.extensions.*
|
|||||||
import com.simplemobiletools.clock.helpers.getPassedSeconds
|
import com.simplemobiletools.clock.helpers.getPassedSeconds
|
||||||
import com.simplemobiletools.clock.models.MyTimeZone
|
import com.simplemobiletools.clock.models.MyTimeZone
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
@ -28,12 +29,9 @@ class ClockFragment : Fragment() {
|
|||||||
private var calendar = Calendar.getInstance()
|
private var calendar = Calendar.getInstance()
|
||||||
private val updateHandler = Handler()
|
private val updateHandler = Handler()
|
||||||
|
|
||||||
private var storedTextColor = 0
|
|
||||||
|
|
||||||
private lateinit var binding: FragmentClockBinding
|
private lateinit var binding: FragmentClockBinding
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
storeStateVariables()
|
|
||||||
binding = FragmentClockBinding.inflate(inflater, container, false)
|
binding = FragmentClockBinding.inflate(inflater, container, false)
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
@ -42,22 +40,12 @@ class ClockFragment : Fragment() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
setupDateTime()
|
setupDateTime()
|
||||||
|
|
||||||
val configTextColor = requireContext().getProperTextColor()
|
binding.clockDate.setTextColor(requireContext().getProperTextColor())
|
||||||
if (storedTextColor != configTextColor) {
|
|
||||||
(binding.timeZonesList.adapter as? TimeZonesAdapter)?.updateTextColor(configTextColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.clockDate.setTextColor(configTextColor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
updateHandler.removeCallbacksAndMessages(null)
|
updateHandler.removeCallbacksAndMessages(null)
|
||||||
storeStateVariables()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
|
||||||
storedTextColor = requireContext().getProperTextColor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupDateTime() {
|
private fun setupDateTime() {
|
||||||
@ -139,7 +127,12 @@ class ClockFragment : Fragment() {
|
|||||||
this@ClockFragment.binding.timeZonesList.adapter = this
|
this@ClockFragment.binding.timeZonesList.adapter = this
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as TimeZonesAdapter).updateItems(timeZones)
|
(currAdapter as TimeZonesAdapter).apply {
|
||||||
|
updatePrimaryColor()
|
||||||
|
updateBackgroundColor(requireContext().getProperBackgroundColor())
|
||||||
|
updateTextColor(requireContext().getProperTextColor())
|
||||||
|
updateItems(timeZones)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,10 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
|||||||
|
|
||||||
class StopwatchFragment : Fragment() {
|
class StopwatchFragment : Fragment() {
|
||||||
|
|
||||||
private var storedTextColor = 0
|
|
||||||
|
|
||||||
lateinit var stopwatchAdapter: StopwatchAdapter
|
lateinit var stopwatchAdapter: StopwatchAdapter
|
||||||
private lateinit var binding: FragmentStopwatchBinding
|
private lateinit var binding: FragmentStopwatchBinding
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
storeStateVariables()
|
|
||||||
val sorting = requireContext().config.stopwatchLapsSort
|
val sorting = requireContext().config.stopwatchLapsSort
|
||||||
Lap.sorting = sorting
|
Lap.sorting = sorting
|
||||||
binding = FragmentStopwatchBinding.inflate(inflater, container, false).apply {
|
binding = FragmentStopwatchBinding.inflate(inflater, container, false).apply {
|
||||||
@ -81,11 +78,6 @@ class StopwatchFragment : Fragment() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
setupViews()
|
setupViews()
|
||||||
|
|
||||||
val configTextColor = requireContext().getProperTextColor()
|
|
||||||
if (storedTextColor != configTextColor) {
|
|
||||||
stopwatchAdapter.updateTextColor(configTextColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
Stopwatch.addUpdateListener(updateListener)
|
Stopwatch.addUpdateListener(updateListener)
|
||||||
updateLaps()
|
updateLaps()
|
||||||
binding.stopwatchSortingIndicatorsHolder.beVisibleIf(Stopwatch.laps.isNotEmpty())
|
binding.stopwatchSortingIndicatorsHolder.beVisibleIf(Stopwatch.laps.isNotEmpty())
|
||||||
@ -101,14 +93,9 @@ class StopwatchFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
storeStateVariables()
|
|
||||||
Stopwatch.removeUpdateListener(updateListener)
|
Stopwatch.removeUpdateListener(updateListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
|
||||||
storedTextColor = requireContext().getProperTextColor()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupViews() {
|
private fun setupViews() {
|
||||||
val properPrimaryColor = requireContext().getProperPrimaryColor()
|
val properPrimaryColor = requireContext().getProperPrimaryColor()
|
||||||
binding.apply {
|
binding.apply {
|
||||||
@ -202,7 +189,12 @@ class StopwatchFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLaps() {
|
private fun updateLaps() {
|
||||||
stopwatchAdapter.updateItems(Stopwatch.laps)
|
stopwatchAdapter.apply {
|
||||||
|
updatePrimaryColor()
|
||||||
|
updateBackgroundColor(requireContext().getProperBackgroundColor())
|
||||||
|
updateTextColor(requireContext().getProperTextColor())
|
||||||
|
updateItems(Stopwatch.laps)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val updateListener = object : Stopwatch.UpdateListener {
|
private val updateListener = object : Stopwatch.UpdateListener {
|
||||||
|
@ -17,6 +17,7 @@ import com.simplemobiletools.clock.extensions.timerHelper
|
|||||||
import com.simplemobiletools.clock.helpers.DisabledItemChangeAnimator
|
import com.simplemobiletools.clock.helpers.DisabledItemChangeAnimator
|
||||||
import com.simplemobiletools.clock.models.Timer
|
import com.simplemobiletools.clock.models.Timer
|
||||||
import com.simplemobiletools.clock.models.TimerEvent
|
import com.simplemobiletools.clock.models.TimerEvent
|
||||||
|
import com.simplemobiletools.commons.extensions.getProperBackgroundColor
|
||||||
import com.simplemobiletools.commons.extensions.getProperTextColor
|
import com.simplemobiletools.commons.extensions.getProperTextColor
|
||||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
@ -30,7 +31,6 @@ class TimerFragment : Fragment() {
|
|||||||
private lateinit var binding: FragmentTimerBinding
|
private lateinit var binding: FragmentTimerBinding
|
||||||
private lateinit var timerAdapter: TimerAdapter
|
private lateinit var timerAdapter: TimerAdapter
|
||||||
private var timerPositionToScrollTo = INVALID_POSITION
|
private var timerPositionToScrollTo = INVALID_POSITION
|
||||||
private var storedTextColor = 0
|
|
||||||
private var currentEditAlarmDialog: EditTimerDialog? = null
|
private var currentEditAlarmDialog: EditTimerDialog? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -45,7 +45,6 @@ class TimerFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
binding = FragmentTimerBinding.inflate(inflater, container, false).apply {
|
binding = FragmentTimerBinding.inflate(inflater, container, false).apply {
|
||||||
storeStateVariables()
|
|
||||||
timersList.itemAnimator = DisabledItemChangeAnimator()
|
timersList.itemAnimator = DisabledItemChangeAnimator()
|
||||||
timerAdd.setOnClickListener {
|
timerAdd.setOnClickListener {
|
||||||
activity?.run {
|
activity?.run {
|
||||||
@ -55,7 +54,7 @@ class TimerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initAdapter()
|
initOrUpdateAdapter()
|
||||||
refreshTimers()
|
refreshTimers()
|
||||||
|
|
||||||
// the initial timer is created asynchronously at first launch, make sure we show it once created
|
// the initial timer is created asynchronously at first launch, make sure we show it once created
|
||||||
@ -68,25 +67,22 @@ class TimerFragment : Fragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initAdapter() {
|
private fun initOrUpdateAdapter() {
|
||||||
timerAdapter = TimerAdapter(requireActivity() as SimpleActivity, binding.timersList, ::refreshTimers, ::openEditTimer)
|
if (this::timerAdapter.isInitialized) {
|
||||||
binding.timersList.adapter = timerAdapter
|
timerAdapter.updatePrimaryColor()
|
||||||
|
timerAdapter.updateBackgroundColor(requireContext().getProperBackgroundColor())
|
||||||
|
timerAdapter.updateTextColor(requireContext().getProperTextColor())
|
||||||
|
} else {
|
||||||
|
timerAdapter = TimerAdapter(requireActivity() as SimpleActivity, binding.timersList, ::refreshTimers, ::openEditTimer)
|
||||||
|
binding.timersList.adapter = timerAdapter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
requireContext().updateTextColors(binding.root)
|
requireContext().updateTextColors(binding.root)
|
||||||
val configTextColor = requireContext().getProperTextColor()
|
initOrUpdateAdapter()
|
||||||
if (storedTextColor != configTextColor) {
|
refreshTimers()
|
||||||
initAdapter()
|
|
||||||
timerAdapter.updateTextColor(configTextColor)
|
|
||||||
refreshTimers()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
storeStateVariables()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshTimers(scrollToLatest: Boolean = false) {
|
private fun refreshTimers(scrollToLatest: Boolean = false) {
|
||||||
@ -106,10 +102,6 @@ class TimerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
|
||||||
storedTextColor = requireContext().getProperTextColor()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
fun onMessageEvent(event: TimerEvent.Refresh) {
|
fun onMessageEvent(event: TimerEvent.Refresh) {
|
||||||
refreshTimers()
|
refreshTimers()
|
||||||
|
Reference in New Issue
Block a user