From eeb8b29e0f1684fc39c00b22fcfdaaa805b33ce9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 1 Mar 2018 21:57:09 +0100 Subject: [PATCH] lets start/stop the timer on resume/pause instead of create/destroy --- .../clock/fragments/ClockFragment.kt | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) 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 a73d598..bce970b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/ClockFragment.kt @@ -32,12 +32,7 @@ class ClockFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { view = inflater.inflate(R.layout.fragment_clock, container, false) as ViewGroup - val offset = calendar.timeZone.rawOffset - passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt() - displayOtherTimeZones = context!!.config.displayOtherTimeZones - updateCurrentTime() - updateDate() - setupViews() + setupDateTime() return view } @@ -46,17 +41,27 @@ class ClockFragment : Fragment() { displayOtherTimeZones = context!!.config.displayOtherTimeZones if (!isFirstResume) { - setupViews() + setupDateTime() } isFirstResume = false } - override fun onDestroy() { - super.onDestroy() + override fun onPause() { + super.onPause() updateHandler.removeCallbacksAndMessages(null) } + private fun setupDateTime() { + calendar = Calendar.getInstance() + val offset = calendar.timeZone.rawOffset + passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt() + displayOtherTimeZones = context!!.config.displayOtherTimeZones + updateCurrentTime() + updateDate() + setupViews() + } + private fun setupViews() { view.apply { context!!.updateTextColors(clock_fragment)