-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ErrorBanner): offline banner (#478)
* feat(ErrorBanner): offline banner * address PR feedback
- Loading branch information
1 parent
ceea4b5
commit 10d2bad
Showing
18 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
iosApp/iosAppTests/ViewModels/ErrorBannerViewModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// ErrorBannerViewModelTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Kayla Brady on 10/18/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import iosApp | ||
import shared | ||
import XCTest | ||
|
||
final class ErrorBannerViewModelTests: XCTestCase { | ||
func testActivateSubscribesToNetworkChanges() async { | ||
let onSubscribeExp = XCTestExpectation(description: "onSubscribe called") | ||
let repo = MockErrorBannerStateRepository(state: nil, onSubscribeToNetworkChanges: { onSubscribeExp.fulfill() }) | ||
let errorVM = ErrorBannerViewModel( | ||
errorRepository: repo, | ||
initialLoadingWhenPredictionsStale: false, | ||
skipListeningForStateChanges: true | ||
) | ||
await errorVM.activate() | ||
wait(for: [onSubscribeExp], timeout: 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/PlatformModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.mbta.tid.mbta_app | ||
|
||
import com.mbta.tid.mbta_app.network.INetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.network.NetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.utils.AndroidSystemPaths | ||
import com.mbta.tid.mbta_app.utils.SystemPaths | ||
import org.koin.dsl.module | ||
|
||
fun platformModule() = module { | ||
includes( | ||
module { single { createDataStore(get()) } }, | ||
module { single<SystemPaths> { AndroidSystemPaths(get()) } } | ||
module { single<SystemPaths> { AndroidSystemPaths(get()) } }, | ||
module { single<INetworkConnectivityMonitor> { NetworkConnectivityMonitor(get()) } } | ||
) | ||
} |
33 changes: 33 additions & 0 deletions
33
shared/src/androidMain/kotlin/com/mbta/tid/mbta_app/network/NetworkConnectivityMonitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mbta.tid.mbta_app.network | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.Context.CONNECTIVITY_SERVICE | ||
import android.net.ConnectivityManager | ||
import android.net.Network | ||
|
||
class NetworkConnectivityMonitor(context: Context) : INetworkConnectivityMonitor { | ||
private var networkCallback: ConnectivityManager.NetworkCallback? = null | ||
private val connectivityManager = | ||
context.getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager | ||
|
||
@SuppressLint("MissingPermission") | ||
// Permission is included in AndroidManifest.xml | ||
override fun registerListener(onNetworkAvailable: () -> Unit, onNetworkLost: () -> Unit) { | ||
networkCallback = | ||
object : ConnectivityManager.NetworkCallback() { | ||
override fun onAvailable(network: Network) { | ||
onNetworkAvailable() | ||
} | ||
|
||
override fun onUnavailable() { | ||
onNetworkLost() | ||
} | ||
|
||
override fun onLost(network: Network) { | ||
onNetworkLost() | ||
} | ||
} | ||
networkCallback?.let { connectivityManager.registerDefaultNetworkCallback(it) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
shared/src/commonMain/kotlin/com/mbta/tid/mbta_app/network/NetworkConnectivityMonitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mbta.tid.mbta_app.network | ||
|
||
/** Observe changes in the device's network connectivity. */ | ||
interface INetworkConnectivityMonitor { | ||
fun registerListener(onNetworkAvailable: () -> Unit, onNetworkLost: () -> Unit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
shared/src/iosMain/kotlin/com/mbta/tid/mbta_app/PlatformModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.mbta.tid.mbta_app | ||
|
||
import com.mbta.tid.mbta_app.network.INetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.network.NetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.utils.IOSSystemPaths | ||
import com.mbta.tid.mbta_app.utils.SystemPaths | ||
import org.koin.dsl.module | ||
|
||
fun platformModule() = module { | ||
includes( | ||
module { single { createDataStore() } }, | ||
module { single<SystemPaths> { IOSSystemPaths() } } | ||
module { single<SystemPaths> { IOSSystemPaths() } }, | ||
module { single<INetworkConnectivityMonitor> { NetworkConnectivityMonitor() } } | ||
) | ||
} |
Oops, something went wrong.