- NetworkX now works with both Activity or Application Scope (NetworkX lifecycle is bounded to
NetworkXLifecycle.Activity
orNetworkXLifecycle.Application
). - Introduced
SmartConfig
to replace old config [NetworkXConfig
has been deprecated]. - New API to initialize
NetworkX
, enabled smart refactoring to replace old API with new one. - New API [
NoInternetDialogV2.forceClose()
] added to closeDialog
forcefully. - Added support for custom Drawable to be shown in
NoInternetDialogV2
. - Added support for No Internet Dialog
JetPack Compose
version. - Several Classes, APIs has been deprecated.
- Removed unused classes/packages.
Add the JitPack repository to your build file .
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Add the dependency.
dependencies {
implementation 'com.github.rommansabbir:NetworkX:4.2.0'
}
Initialize NetworkX
from your Application.onCreate()
//Deprecated way
val builder = NetworkXConfig.Builder()
.withApplication(this)
// You can disable speed meter if not required
.withEnableSpeedMeter(true)
.build()
NetworkXProvider.enable(builder)
//New smart way
NetworkXProvider.enable(SmartConfig(this, true, NetworkXLifecycle.Application))
- To check Internet Connection status, simply call extension variable
isInternetConnected
orisInternetConnectedLiveData
orisInternetConnectedFlow
.
isInternetConnectedFlow.collectLatest {
lifecycleScope.launch {
textView.text = "Internet connection status: $it"
}
}
- To get connected network speed/last known speed [
LastKnownSpeed
] call extension variablelastKnownSpeed
orlastKnownSpeedLiveData
orlastKnownSpeedFlow
lastKnownSpeed?.let {
textView2.text ="S-${it.speed}|T-${it.networkTypeNetwork}|SS-${it.simplifiedSpeed}"
}
- Show Dialog
NoInternetDialogV2(
activity = WeakReference(this@MainActivity),
title = "No Internet Bro",
message = "This is just a dummy message",
buttonTitle = "Okay",
isCancelable = true
) { /* Button Presses */ }
- Close Dialog (Forcefully)
NoInternetDialogV2.forceClose()
- Determine if the
NoInternetDialogV2
is currently visible or not.
NoInternetDialogV2.isVisible
- Show Dialog (Compose Version)
val ui = defaultNoInternetUI()
NoInternetDialogCompose(
true,
ui,
{ /*Dialog Cancelled*/ },
{ /*Dialog closed by user, by pressing action button*/ }
)
- NetworkX (including Speed Meter) can work on both Application scope or Activity scope. If scope is Activity, NetworkX will start/release it's components based on ActivityLifecycleCallback (onCreate - onDestroy). Else, it will start it's components only once and there will be no components release event.
- To emit (
MutableStateFlow
) Last Known Speed or Internet Connection Status,requiredCoroutineScope
works under aDispatchers.IO
context. - The default value for Internet Connection Status is
false
. - The default value for LastKnownSpeed is
NONE
.
β LinkedIn
β Website
Copyright (C) 2022 Romman Sabbir
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.