From 579a4057c69c20394f821f2112e4d62cfaab7cdb Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 13 Mar 2018 19:26:16 +0100 Subject: [PATCH] update text colors on resume if they changed --- .../clock/activities/MainActivity.kt | 2 +- .../clock/fragments/AlarmFragment.kt | 18 ++++++++++++++++++ .../clock/fragments/ClockFragment.kt | 13 +++++++++++++ .../clock/fragments/StopwatchFragment.kt | 17 +++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt index 6dc8c7f3..cea49884 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt @@ -151,7 +151,7 @@ class MainActivity : SimpleActivity() { } } - private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2).filter { it != activeIndex } + private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1, 2, 3).filter { it != activeIndex } private fun launchSettings() { startActivity(Intent(applicationContext, SettingsActivity::class.java)) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt index e4aa4d2d..8919ccbf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/AlarmFragment.kt @@ -20,9 +20,13 @@ import java.util.* class AlarmFragment : Fragment(), ToggleAlarmInterface { private var alarms = ArrayList() + + private var storedTextColor = 0 + lateinit var view: ViewGroup override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + storeStateVariables() view = inflater.inflate(R.layout.fragment_alarm, container, false) as ViewGroup return view } @@ -30,6 +34,20 @@ class AlarmFragment : Fragment(), ToggleAlarmInterface { override fun onResume() { super.onResume() setupViews() + + val configTextColor = context!!.config.textColor + if (storedTextColor != configTextColor) { + (view.alarms_list.adapter as AlarmsAdapter).updateTextColor(configTextColor) + } + } + + override fun onPause() { + super.onPause() + storeStateVariables() + } + + private fun storeStateVariables() { + storedTextColor = context!!.config.textColor } private fun setupViews() { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt index bbed4514..fc2e756e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt @@ -29,9 +29,12 @@ class ClockFragment : Fragment() { private var calendar = Calendar.getInstance() private val updateHandler = Handler() + private var storedTextColor = 0 + lateinit var view: ViewGroup override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + storeStateVariables() view = inflater.inflate(R.layout.fragment_clock, container, false) as ViewGroup return view } @@ -40,11 +43,21 @@ class ClockFragment : Fragment() { super.onResume() displayOtherTimeZones = context!!.config.displayOtherTimeZones setupDateTime() + + val configTextColor = context!!.config.textColor + if (storedTextColor != configTextColor) { + (view.time_zones_list.adapter as? TimeZonesAdapter)?.updateTextColor(configTextColor) + } } override fun onPause() { super.onPause() updateHandler.removeCallbacksAndMessages(null) + storeStateVariables() + } + + private fun storeStateVariables() { + storedTextColor = context!!.config.textColor } private fun setupDateTime() { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt index fd44e999..28f4102f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt @@ -36,10 +36,13 @@ class StopwatchFragment : Fragment() { private var sorting = SORT_BY_LAP or SORT_DESCENDING private var laps = ArrayList() + private var storedTextColor = 0 + lateinit var stopwatchAdapter: StopwatchAdapter lateinit var view: ViewGroup override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + storeStateVariables() view = (inflater.inflate(R.layout.fragment_stopwatch, container, false) as ViewGroup).apply { stopwatch_time.setOnClickListener { togglePlayPause() @@ -96,6 +99,16 @@ class StopwatchFragment : Fragment() { override fun onResume() { super.onResume() setupViews() + + val configTextColor = context!!.config.textColor + if (storedTextColor != configTextColor) { + stopwatchAdapter.updateTextColor(configTextColor) + } + } + + override fun onPause() { + super.onPause() + storeStateVariables() } override fun onDestroy() { @@ -107,6 +120,10 @@ class StopwatchFragment : Fragment() { updateHandler.removeCallbacks(updateRunnable) } + private fun storeStateVariables() { + storedTextColor = context!!.config.textColor + } + private fun setupViews() { val adjustedPrimaryColor = context!!.getAdjustedPrimaryColor() view.apply {