summaryrefslogtreecommitdiffstats
path: root/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/lifecycle/StoreLifecycleObserver.kt
blob: 212384aa1bf67f7d2a35ec0b19f1ea103a909adc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.lifecycle

import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import mozilla.components.browser.state.action.AppLifecycleAction
import mozilla.components.browser.state.store.BrowserStore
import org.mozilla.fenix.components.AppStore
import org.mozilla.fenix.components.appstate.AppAction

/**
 * [LifecycleObserver] to dispatch app lifecycle actions to the [AppStore] and [BrowserStore].
 */
class StoreLifecycleObserver(
    private val appStore: AppStore,
    private val browserStore: BrowserStore,
) : DefaultLifecycleObserver {
    override fun onPause(owner: LifecycleOwner) {
        super.onPause(owner)
        appStore.dispatch(AppAction.AppLifecycleAction.PauseAction)
        browserStore.dispatch(AppLifecycleAction.PauseAction)
    }

    override fun onResume(owner: LifecycleOwner) {
        super.onResume(owner)
        appStore.dispatch(AppAction.AppLifecycleAction.ResumeAction)
        browserStore.dispatch(AppLifecycleAction.ResumeAction)
    }
}