lets start/stop the timer on resume/pause instead of create/destroy
This commit is contained in:
parent
8107901a1c
commit
eeb8b29e0f
1 changed files with 14 additions and 9 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue