Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28ad798b authored by Santiago Etchebehere's avatar Santiago Etchebehere Committed by Chris Poultney
Browse files

Reuse ClockViewFactory

Bug: b/302425391
Test: manually verified that the clock carousel and setting work
Merged-In: Ic464db9d6ec5eeb8b18ee27d6a205d217228ace3
Change-Id: Ic80961096b17dbbabf5816674436b027da1fa5c1
parent 1223468b
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.customization.module

import android.app.Activity
import android.app.UiModeManager
import android.app.WallpaperManager
import android.content.Context
@@ -111,7 +112,7 @@ internal constructor(
    private var clockPickerInteractor: ClockPickerInteractor? = null
    private var clockSectionViewModel: ClockSectionViewModel? = null
    private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null
    private var clockViewFactories: MutableMap<Int, ClockViewFactory> = HashMap()
    private var clockViewFactory: ClockViewFactory? = null
    private var clockPickerSnapshotRestorer: ClockPickerSnapshotRestorer? = null
    private var notificationsInteractor: NotificationsInteractor? = null
    private var notificationSectionViewModelFactory: NotificationSectionViewModel.Factory? = null
@@ -388,8 +389,7 @@ internal constructor(
    }

    override fun getClockViewFactory(activity: ComponentActivity): ClockViewFactory {
        val activityHashCode = activity.hashCode()
        return clockViewFactories[activityHashCode]
        return clockViewFactory
            ?: ClockViewFactory(
                    activity.applicationContext,
                    ScreenSizeCalculator.getInstance()
@@ -398,13 +398,13 @@ internal constructor(
                    getClockRegistry(activity.applicationContext),
                )
                .also {
                    clockViewFactories[activityHashCode] = it
                    clockViewFactory = it
                    activity.lifecycle.addObserver(
                        object : DefaultLifecycleObserver {
                            override fun onDestroy(owner: LifecycleOwner) {
                                super.onDestroy(owner)
                                clockViewFactories[activityHashCode]?.onDestroy()
                                clockViewFactories.remove(activityHashCode)
                                if ((owner as Activity).isChangingConfigurations()) return
                                clockViewFactory?.onDestroy()
                            }
                        }
                    )