-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RemoteConfig / ReactBundleManager 리액티브하게 리팩토링 (#224)
- Loading branch information
Showing
12 changed files
with
184 additions
and
99 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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/wafflestudio/snutt2/lib/network/NetworkConnectivityManager.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,47 @@ | ||
package com.wafflestudio.snutt2.lib.network | ||
|
||
import android.net.ConnectivityManager | ||
import android.net.Network | ||
import android.net.NetworkCapabilities | ||
import android.net.NetworkRequest | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.filterNotNull | ||
import kotlinx.coroutines.flow.shareIn | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class NetworkConnectivityManager @Inject constructor( | ||
connectivityManager: ConnectivityManager, | ||
) { | ||
private val _networkConnectivity = MutableStateFlow<Boolean?>(null) | ||
val networkConnectivity = _networkConnectivity.filterNotNull() | ||
.shareIn( | ||
CoroutineScope(Dispatchers.Main), | ||
SharingStarted.Eagerly, | ||
replay = 1, | ||
) | ||
|
||
init { | ||
connectivityManager.registerNetworkCallback( | ||
NetworkRequest.Builder().apply { | ||
addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) | ||
addTransportType(NetworkCapabilities.TRANSPORT_WIFI) | ||
}.build(), | ||
object : ConnectivityManager.NetworkCallback() { | ||
override fun onLost(network: Network) { | ||
super.onLost(network) | ||
_networkConnectivity.value = false | ||
} | ||
|
||
override fun onAvailable(network: Network) { | ||
super.onAvailable(network) | ||
_networkConnectivity.value = true | ||
} | ||
}, | ||
) | ||
} | ||
} |
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
Oops, something went wrong.