lets start/stop the timer on resume/pause instead of create/destroy

This commit is contained in:
tibbi 2018-03-01 21:57:09 +01:00
parent 8107901a1c
commit eeb8b29e0f

View File

@ -32,12 +32,7 @@ class ClockFragment : 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_clock, container, false) as ViewGroup view = inflater.inflate(R.layout.fragment_clock, container, false) as ViewGroup
val offset = calendar.timeZone.rawOffset setupDateTime()
passedSeconds = ((calendar.timeInMillis + offset) / 1000).toInt()
displayOtherTimeZones = context!!.config.displayOtherTimeZones
updateCurrentTime()
updateDate()
setupViews()
return view return view
} }
@ -46,17 +41,27 @@ class ClockFragment : Fragment() {
displayOtherTimeZones = context!!.config.displayOtherTimeZones displayOtherTimeZones = context!!.config.displayOtherTimeZones
if (!isFirstResume) { if (!isFirstResume) {
setupViews() setupDateTime()
} }
isFirstResume = false isFirstResume = false
} }
override fun onDestroy() { override fun onPause() {
super.onDestroy() super.onPause()
updateHandler.removeCallbacksAndMessages(null) 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() { private fun setupViews() {
view.apply { view.apply {
context!!.updateTextColors(clock_fragment) context!!.updateTextColors(clock_fragment)