2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-05 21:20:45 +00:00

fixes #22943: update androidx.lifecycle to 2.4.0

This commit is contained in:
Matt Tighe 2021-12-21 18:14:33 -08:00 committed by Jonathan Almeida
parent 7d0fae8450
commit 0b99c2e67d
12 changed files with 42 additions and 58 deletions

View File

@ -38,7 +38,7 @@ class StoreProviderFactory<T : Store<*, *>>(
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <VM : ViewModel?> create(modelClass: Class<VM>): VM {
override fun <VM : ViewModel> create(modelClass: Class<VM>): VM {
return StoreProvider(createStore()) as VM
}
}

View File

@ -5,9 +5,9 @@
package org.mozilla.fenix.components.metrics
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import mozilla.components.concept.base.crash.Breadcrumb
@ -23,15 +23,13 @@ class BreadcrumbsRecorder(
private val crashReporter: CrashReporter,
private val navController: NavController,
private val getBreadcrumbMessage: (NavDestination) -> String
) : NavController.OnDestinationChangedListener, LifecycleObserver {
) : NavController.OnDestinationChangedListener, DefaultLifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
fun onCreate() {
override fun onCreate(owner: LifecycleOwner) {
navController.addOnDestinationChangedListener(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
override fun onDestroy(owner: LifecycleOwner) {
navController.removeOnDestinationChangedListener(this)
}

View File

@ -15,9 +15,8 @@ import androidx.core.app.NotificationCompat.BADGE_ICON_NONE
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.state.ExternalAppType
import mozilla.components.browser.state.store.BrowserStore
@ -32,18 +31,16 @@ class PoweredByNotification(
private val applicationContext: Context,
private val store: BrowserStore,
private val customTabId: String
) : LifecycleObserver {
) : DefaultLifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun onResume() {
override fun onResume(owner: LifecycleOwner) {
if (store.state.findCustomTab(customTabId)?.config?.externalAppType === ExternalAppType.TRUSTED_WEB_ACTIVITY) {
NotificationManagerCompat.from(applicationContext)
.notify(applicationContext, NOTIFICATION_TAG, buildNotification())
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun onPause() {
override fun onPause(owner: LifecycleOwner) {
NotificationManagerCompat.from(applicationContext)
.cancel(applicationContext, NOTIFICATION_TAG)
}

View File

@ -5,9 +5,8 @@
package org.mozilla.fenix.library.bookmarks
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import org.mozilla.fenix.R
@ -16,15 +15,13 @@ class BookmarkDeselectNavigationListener(
private val navController: NavController,
private val viewModel: BookmarksSharedViewModel,
private val bookmarkInteractor: BookmarkViewInteractor
) : NavController.OnDestinationChangedListener, LifecycleObserver {
) : NavController.OnDestinationChangedListener, DefaultLifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun onResume() {
override fun onResume(owner: LifecycleOwner) {
navController.addOnDestinationChangedListener(this)
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun onDestroy() {
override fun onDestroy(owner: LifecycleOwner) {
navController.removeOnDestinationChangedListener(this)
}

View File

@ -5,24 +5,19 @@
package org.mozilla.fenix.settings
import android.content.SharedPreferences
import androidx.lifecycle.Lifecycle.Event.ON_CREATE
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
class OnSharedPreferenceChangeListener(
private val sharedPreferences: SharedPreferences,
private val listener: (SharedPreferences, String) -> Unit
) : SharedPreferences.OnSharedPreferenceChangeListener, LifecycleObserver {
) : SharedPreferences.OnSharedPreferenceChangeListener, DefaultLifecycleObserver {
@OnLifecycleEvent(ON_CREATE)
fun onCreate() {
override fun onCreate(owner: LifecycleOwner) {
sharedPreferences.registerOnSharedPreferenceChangeListener(this)
}
@OnLifecycleEvent(ON_DESTROY)
fun onDestroy() {
override fun onDestroy(owner: LifecycleOwner) {
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
}

View File

@ -6,9 +6,8 @@ package org.mozilla.fenix.settings.about
import android.view.View
import android.widget.Toast
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import org.mozilla.fenix.R
import org.mozilla.fenix.utils.Settings
@ -18,7 +17,7 @@ import org.mozilla.fenix.utils.Settings
class SecretDebugMenuTrigger(
logoView: View,
private val settings: Settings
) : View.OnClickListener, LifecycleObserver {
) : View.OnClickListener, DefaultLifecycleObserver {
private var secretDebugMenuClicks = 0
private var lastDebugMenuToast: Toast? = null
@ -32,8 +31,7 @@ class SecretDebugMenuTrigger(
/**
* Reset the [secretDebugMenuClicks] counter.
*/
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun clearClickCounter() {
override fun onResume(owner: LifecycleOwner) {
secretDebugMenuClicks = 0
}

View File

@ -4,9 +4,9 @@
package org.mozilla.fenix.telemetry
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.LifecycleOwner
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.base.android.Clock
import org.mozilla.fenix.GleanMetrics.EngineTab as EngineMetrics
@ -22,16 +22,14 @@ import org.mozilla.fenix.GleanMetrics.EngineTab.foregroundMetricsKeys as Metrics
*/
class TelemetryLifecycleObserver(
private val store: BrowserStore
) : LifecycleObserver {
) : DefaultLifecycleObserver {
private var pausedState: TabState? = null
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun onPause() {
override fun onPause(owner: LifecycleOwner) {
pausedState = createTabState()
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun onResume() {
override fun onResume(owner: LifecycleOwner) {
val lastState = pausedState ?: return
val currentState = createTabState()

View File

@ -30,7 +30,7 @@ class PoweredByNotificationTest {
)
val feature = PoweredByNotification(testContext, store, "session-id")
feature.onResume()
feature.onResume(mockk())
}
@Test
@ -45,12 +45,12 @@ class PoweredByNotificationTest {
)
val feature = PoweredByNotification(testContext, store, "session-id")
feature.onResume()
feature.onResume(mockk())
}
@Test
fun `unregister receiver on pause`() {
val feature = PoweredByNotification(testContext, mockk(), "session-id")
feature.onPause()
feature.onPause(mockk())
}
}

View File

@ -36,10 +36,10 @@ class BookmarkDeselectNavigationListenerTest {
val navController: NavController = mockk(relaxed = true)
val listener = BookmarkDeselectNavigationListener(navController, mockk(), mockk())
listener.onResume()
listener.onResume(mockk())
verify { navController.addOnDestinationChangedListener(listener) }
listener.onDestroy()
listener.onDestroy(mockk())
verify { navController.removeOnDestinationChangedListener(listener) }
}

View File

@ -13,6 +13,7 @@ import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.slot
import io.mockk.unmockkStatic
@ -78,7 +79,7 @@ class SecretDebugMenuTriggerTest {
val trigger = SecretDebugMenuTrigger(logoView, settings)
clickListener.captured.onClick(logoView)
trigger.clearClickCounter()
trigger.onResume(mockk())
clickListener.captured.onClick(logoView)

View File

@ -47,7 +47,7 @@ class TelemetryLifecycleObserverTest {
fun `resume without a pause does not record any metrics`() {
val store = BrowserStore()
val observer = TelemetryLifecycleObserver(store)
observer.onResume()
observer.onResume(mockk())
assertFalse(EngineMetrics.foregroundMetrics.testHasValue())
}
@ -57,11 +57,11 @@ class TelemetryLifecycleObserverTest {
val store = BrowserStore()
val observer = TelemetryLifecycleObserver(store)
observer.onPause()
observer.onPause(mockk())
clock.elapsedTime = 550
observer.onResume()
observer.onResume(mockk())
assertTrue(EngineMetrics.foregroundMetrics.testHasValue())
@ -92,7 +92,7 @@ class TelemetryLifecycleObserverTest {
clock.elapsedTime = 120
observer.onPause()
observer.onPause(mockk())
store.dispatch(
EngineAction.KillEngineSessionAction("theverge")
@ -104,7 +104,7 @@ class TelemetryLifecycleObserverTest {
clock.elapsedTime = 10340
observer.onResume()
observer.onResume(mockk())
assertTrue(EngineMetrics.foregroundMetrics.testHasValue())

View File

@ -30,7 +30,7 @@ object Versions {
const val androidx_preference = "1.1.1"
const val androidx_legacy = "1.0.0"
const val androidx_annotation = "1.1.0"
const val androidx_lifecycle = "2.2.0"
const val androidx_lifecycle = "2.4.0"
const val androidx_fragment = "1.3.4"
const val androidx_navigation = "2.3.3"
const val androidx_recyclerview = "1.2.1"